diff options
author | Ashley Whetter <ashley@awhetter.co.uk> | 2017-06-10 06:43:00 +0100 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2017-07-08 14:33:12 +0300 |
commit | a6fc9c8fe78d406b946dd3a5345acfa4bbb04b1e (patch) | |
tree | c1ae103372234c875dd19dc70d7d4c4e12f8d6ae /pylint/test/extensions/test_check_docs.py | |
parent | 1f31968f0f0d74d89bad74aca9305483c935d0c3 (diff) | |
download | pylint-git-a6fc9c8fe78d406b946dd3a5345acfa4bbb04b1e.tar.gz |
Added docparams property tests
Diffstat (limited to 'pylint/test/extensions/test_check_docs.py')
-rw-r--r-- | pylint/test/extensions/test_check_docs.py | 332 |
1 files changed, 332 insertions, 0 deletions
diff --git a/pylint/test/extensions/test_check_docs.py b/pylint/test/extensions/test_check_docs.py index 78c3f71f9..7c505e11d 100644 --- a/pylint/test/extensions/test_check_docs.py +++ b/pylint/test/extensions/test_check_docs.py @@ -1352,3 +1352,335 @@ class TestParamDocChecker(CheckerTestCase): ''') with self.assertNoMessages(): self.checker.visit_functiondef(node) + + def test_finds_missing_raises_from_setter_sphinx(self): + """Example of a setter having missing raises documentation in + the Sphinx style docstring of the property + """ + property_node, node = astroid.extract_node(""" + class Foo(object): + @property + def foo(self): #@ + '''docstring ... + + :type: int + ''' + return 10 + + @foo.setter + def foo(self, value): + raise AttributeError() #@ + """) + with self.assertAddsMessages( + Message( + msg_id='missing-raises-doc', + node=property_node, + args=('AttributeError',)), + ): + self.checker.visit_raise(node) + + def test_finds_missing_raises_from_setter_google(self): + """Example of a setter having missing raises documentation in + the Google style docstring of the property + """ + property_node, node = astroid.extract_node(""" + class Foo(object): + @property + def foo(self): #@ + '''int: docstring + + Include a "Raises" section so that this is identified + as a Google docstring and not a Numpy docstring. + + Raises: + RuntimeError: Always + ''' + raise RuntimeError() + return 10 + + @foo.setter + def foo(self, value): + raises AttributeError() #@ + """) + with self.assertAddsMessages( + Message( + msg_id='missing-raises-doc', + node=property_node, + args=('AttributeError',)), + ): + self.checker.visit_raise(node) + + def test_finds_missing_raises_from_setter_numpy(self): + """Example of a setter having missing raises documentation in + the Numpy style docstring of the property + """ + property_node, node = astroid.extract_node(""" + class Foo(object): + @property + def foo(self): #@ + '''int: docstring + + Include a "Raises" section so that this is identified + as a Numpy docstring and not a Google docstring. + + Raises + ------ + RuntimeError + Always + ''' + raise RuntimeError() + return 10 + + @foo.setter + def foo(self, value): + raises AttributeError() #@ + """) + with self.assertAddsMessages( + Message( + msg_id='missing-raises-doc', + node=property_node, + args=('AttributeError',)), + ): + self.checker.visit_raise(node) + + def test_finds_missing_raises_in_setter_sphinx(self): + """Example of a setter having missing raises documentation in + its own Sphinx style docstring + """ + setter_node, node = astroid.extract_node(""" + class Foo(object): + @property + def foo(self): + '''docstring ... + + :type: int + :raises RuntimeError: Always + ''' + raise RuntimeError() + return 10 + + @foo.setter + def foo(self, value): #@ + '''setter docstring ... + + :type: None + ''' + raise AttributeError() #@ + """) + with self.assertAddsMessages( + Message( + msg_id='missing-raises-doc', + node=setter_node, + args=('AttributeError',)), + ): + self.checker.visit_raise(node) + + def test_finds_missing_raises_from_setter_google(self): + """Example of a setter having missing raises documentation in + its own Google style docstring of the property + """ + setter_node, node = astroid.extract_node(""" + class Foo(object): + @property + def foo(self): + '''int: docstring ... + + Raises: + RuntimeError: Always + ''' + raise RuntimeError() + return 10 + + @foo.setter + def foo(self, value): #@ + '''setter docstring ... + + Raises: + RuntimeError: Never + ''' + if True: + raise AttributeError() #@ + raise RuntimeError() + """) + with self.assertAddsMessages( + Message( + msg_id='missing-raises-doc', + node=setter_node, + args=('AttributeError',)), + ): + self.checker.visit_raise(node) + + def test_finds_missing_raises_from_setter_numpy(self): + """Example of a setter having missing raises documentation in + its own Numpy style docstring of the property + """ + setter_node, node = astroid.extract_node(""" + class Foo(object): + @property + def foo(self): + '''int: docstring ... + + Raises + ------ + RuntimeError + Always + ''' + raise RuntimeError() + return 10 + + @foo.setter + def foo(self, value): #@ + '''setter docstring ... + + Raises + ------ + RuntimeError + Never + ''' + if True: + raise AttributeError() #@ + raise RuntimeError() + """) + with self.assertAddsMessages( + Message( + msg_id='missing-raises-doc', + node=setter_node, + args=('AttributeError',)), + ): + self.checker.visit_raise(node) + + def test_finds_property_return_type_sphinx(self): + """Example of a property having return documentation in + a Sphinx style docstring + """ + node = astroid.extract_node(""" + class Foo(object): + @property + def foo(self): #@ + '''docstring ... + + :type: int + ''' + return 10 + """) + with self.assertNoMessages(): + self.checker.visit_functiondef(node) + + def test_finds_property_return_type_google(self): + """Example of a property having return documentation in + a Google style docstring + """ + node = astroid.extract_node(""" + class Foo(object): + @property + def foo(self): #@ + '''int: docstring ... + + Raises: + RuntimeError: Always + ''' + raise RuntimeError() + return 10 + """) + with self.assertNoMessages(): + self.checker.visit_functiondef(node) + + def test_finds_property_return_type_numpy(self): + """Example of a property having return documentation in + a numpy style docstring + """ + node = astroid.extract_node(""" + class Foo(object): + @property + def foo(self): #@ + '''int: docstring ... + + Raises + ------ + RuntimeError + Always + ''' + raise RuntimeError() + return 10 + """) + with self.assertNoMessages(): + self.checker.visit_functiondef(node) + + def test_finds_missing_property_return_type_sphinx(self): + """Example of a property having missing return documentation in + a Sphinx style docstring + """ + property_node, node = astroid.extract_node(""" + class Foo(object): + @property + def foo(self): #@ + '''docstring ... + + :raises RuntimeError: Always + ''' + raise RuntimeError() + return 10 #@ + """) + with self.assertAddsMessages( + Message( + msg_id='missing-return-doc', + node=property_node), + Message( + msg_id='missing-return-type-doc', + node=property_node), + ): + self.checker.visit_return(node) + + def test_finds_property_return_type_google(self): + """Example of a property having return documentation in + a Google style docstring + """ + property_node, node = astroid.extract_node(""" + class Foo(object): + @property + def foo(self): #@ + '''docstring ... + + Raises: + RuntimeError: Always + ''' + raise RuntimeError() + return 10 #@ + """) + with self.assertAddsMessages( + Message( + msg_id='missing-return-doc', + node=property_node), + Message( + msg_id='missing-return-type-doc', + node=property_node), + ): + self.checker.visit_return(node) + + def test_finds_property_return_type_numpy(self): + """Example of a property having return documentation in + a numpy style docstring + """ + property_node, node = astroid.extract_node(""" + class Foo(object): + @property + def foo(self): #@ + '''docstring ... + + Raises + ------ + RuntimeError + Always + ''' + raise RuntimeError() + return 10 #@ + """) + with self.assertAddsMessages( + Message( + msg_id='missing-return-doc', + node=property_node), + Message( + msg_id='missing-return-type-doc', + node=property_node), + ): + self.checker.visit_return(node) |