diff options
author | Daniƫl van Noord <13665637+DanielNoord@users.noreply.github.com> | 2021-12-08 19:42:10 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-08 19:42:10 +0100 |
commit | a51a5486ebff7543ae4fb6943fac2558947fa974 (patch) | |
tree | 84e437c5812ce0f13a11b7cd60057ac7ff492df0 /tests/extensions/test_check_docs.py | |
parent | 7523ad1c6710ff00ed2d500ed5d9b80c6d9007a7 (diff) | |
download | pylint-git-a51a5486ebff7543ae4fb6943fac2558947fa974.tar.gz |
Move some of the Numpy tests out of ``TestParamDocChecker`` (#5492)
Diffstat (limited to 'tests/extensions/test_check_docs.py')
-rw-r--r-- | tests/extensions/test_check_docs.py | 585 |
1 files changed, 0 insertions, 585 deletions
diff --git a/tests/extensions/test_check_docs.py b/tests/extensions/test_check_docs.py index a5293b821..b0eeeb483 100644 --- a/tests/extensions/test_check_docs.py +++ b/tests/extensions/test_check_docs.py @@ -25,12 +25,10 @@ in particular the parameter documentation checker `DocstringChecker` """ -# pylint: disable=too-many-public-methods import re import astroid -import pytest from astroid import nodes from pylint.extensions.docparams import DocstringParameterChecker @@ -48,33 +46,6 @@ class TestParamDocChecker(CheckerTestCase): "docstring_min_length": -1, } - def test_missing_func_params_in_numpy_docstring(self) -> None: - """Example of a function with missing NumPy style parameter - documentation in the docstring - """ - node = astroid.extract_node( - """ - def function_foo(x, y, z): - '''docstring ... - - Parameters - ---------- - x: - bla - z: int - bar - - some other stuff - ''' - pass - """ - ) - with self.assertAddsMessages( - MessageTest(msg_id="missing-param-doc", node=node, args=("y",)), - MessageTest(msg_id="missing-type-doc", node=node, args=("x, y",)), - ): - self.checker.visit_functiondef(node) - @set_config(accept_no_param_doc=True) def test_tolerate_no_param_documentation_at_all(self) -> None: """Example of a function with no parameter documentation at all @@ -139,228 +110,6 @@ class TestParamDocChecker(CheckerTestCase): if isinstance(body_item, nodes.FunctionDef) and hasattr(body_item, "name"): self.checker.visit_functiondef(body_item) - def test_missing_method_params_in_numpy_docstring(self) -> None: - """Example of a class method with missing parameter documentation in - the Numpy style docstring - """ - node = astroid.extract_node( - """ - class Foo(object): - def method_foo(self, x, y): - '''docstring ... - - missing parameter documentation - - Parameters - ---------- - x: - bla - ''' - pass - """ - ) - method_node = node.body[0] - with self.assertAddsMessages( - MessageTest(msg_id="missing-param-doc", node=method_node, args=("y",)), - MessageTest(msg_id="missing-type-doc", node=method_node, args=("x, y",)), - ): - self._visit_methods_of_class(node) - - def test_existing_func_params_in_numpy_docstring(self) -> None: - """Example of a function with correctly documented parameters and - return values (Numpy style) - """ - node = astroid.extract_node( - """ - def function_foo(xarg, yarg, zarg, warg): - '''function foo ... - - Parameters - ---------- - xarg: int - bla xarg - yarg: my.qualified.type - bla yarg - - zarg: int - bla zarg - warg: my.qualified.type - bla warg - - Returns - ------- - float - sum - ''' - return xarg + yarg - """ - ) - with self.assertNoMessages(): - self.checker.visit_functiondef(node) - - def test_wrong_name_of_func_params_in_numpy_docstring(self) -> None: - """Example of functions with inconsistent parameter names in the - signature and in the Numpy style documentation - """ - node = astroid.extract_node( - """ - def function_foo(xarg, yarg, zarg): - '''function foo ... - - Parameters - ---------- - xarg1: int - bla xarg - yarg: float - bla yarg - - zarg1: str - bla zarg - ''' - return xarg + yarg - """ - ) - with self.assertAddsMessages( - MessageTest(msg_id="missing-param-doc", node=node, args=("xarg, zarg",)), - MessageTest(msg_id="missing-type-doc", node=node, args=("xarg, zarg",)), - MessageTest( - msg_id="differing-param-doc", node=node, args=("xarg1, zarg1",) - ), - MessageTest(msg_id="differing-type-doc", node=node, args=("xarg1, zarg1",)), - ): - self.checker.visit_functiondef(node) - - node = astroid.extract_node( - """ - def function_foo(xarg, yarg): - '''function foo ... - - Parameters - ---------- - yarg1: float - bla yarg - - For the other parameters, see bla. - ''' - return xarg + yarg - """ - ) - with self.assertAddsMessages( - MessageTest(msg_id="differing-param-doc", node=node, args=("yarg1",)), - MessageTest(msg_id="differing-type-doc", node=node, args=("yarg1",)), - ): - self.checker.visit_functiondef(node) - - def test_see_sentence_for_func_params_in_numpy_docstring(self) -> None: - """Example for the usage of "For the other parameters, see" to avoid - too many repetitions, e.g. in functions or methods adhering to a - given interface (Numpy style) - """ - node = astroid.extract_node( - """ - def function_foo(xarg, yarg): - '''function foo ... - - Parameters - ---------- - yarg: float - bla yarg - - For the other parameters, see :func:`bla` - ''' - return xarg + yarg - """ - ) - with self.assertNoMessages(): - self.checker.visit_functiondef(node) - - def test_constr_params_in_class_numpy(self) -> None: - """Example of a class with missing constructor parameter documentation - (Numpy style) - - Everything is completely analogous to functions. - """ - node = astroid.extract_node( - """ - class ClassFoo(object): - '''docstring foo - - Parameters - ---------- - y: - bla - - missing constructor parameter documentation - ''' - - def __init__(self, x, y): - pass - - """ - ) - with self.assertAddsMessages( - MessageTest(msg_id="missing-param-doc", node=node, args=("x",)), - MessageTest(msg_id="missing-type-doc", node=node, args=("x, y",)), - ): - self._visit_methods_of_class(node) - - def test_constr_params_and_attributes_in_class_numpy(self) -> None: - """Example of a class with correct constructor parameter documentation - and an attributes section (Numpy style) - """ - node = astroid.extract_node( - """ - class ClassFoo(object): - ''' - Parameters - ---------- - foo : str - Something. - - Attributes - ---------- - bar : str - Something. - ''' - def __init__(self, foo): - self.bar = None - """ - ) - with self.assertNoMessages(): - self._visit_methods_of_class(node) - - def test_constr_params_in_init_numpy(self) -> None: - """Example of a class with missing constructor parameter documentation - (Numpy style) - - Everything is completely analogous to functions. - """ - node = astroid.extract_node( - """ - class ClassFoo(object): - def __init__(self, x, y): - '''docstring foo constructor - - Parameters - ---------- - y: - bla - - missing constructor parameter documentation - ''' - pass - - """ - ) - constructor_node = node.body[0] - with self.assertAddsMessages( - MessageTest(msg_id="missing-param-doc", node=constructor_node, args=("x",)), - MessageTest( - msg_id="missing-type-doc", node=constructor_node, args=("x, y",) - ), - ): - self._visit_methods_of_class(node) - def test_see_sentence_for_constr_params_in_class(self) -> None: """Example usage of "For the parameters, see" in class docstring""" node = astroid.extract_node( @@ -399,54 +148,6 @@ class TestParamDocChecker(CheckerTestCase): with self.assertNoMessages(): self._visit_methods_of_class(node) - def test_constr_params_in_class_and_init_numpy(self) -> None: - """Example of a class with missing constructor parameter documentation - in both the init docstring and the class docstring - (Numpy style) - - Everything is completely analogous to functions. - """ - node = astroid.extract_node( - """ - class ClassFoo(object): - '''docstring foo - - Parameters - ---------- - y: - bla - - missing constructor parameter documentation - ''' - - def __init__(self, x, y): - '''docstring foo - - Parameters - ---------- - y: - bla - - missing constructor parameter documentation - ''' - pass - - """ - ) - constructor_node = node.body[0] - with self.assertAddsMessages( - MessageTest( - msg_id="multiple-constructor-doc", node=node, args=(node.name,) - ), - MessageTest(msg_id="missing-param-doc", node=node, args=("x",)), - MessageTest(msg_id="missing-type-doc", node=node, args=("x, y",)), - MessageTest(msg_id="missing-param-doc", node=constructor_node, args=("x",)), - MessageTest( - msg_id="missing-type-doc", node=constructor_node, args=("x, y",) - ), - ): - self._visit_methods_of_class(node) - def test_kwonlyargs_are_taken_in_account(self) -> None: node = astroid.extract_node( ''' @@ -466,197 +167,6 @@ class TestParamDocChecker(CheckerTestCase): ): self.checker.visit_functiondef(node) - def test_warns_missing_args_numpy(self) -> None: - node = astroid.extract_node( - ''' - def my_func(named_arg, *args): - """The docstring - - Args - ---- - named_arg : object - Returned - - Returns - ------- - object or None - Maybe named_arg - """ - if args: - return named_arg - ''' - ) - with self.assertAddsMessages( - MessageTest(msg_id="missing-param-doc", node=node, args=("*args",)) - ): - self.checker.visit_functiondef(node) - - def test_warns_missing_kwargs_numpy(self) -> None: - node = astroid.extract_node( - ''' - def my_func(named_arg, **kwargs): - """The docstring - - Args - ---- - named_arg : object - Returned - - Returns - ------- - object or None - Maybe named_arg - """ - if kwargs: - return named_arg - ''' - ) - with self.assertAddsMessages( - MessageTest(msg_id="missing-param-doc", node=node, args=("**kwargs",)) - ): - self.checker.visit_functiondef(node) - - def test_finds_args_without_type_numpy(self) -> None: - node = astroid.extract_node( - ''' - def my_func(named_arg, typed_arg: bool, untyped_arg, *args): - """The docstring - - Args - ---- - named_arg : object - Returned - typed_arg - Other argument without numpy type annotation - untyped_arg - Other argument without any type annotation - *args : - Optional Arguments - - Returns - ------- - object or None - Maybe named_arg - """ - if args: - return named_arg - ''' - ) - with self.assertAddsMessages( - MessageTest(msg_id="missing-type-doc", node=node, args=("untyped_arg",)) - ): - self.checker.visit_functiondef(node) - - def test_finds_args_with_xref_type_numpy(self) -> None: - node = astroid.extract_node( - ''' - def my_func(named_arg, *args): - """The docstring - - Args - ---- - named_arg : `example.value` - Returned - *args : - Optional Arguments - - Returns - ------- - `example.value` - Maybe named_arg - """ - if args: - return named_arg - ''' - ) - with self.assertNoMessages(): - self.checker.visit_functiondef(node) - - def test_finds_kwargs_without_type_numpy(self) -> None: - node = astroid.extract_node( - ''' - def my_func(named_arg, **kwargs): - """The docstring - - Args - ---- - named_arg : object - Returned - **kwargs : - Keyword arguments - - Returns - ------- - object or None - Maybe named_arg - """ - if kwargs: - return named_arg - ''' - ) - with self.assertNoMessages(): - self.checker.visit_functiondef(node) - - COMPLEX_TYPES = [ - "dict(str,str)", - "dict[str,str]", - "tuple(int)", - "list[tokenize.TokenInfo]", - "dict(str, str)", - "dict[str, str]", - "int or str", - "tuple(int or str)", - "tuple(int) or list(int)", - "tuple(int or str) or list(int or str)", - ] - - @pytest.mark.parametrize("complex_type", COMPLEX_TYPES) - def test_finds_multiple_types_numpy(self, complex_type): - node = astroid.extract_node( - f''' - def my_func(named_arg): - """The docstring - - Args - ---- - named_arg : {complex_type} - Returned - - Returns - ------- - {complex_type} - named_arg - """ - return named_arg - ''' - ) - with self.assertNoMessages(): - self.checker.visit_functiondef(node) - - def test_ignores_optional_specifier_numpy(self) -> None: - node = astroid.extract_node( - ''' - def do_something(param, param2='all'): - """Do something. - - Parameters - ---------- - param : str - Description. - param2 : str, optional - Description (the default is 'all'). - - Returns - ------- - int - Description. - """ - return param, param2 - ''' - ) - with self.assertNoMessages(): - self.checker.visit_functiondef(node) - def test_finds_short_name_exception(self) -> None: node = astroid.extract_node( ''' @@ -850,101 +360,6 @@ class TestParamDocChecker(CheckerTestCase): ): self.checker.visit_return(node) - def test_ignores_return_in_abstract_method_numpy(self) -> None: - """Example of an abstract method documenting the return type that an - implementation should return. - """ - node = astroid.extract_node( - """ - import abc - class Foo(object): - @abc.abstractmethod - def foo(self): #@ - '''docstring ... - - Returns - ------- - int - Ten - ''' - return 10 - """ - ) - with self.assertNoMessages(): - self.checker.visit_functiondef(node) - - def test_ignores_return_in_abstract_method_numpy_2(self) -> None: - """Example of a method documenting the return type that an - implementation should return. - """ - node = astroid.extract_node( - """ - class Foo(object): - def foo(self, arg): #@ - '''docstring ... - - Parameters - ---------- - arg : int - An argument. - ''' - raise NotImplementedError() - """ - ) - with self.assertNoMessages(): - self.checker.visit_functiondef(node) - - def test_ignores_ignored_argument_names_numpy(self) -> None: - """Example of a method documenting the return type that an - implementation should return. - """ - node = astroid.extract_node( - """ - class Foo(object): - def foo(self, arg, _): #@ - '''docstring ... - - Parameters - ---------- - arg : int - An argument. - ''' - pass - """ - ) - with self.assertNoMessages(): - self.checker.visit_functiondef(node) - - def test_useless_docs_ignored_argument_names_numpy(self) -> None: - """Example of a method documenting the return type that an - implementation should return. - """ - node = astroid.extract_node( - """ - class Foo(object): - def foo(self, arg, _, _ignored): #@ - '''docstring ... - - Parameters - ---------- - arg : int - An argument. - - _ : float - Another argument. - - _ignored : - Ignored Argument - ''' - pass - """ - ) - with self.assertAddsMessages( - MessageTest(msg_id="useless-type-doc", node=node, args=("_",)), - MessageTest(msg_id="useless-param-doc", node=node, args=("_, _ignored",)), - ): - self.checker.visit_functiondef(node) - @set_config_directly(no_docstring_rgx=re.compile(r"^_(?!_).*$")) def test_skip_no_docstring_rgx(self) -> None: """Example of a function that matches the default 'no-docstring-rgx' config option |