summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniƫl van Noord <13665637+DanielNoord@users.noreply.github.com>2021-12-12 23:26:43 +0100
committerGitHub <noreply@github.com>2021-12-12 23:26:43 +0100
commitf8b23eb9cccf4bda452bf56dc1c71b8a046e571b (patch)
tree050efc17b90e701249787ad5fb57a5c17901d4d0
parentcbf39764474529b03eea206801fb8f456a2da9b2 (diff)
downloadpylint-git-f8b23eb9cccf4bda452bf56dc1c71b8a046e571b.tar.gz
Move ``Numpy`` tests from ``TestParamDocChecker`` to functional tests (#5507)
-rw-r--r--tests/extensions/test_check_docs.py140
-rw-r--r--tests/functional/ext/docparams/raise/missing_raises_doc_Numpy.py60
-rw-r--r--tests/functional/ext/docparams/raise/missing_raises_doc_Numpy.txt19
-rw-r--r--tests/functional/ext/docparams/return/missing_return_doc_required_Numpy.py59
-rw-r--r--tests/functional/ext/docparams/return/missing_return_doc_required_Numpy.txt7
5 files changed, 134 insertions, 151 deletions
diff --git a/tests/extensions/test_check_docs.py b/tests/extensions/test_check_docs.py
index 37a5e62bc..aab3bd761 100644
--- a/tests/extensions/test_check_docs.py
+++ b/tests/extensions/test_check_docs.py
@@ -184,146 +184,6 @@ class TestParamDocChecker(CheckerTestCase):
with self.assertNoMessages():
self.checker.visit_functiondef(node)
- def test_finds_missing_raises_from_setter_numpy_2(self) -> None:
- """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(
- MessageTest(
- msg_id="missing-raises-doc", node=setter_node, args=("AttributeError",)
- )
- ):
- self.checker.visit_raise(node)
-
- def test_finds_property_return_type_numpy(self) -> None:
- """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)
-
- @set_config(accept_no_return_doc="no")
- def test_finds_missing_property_return_type_numpy(self) -> None:
- """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(
- MessageTest(msg_id="missing-return-type-doc", node=property_node)
- ):
- self.checker.visit_return(node)
-
- @set_config(accept_no_return_doc="no")
- def test_ignores_non_property_return_type_numpy(self) -> None:
- """Example of a class function trying to use `type` as return
- documentation in a numpy style docstring
- """
- func_node, node = astroid.extract_node(
- """
- class Foo(object):
- def foo(self): #@
- '''int: docstring ...
-
- Raises
- ------
- RuntimeError
- Always
- '''
- raise RuntimeError()
- return 10 #@
- """
- )
- with self.assertAddsMessages(
- MessageTest(msg_id="missing-return-doc", node=func_node),
- MessageTest(msg_id="missing-return-type-doc", node=func_node),
- ):
- self.checker.visit_return(node)
-
- @set_config(accept_no_return_doc="no")
- def test_non_property_annotation_return_type_numpy(self) -> None:
- """Example of a class function trying to use `type` as return
- documentation in a numpy style docstring
- """
- func_node, node = astroid.extract_node(
- """
- class Foo(object):
- def foo(self) -> int: #@
- '''int: docstring ...
-
- Raises
- ------
- RuntimeError
- Always
- '''
- raise RuntimeError()
- return 10 #@
- """
- )
- with self.assertAddsMessages(
- MessageTest(msg_id="missing-return-doc", node=func_node)
- ):
- self.checker.visit_return(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
diff --git a/tests/functional/ext/docparams/raise/missing_raises_doc_Numpy.py b/tests/functional/ext/docparams/raise/missing_raises_doc_Numpy.py
index dc42940ea..8cf8e041f 100644
--- a/tests/functional/ext/docparams/raise/missing_raises_doc_Numpy.py
+++ b/tests/functional/ext/docparams/raise/missing_raises_doc_Numpy.py
@@ -1,7 +1,11 @@
-"""Tests for missing-raises-doc and missing-raises-type-doc for Numpy style docstrings"""
+"""Tests for missing-raises-doc and missing-raises-type-doc for Numpy style docstrings
+
+Styleguide:
+https://numpydoc.readthedocs.io/en/latest/format.html#docstring-standard
+"""
# pylint: disable=function-redefined, invalid-name, undefined-variable, missing-function-docstring
# pylint: disable=unused-argument, try-except-raise, import-outside-toplevel
-# pylint: disable=too-few-public-methods, disallowed-name
+# pylint: disable=too-few-public-methods, disallowed-name, using-constant-test
def test_find_missing_numpy_raises(self): # [missing-raises-doc]
@@ -157,3 +161,55 @@ class Foo:
def foo(self, value):
print(self)
raise AttributeError()
+
+
+class Foo:
+ """test_finds_missing_raises_from_setter_numpy_2
+ Example of a setter having missing raises documentation in
+ its own Numpy style docstring of the property
+ """
+
+ @property
+ def foo(self):
+ """int: docstring ...
+
+ Raises
+ ------
+ RuntimeError
+ Always
+ """
+ raise RuntimeError()
+ return 10 # [unreachable]
+
+ @foo.setter
+ def foo(self, value): # [missing-raises-doc]
+ """setter docstring ...
+
+ Raises
+ ------
+ RuntimeError
+ Never
+ """
+ print(self)
+ if True:
+ raise AttributeError()
+ raise RuntimeError()
+
+
+class Foo:
+ """test_finds_property_return_type_numpy
+ Example of a property having return documentation in
+ a numpy style docstring
+ """
+
+ @property
+ def foo(self):
+ """int: docstring ...
+
+ Raises
+ ------
+ RuntimeError
+ Always
+ """
+ raise RuntimeError()
+ return 10 # [unreachable]
diff --git a/tests/functional/ext/docparams/raise/missing_raises_doc_Numpy.txt b/tests/functional/ext/docparams/raise/missing_raises_doc_Numpy.txt
index 69dcffb21..8e63c4d9b 100644
--- a/tests/functional/ext/docparams/raise/missing_raises_doc_Numpy.txt
+++ b/tests/functional/ext/docparams/raise/missing_raises_doc_Numpy.txt
@@ -1,8 +1,11 @@
-missing-raises-doc:7:0:16:25:test_find_missing_numpy_raises:"""RuntimeError"" not documented as being raised":UNDEFINED
-unreachable:16:4:16:25:test_find_missing_numpy_raises:Unreachable code:UNDEFINED
-unreachable:30:4:30:25:test_find_all_numpy_raises:Unreachable code:UNDEFINED
-missing-raises-doc:33:0:46:25:test_find_rethrown_numpy_raises:"""RuntimeError"" not documented as being raised":UNDEFINED
-missing-raises-doc:49:0:62:25:test_find_rethrown_numpy_multiple_raises:"""RuntimeError, ValueError"" not documented as being raised":UNDEFINED
-missing-raises-doc:107:0:117:21:test_find_valid_missing_numpy_attr_raises:"""error"" not documented as being raised":UNDEFINED
-missing-raises-doc:142:4:154:17:Foo.foo:"""AttributeError"" not documented as being raised":UNDEFINED
-unreachable:154:8:154:17:Foo.foo:Unreachable code:UNDEFINED
+missing-raises-doc:11:0:20:25:test_find_missing_numpy_raises:"""RuntimeError"" not documented as being raised":UNDEFINED
+unreachable:20:4:20:25:test_find_missing_numpy_raises:Unreachable code:UNDEFINED
+unreachable:34:4:34:25:test_find_all_numpy_raises:Unreachable code:UNDEFINED
+missing-raises-doc:37:0:50:25:test_find_rethrown_numpy_raises:"""RuntimeError"" not documented as being raised":UNDEFINED
+missing-raises-doc:53:0:66:25:test_find_rethrown_numpy_multiple_raises:"""RuntimeError, ValueError"" not documented as being raised":UNDEFINED
+missing-raises-doc:111:0:121:21:test_find_valid_missing_numpy_attr_raises:"""error"" not documented as being raised":UNDEFINED
+missing-raises-doc:146:4:158:17:Foo.foo:"""AttributeError"" not documented as being raised":UNDEFINED
+unreachable:158:8:158:17:Foo.foo:Unreachable code:UNDEFINED
+unreachable:182:8:182:17:Foo.foo:Unreachable code:UNDEFINED
+missing-raises-doc:185:4:196:28:Foo.foo:"""AttributeError"" not documented as being raised":UNDEFINED
+unreachable:215:8:215:17:Foo.foo:Unreachable code:UNDEFINED
diff --git a/tests/functional/ext/docparams/return/missing_return_doc_required_Numpy.py b/tests/functional/ext/docparams/return/missing_return_doc_required_Numpy.py
index 9b160c177..8cc59f0ac 100644
--- a/tests/functional/ext/docparams/return/missing_return_doc_required_Numpy.py
+++ b/tests/functional/ext/docparams/return/missing_return_doc_required_Numpy.py
@@ -1,7 +1,7 @@
"""Tests for missing-return-doc and missing-return-type-doc for Numpy style docstrings
with accept-no-returns-doc = no"""
# pylint: disable=function-redefined, invalid-name, undefined-variable, missing-function-docstring
-# pylint: disable=unused-argument
+# pylint: disable=unused-argument, too-few-public-methods
def my_func(self, doc_type): # [missing-return-doc]
@@ -38,3 +38,60 @@ def my_func(self): # [missing-return-doc]
list(:class:`mymodule.Class`)
"""
return [mymodule.Class()]
+
+
+class Foo:
+ """test_finds_missing_property_return_type_numpy
+ Example of a property having return documentation in
+ a numpy style docstring
+ """
+
+ @property
+ def foo_prop(self): # [missing-return-type-doc]
+ """docstring ...
+
+ Raises
+ ------
+ RuntimeError
+ Always
+ """
+ raise RuntimeError()
+ return 10 # [unreachable]
+
+
+class Foo:
+ """test_ignores_non_property_return_type_numpy
+ Example of a class function trying to use `type` as return
+ documentation in a numpy style docstring
+ """
+
+ def foo_method(self): # [missing-return-doc, missing-return-type-doc]
+ """int: docstring ...
+
+ Raises
+ ------
+ RuntimeError
+ Always
+ """
+ print(self)
+ raise RuntimeError()
+ return 10 # [unreachable]
+
+
+class Foo:
+ """test_non_property_annotation_return_type_numpy
+ Example of a class function trying to use `type` as return
+ documentation in a numpy style docstring
+ """
+
+ def foo_method(self) -> int: # [missing-return-doc]
+ """int: docstring ...
+
+ Raises
+ ------
+ RuntimeError
+ Always
+ """
+ print(self)
+ raise RuntimeError()
+ return 10 # [unreachable]
diff --git a/tests/functional/ext/docparams/return/missing_return_doc_required_Numpy.txt b/tests/functional/ext/docparams/return/missing_return_doc_required_Numpy.txt
index e3872d206..f3dc18f8b 100644
--- a/tests/functional/ext/docparams/return/missing_return_doc_required_Numpy.txt
+++ b/tests/functional/ext/docparams/return/missing_return_doc_required_Numpy.txt
@@ -2,3 +2,10 @@ missing-return-doc:7:0:19:16:my_func:Missing return documentation:UNDEFINED
missing-return-doc:22:0:30:16:my_func:Missing return documentation:UNDEFINED
missing-return-type-doc:22:0:30:16:my_func:Missing return type documentation:UNDEFINED
missing-return-doc:33:0:40:29:my_func:Missing return documentation:UNDEFINED
+missing-return-type-doc:50:4:59:17:Foo.foo_prop:Missing return type documentation:UNDEFINED
+unreachable:59:8:59:17:Foo.foo_prop:Unreachable code:UNDEFINED
+missing-return-doc:68:4:78:17:Foo.foo_method:Missing return documentation:UNDEFINED
+missing-return-type-doc:68:4:78:17:Foo.foo_method:Missing return type documentation:UNDEFINED
+unreachable:78:8:78:17:Foo.foo_method:Unreachable code:UNDEFINED
+missing-return-doc:87:4:97:17:Foo.foo_method:Missing return documentation:UNDEFINED
+unreachable:97:8:97:17:Foo.foo_method:Unreachable code:UNDEFINED