summaryrefslogtreecommitdiff
path: root/tests/extensions/test_check_docs.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/extensions/test_check_docs.py')
-rw-r--r--tests/extensions/test_check_docs.py1002
1 files changed, 476 insertions, 526 deletions
diff --git a/tests/extensions/test_check_docs.py b/tests/extensions/test_check_docs.py
index 1eacc9387..9b4acce84 100644
--- a/tests/extensions/test_check_docs.py
+++ b/tests/extensions/test_check_docs.py
@@ -29,16 +29,16 @@ from pylint.testutils import CheckerTestCase, Message, set_config
class TestParamDocChecker(CheckerTestCase):
"""Tests for pylint_plugin.ParamDocChecker"""
+
CHECKER_CLASS = DocstringParameterChecker
- CONFIG = {
- 'accept_no_param_doc': False,
- }
+ CONFIG = {"accept_no_param_doc": False}
def test_missing_func_params_in_sphinx_docstring(self):
"""Example of a function with missing Sphinx parameter documentation in
the docstring
"""
- node = astroid.extract_node("""
+ node = astroid.extract_node(
+ """
def function_foo(x, y, z):
'''docstring ...
@@ -47,16 +47,11 @@ class TestParamDocChecker(CheckerTestCase):
:param int z: bar
'''
pass
- """)
+ """
+ )
with self.assertAddsMessages(
- Message(
- msg_id='missing-param-doc',
- node=node,
- args=('y',)),
- Message(
- msg_id='missing-type-doc',
- node=node,
- args=('x, y',))
+ Message(msg_id="missing-param-doc", node=node, args=("y",)),
+ Message(msg_id="missing-type-doc", node=node, args=("x, y",)),
):
self.checker.visit_functiondef(node)
@@ -64,7 +59,8 @@ class TestParamDocChecker(CheckerTestCase):
"""Example of a function with missing Google style parameter
documentation in the docstring
"""
- node = astroid.extract_node("""
+ node = astroid.extract_node(
+ """
def function_foo(x, y, z):
'''docstring ...
@@ -75,16 +71,11 @@ class TestParamDocChecker(CheckerTestCase):
some other stuff
'''
pass
- """)
+ """
+ )
with self.assertAddsMessages(
- Message(
- msg_id='missing-param-doc',
- node=node,
- args=('y',)),
- Message(
- msg_id='missing-type-doc',
- node=node,
- args=('x, y',))
+ Message(msg_id="missing-param-doc", node=node, args=("y",)),
+ Message(msg_id="missing-type-doc", node=node, args=("x, y",)),
):
self.checker.visit_functiondef(node)
@@ -92,7 +83,8 @@ class TestParamDocChecker(CheckerTestCase):
"""Example of a function with missing Google style parameter
documentation in the docstring.
"""
- node = astroid.extract_node("""
+ node = astroid.extract_node(
+ """
def function_foo(x: int, y: bool, z):
'''docstring ...
@@ -104,7 +96,8 @@ class TestParamDocChecker(CheckerTestCase):
some other stuff
'''
pass
- """)
+ """
+ )
with self.assertNoMessages():
self.checker.visit_functiondef(node)
@@ -112,7 +105,8 @@ class TestParamDocChecker(CheckerTestCase):
"""Example of a function with missing Google style parameter
documentation in the docstring.
"""
- node = astroid.extract_node("""
+ node = astroid.extract_node(
+ """
def function_foo(x: int, y: bool, z: int = 786):
'''docstring ...
@@ -124,7 +118,8 @@ class TestParamDocChecker(CheckerTestCase):
some other stuff
'''
pass
- """)
+ """
+ )
with self.assertNoMessages():
self.checker.visit_functiondef(node)
@@ -132,7 +127,8 @@ class TestParamDocChecker(CheckerTestCase):
"""Example of a function with missing Google style parameter
documentation in the docstring.
"""
- node = astroid.extract_node("""
+ node = astroid.extract_node(
+ """
def function_foo(x, y: bool, z):
'''docstring ...
@@ -144,12 +140,10 @@ class TestParamDocChecker(CheckerTestCase):
some other stuff
'''
pass
- """)
+ """
+ )
with self.assertAddsMessages(
- Message(
- msg_id='missing-type-doc',
- node=node,
- args=('x',))
+ Message(msg_id="missing-type-doc", node=node, args=("x",))
):
self.checker.visit_functiondef(node)
@@ -157,7 +151,8 @@ class TestParamDocChecker(CheckerTestCase):
"""Example of a function with missing Google style parameter
documentation in the docstring.
"""
- node = astroid.extract_node("""
+ node = astroid.extract_node(
+ """
def area(bottomleft: Point, topright: Point) -> float:
'''Calculate area of fake rectangle.
Args:
@@ -165,7 +160,8 @@ class TestParamDocChecker(CheckerTestCase):
topright: top right point of rectangle
'''
pass
- """)
+ """
+ )
with self.assertNoMessages():
self.checker.visit_functiondef(node)
@@ -173,7 +169,8 @@ class TestParamDocChecker(CheckerTestCase):
"""Example of a function with missing Google style parameter
documentation in the docstring.
"""
- node = astroid.extract_node("""
+ node = astroid.extract_node(
+ """
def get_midpoint(bottomleft: Point, topright: Point) -> Point:
'''Calculate midpoint of fake rectangle.
Args:
@@ -181,7 +178,8 @@ class TestParamDocChecker(CheckerTestCase):
topright: top right point of rectangle
'''
pass
- """)
+ """
+ )
with self.assertNoMessages():
self.checker.visit_functiondef(node)
@@ -189,7 +187,8 @@ class TestParamDocChecker(CheckerTestCase):
"""Example of a function with Google style parameter splitted
in Args and Keyword Args in the docstring
"""
- node = astroid.extract_node("""
+ node = astroid.extract_node(
+ """
def my_func(this, other, that=True):
'''Prints this, other and that
@@ -201,7 +200,8 @@ class TestParamDocChecker(CheckerTestCase):
that (bool): Printed second
'''
print(this, that, other)
- """)
+ """
+ )
with self.assertNoMessages():
self.checker.visit_functiondef(node)
@@ -209,7 +209,8 @@ class TestParamDocChecker(CheckerTestCase):
"""Example of a function with Google style parameter splitted
in Args and Keyword Args in the docstring but with wrong keyword args
"""
- node = astroid.extract_node("""
+ node = astroid.extract_node(
+ """
def my_func(this, other, that=True):
'''Prints this, other and that
@@ -221,32 +222,22 @@ class TestParamDocChecker(CheckerTestCase):
these (bool): Printed second
'''
print(this, that, other)
- """)
+ """
+ )
with self.assertAddsMessages(
- Message(
- msg_id='missing-param-doc',
- node=node,
- args=('that',)),
- Message(
- msg_id='missing-type-doc',
- node=node,
- args=('that',)),
- Message(
- msg_id='differing-param-doc',
- node=node,
- args=('these',)),
- Message(
- msg_id='differing-type-doc',
- node=node,
- args=('these',))
- ):
+ Message(msg_id="missing-param-doc", node=node, args=("that",)),
+ Message(msg_id="missing-type-doc", node=node, args=("that",)),
+ Message(msg_id="differing-param-doc", node=node, args=("these",)),
+ Message(msg_id="differing-type-doc", node=node, args=("these",)),
+ ):
self.checker.visit_functiondef(node)
def test_missing_func_params_in_numpy_docstring(self):
"""Example of a function with missing NumPy style parameter
documentation in the docstring
"""
- node = astroid.extract_node("""
+ node = astroid.extract_node(
+ """
def function_foo(x, y, z):
'''docstring ...
@@ -260,16 +251,11 @@ class TestParamDocChecker(CheckerTestCase):
some other stuff
'''
pass
- """)
+ """
+ )
with self.assertAddsMessages(
- Message(
- msg_id='missing-param-doc',
- node=node,
- args=('y',)),
- Message(
- msg_id='missing-type-doc',
- node=node,
- args=('x, y',))
+ Message(msg_id="missing-param-doc", node=node, args=("y",)),
+ Message(msg_id="missing-type-doc", node=node, args=("x, y",)),
):
self.checker.visit_functiondef(node)
@@ -279,13 +265,15 @@ class TestParamDocChecker(CheckerTestCase):
No error message is emitted.
"""
- node = astroid.extract_node("""
+ node = astroid.extract_node(
+ """
def function_foo(x, y):
'''docstring ...
missing parameter documentation'''
pass
- """)
+ """
+ )
with self.assertNoMessages():
self.checker.visit_functiondef(node)
@@ -294,22 +282,18 @@ class TestParamDocChecker(CheckerTestCase):
Missing documentation error message is emitted.
"""
- node = astroid.extract_node("""
+ node = astroid.extract_node(
+ """
def function_foo(x, y):
'''docstring ...
missing parameter documentation'''
pass
- """)
+ """
+ )
with self.assertAddsMessages(
- Message(
- msg_id='missing-param-doc',
- node=node,
- args=('x, y',)),
- Message(
- msg_id='missing-type-doc',
- node=node,
- args=('x, y',))
+ Message(msg_id="missing-param-doc", node=node, args=("x, y",)),
+ Message(msg_id="missing-type-doc", node=node, args=("x, y",)),
):
self.checker.visit_functiondef(node)
@@ -317,14 +301,16 @@ class TestParamDocChecker(CheckerTestCase):
"""Example for the usage of "For the parameters, see"
to suppress missing-param warnings.
"""
- node = astroid.extract_node("""
+ node = astroid.extract_node(
+ """
def function_foo(x, y):
'''docstring ...
For the parameters, see :func:`blah`
'''
pass
- """)
+ """
+ )
with self.assertNoMessages():
self.checker.visit_functiondef(node)
@@ -335,15 +321,17 @@ class TestParamDocChecker(CheckerTestCase):
:type node: :class:`astroid.scoped_nodes.Class`
"""
for body_item in node.body:
- if (isinstance(body_item, astroid.FunctionDef)
- and hasattr(body_item, 'name')):
+ if isinstance(body_item, astroid.FunctionDef) and hasattr(
+ body_item, "name"
+ ):
self.checker.visit_functiondef(body_item)
def test_missing_method_params_in_sphinx_docstring(self):
"""Example of a class method with missing parameter documentation in
the Sphinx style docstring
"""
- node = astroid.extract_node("""
+ node = astroid.extract_node(
+ """
class Foo(object):
def method_foo(self, x, y):
'''docstring ...
@@ -353,17 +341,12 @@ class TestParamDocChecker(CheckerTestCase):
:param x: bla
'''
pass
- """)
+ """
+ )
method_node = node.body[0]
with self.assertAddsMessages(
- Message(
- msg_id='missing-param-doc',
- node=method_node,
- args=('y',)),
- Message(
- msg_id='missing-type-doc',
- node=method_node,
- args=('x, y',))
+ Message(msg_id="missing-param-doc", node=method_node, args=("y",)),
+ Message(msg_id="missing-type-doc", node=method_node, args=("x, y",)),
):
self._visit_methods_of_class(node)
@@ -371,7 +354,8 @@ class TestParamDocChecker(CheckerTestCase):
"""Example of a class method with missing parameter documentation in
the Google style docstring
"""
- node = astroid.extract_node("""
+ node = astroid.extract_node(
+ """
class Foo(object):
def method_foo(self, x, y):
'''docstring ...
@@ -382,17 +366,12 @@ class TestParamDocChecker(CheckerTestCase):
x: bla
'''
pass
- """)
+ """
+ )
method_node = node.body[0]
with self.assertAddsMessages(
- Message(
- msg_id='missing-param-doc',
- node=method_node,
- args=('y',)),
- Message(
- msg_id='missing-type-doc',
- node=method_node,
- args=('x, y',))
+ Message(msg_id="missing-param-doc", node=method_node, args=("y",)),
+ Message(msg_id="missing-type-doc", node=method_node, args=("x, y",)),
):
self._visit_methods_of_class(node)
@@ -400,7 +379,8 @@ class TestParamDocChecker(CheckerTestCase):
"""Example of a class method with missing parameter documentation in
the Numpy style docstring
"""
- node = astroid.extract_node("""
+ node = astroid.extract_node(
+ """
class Foo(object):
def method_foo(self, x, y):
'''docstring ...
@@ -413,17 +393,12 @@ class TestParamDocChecker(CheckerTestCase):
bla
'''
pass
- """)
+ """
+ )
method_node = node.body[0]
with self.assertAddsMessages(
- Message(
- msg_id='missing-param-doc',
- node=method_node,
- args=('y',)),
- Message(
- msg_id='missing-type-doc',
- node=method_node,
- args=('x, y',))
+ Message(msg_id="missing-param-doc", node=method_node, args=("y",)),
+ Message(msg_id="missing-type-doc", node=method_node, args=("x, y",)),
):
self._visit_methods_of_class(node)
@@ -431,7 +406,8 @@ class TestParamDocChecker(CheckerTestCase):
"""Example of a function with correctly documented parameters and
return values (Sphinx style)
"""
- node = astroid.extract_node("""
+ node = astroid.extract_node(
+ """
def function_foo(xarg, yarg, zarg, warg):
'''function foo ...
@@ -449,7 +425,8 @@ class TestParamDocChecker(CheckerTestCase):
:rtype: float
'''
return xarg + yarg
- """)
+ """
+ )
with self.assertNoMessages():
self.checker.visit_functiondef(node)
@@ -457,7 +434,8 @@ class TestParamDocChecker(CheckerTestCase):
"""Example of a function with correctly documented parameters and
return values (Google style)
"""
- node = astroid.extract_node("""
+ node = astroid.extract_node(
+ """
def function_foo(xarg, yarg, zarg, warg):
'''function foo ...
@@ -473,7 +451,8 @@ class TestParamDocChecker(CheckerTestCase):
float: sum
'''
return xarg + yarg
- """)
+ """
+ )
with self.assertNoMessages():
self.checker.visit_functiondef(node)
@@ -481,7 +460,8 @@ class TestParamDocChecker(CheckerTestCase):
"""Example of a function with correctly documented parameters and
return values (Numpy style)
"""
- node = astroid.extract_node("""
+ node = astroid.extract_node(
+ """
def function_foo(xarg, yarg, zarg, warg):
'''function foo ...
@@ -503,7 +483,8 @@ class TestParamDocChecker(CheckerTestCase):
sum
'''
return xarg + yarg
- """)
+ """
+ )
with self.assertNoMessages():
self.checker.visit_functiondef(node)
@@ -511,7 +492,8 @@ class TestParamDocChecker(CheckerTestCase):
"""Example of functions with inconsistent parameter names in the
signature and in the Sphinx style documentation
"""
- node = astroid.extract_node("""
+ node = astroid.extract_node(
+ """
def function_foo(xarg, yarg, zarg):
'''function foo ...
@@ -524,28 +506,18 @@ class TestParamDocChecker(CheckerTestCase):
:param str zarg1: bla zarg
'''
return xarg + yarg
- """)
+ """
+ )
with self.assertAddsMessages(
- Message(
- msg_id='missing-param-doc',
- node=node,
- args=('xarg, zarg',)),
- Message(
- msg_id='missing-type-doc',
- node=node,
- args=('yarg, zarg',)),
- Message(
- msg_id='differing-param-doc',
- node=node,
- args=('xarg1, zarg1',)),
- Message(
- msg_id='differing-type-doc',
- node=node,
- args=('yarg1, zarg1',)),
+ Message(msg_id="missing-param-doc", node=node, args=("xarg, zarg",)),
+ Message(msg_id="missing-type-doc", node=node, args=("yarg, zarg",)),
+ Message(msg_id="differing-param-doc", node=node, args=("xarg1, zarg1",)),
+ Message(msg_id="differing-type-doc", node=node, args=("yarg1, zarg1",)),
):
self.checker.visit_functiondef(node)
- node = astroid.extract_node("""
+ node = astroid.extract_node(
+ """
def function_foo(xarg, yarg):
'''function foo ...
@@ -555,16 +527,11 @@ class TestParamDocChecker(CheckerTestCase):
For the other parameters, see bla.
'''
return xarg + yarg
- """)
+ """
+ )
with self.assertAddsMessages(
- Message(
- msg_id='differing-param-doc',
- node=node,
- args=('yarg1',)),
- Message(
- msg_id='differing-type-doc',
- node=node,
- args=('yarg1',)),
+ Message(msg_id="differing-param-doc", node=node, args=("yarg1",)),
+ Message(msg_id="differing-type-doc", node=node, args=("yarg1",)),
):
self.checker.visit_functiondef(node)
@@ -572,7 +539,8 @@ class TestParamDocChecker(CheckerTestCase):
"""Example of functions with inconsistent parameter names in the
signature and in the Google style documentation
"""
- node = astroid.extract_node("""
+ node = astroid.extract_node(
+ """
def function_foo(xarg, yarg, zarg):
'''function foo ...
@@ -583,28 +551,18 @@ class TestParamDocChecker(CheckerTestCase):
zarg1 (str): bla zarg
'''
return xarg + yarg
- """)
+ """
+ )
with self.assertAddsMessages(
- Message(
- msg_id='missing-param-doc',
- node=node,
- args=('xarg, zarg',)),
- Message(
- msg_id='missing-type-doc',
- node=node,
- args=('xarg, zarg',)),
- Message(
- msg_id='differing-param-doc',
- node=node,
- args=('xarg1, zarg1',)),
- Message(
- msg_id='differing-type-doc',
- node=node,
- args=('xarg1, zarg1',)),
+ Message(msg_id="missing-param-doc", node=node, args=("xarg, zarg",)),
+ Message(msg_id="missing-type-doc", node=node, args=("xarg, zarg",)),
+ Message(msg_id="differing-param-doc", node=node, args=("xarg1, zarg1",)),
+ Message(msg_id="differing-type-doc", node=node, args=("xarg1, zarg1",)),
):
self.checker.visit_functiondef(node)
- node = astroid.extract_node("""
+ node = astroid.extract_node(
+ """
def function_foo(xarg, yarg):
'''function foo ...
@@ -614,16 +572,11 @@ class TestParamDocChecker(CheckerTestCase):
For the other parameters, see bla.
'''
return xarg + yarg
- """)
+ """
+ )
with self.assertAddsMessages(
- Message(
- msg_id='differing-param-doc',
- node=node,
- args=('yarg1',)),
- Message(
- msg_id='differing-type-doc',
- node=node,
- args=('yarg1',))
+ Message(msg_id="differing-param-doc", node=node, args=("yarg1",)),
+ Message(msg_id="differing-type-doc", node=node, args=("yarg1",)),
):
self.checker.visit_functiondef(node)
@@ -631,7 +584,8 @@ class TestParamDocChecker(CheckerTestCase):
"""Example of functions with inconsistent parameter names in the
signature and in the Numpy style documentation
"""
- node = astroid.extract_node("""
+ node = astroid.extract_node(
+ """
def function_foo(xarg, yarg, zarg):
'''function foo ...
@@ -646,28 +600,18 @@ class TestParamDocChecker(CheckerTestCase):
bla zarg
'''
return xarg + yarg
- """)
+ """
+ )
with self.assertAddsMessages(
- Message(
- msg_id='missing-param-doc',
- node=node,
- args=('xarg, zarg',)),
- Message(
- msg_id='missing-type-doc',
- node=node,
- args=('xarg, zarg',)),
- Message(
- msg_id='differing-param-doc',
- node=node,
- args=('xarg1, zarg1',)),
- Message(
- msg_id='differing-type-doc',
- node=node,
- args=('xarg1, zarg1',)),
+ Message(msg_id="missing-param-doc", node=node, args=("xarg, zarg",)),
+ Message(msg_id="missing-type-doc", node=node, args=("xarg, zarg",)),
+ Message(msg_id="differing-param-doc", node=node, args=("xarg1, zarg1",)),
+ Message(msg_id="differing-type-doc", node=node, args=("xarg1, zarg1",)),
):
self.checker.visit_functiondef(node)
- node = astroid.extract_node("""
+ node = astroid.extract_node(
+ """
def function_foo(xarg, yarg):
'''function foo ...
@@ -679,16 +623,11 @@ class TestParamDocChecker(CheckerTestCase):
For the other parameters, see bla.
'''
return xarg + yarg
- """)
+ """
+ )
with self.assertAddsMessages(
- Message(
- msg_id='differing-param-doc',
- node=node,
- args=('yarg1',)),
- Message(
- msg_id='differing-type-doc',
- node=node,
- args=('yarg1',))
+ Message(msg_id="differing-param-doc", node=node, args=("yarg1",)),
+ Message(msg_id="differing-type-doc", node=node, args=("yarg1",)),
):
self.checker.visit_functiondef(node)
@@ -697,7 +636,8 @@ class TestParamDocChecker(CheckerTestCase):
too many repetitions, e.g. in functions or methods adhering to a
given interface (Sphinx style)
"""
- node = astroid.extract_node("""
+ node = astroid.extract_node(
+ """
def function_foo(xarg, yarg):
'''function foo ...
@@ -707,7 +647,8 @@ class TestParamDocChecker(CheckerTestCase):
For the other parameters, see :func:`bla`
'''
return xarg + yarg
- """)
+ """
+ )
with self.assertNoMessages():
self.checker.visit_functiondef(node)
@@ -716,7 +657,8 @@ class TestParamDocChecker(CheckerTestCase):
too many repetitions, e.g. in functions or methods adhering to a
given interface (Google style)
"""
- node = astroid.extract_node("""
+ node = astroid.extract_node(
+ """
def function_foo(xarg, yarg):
'''function foo ...
@@ -726,7 +668,8 @@ class TestParamDocChecker(CheckerTestCase):
For the other parameters, see :func:`bla`
'''
return xarg + yarg
- """)
+ """
+ )
with self.assertNoMessages():
self.checker.visit_functiondef(node)
@@ -735,7 +678,8 @@ class TestParamDocChecker(CheckerTestCase):
too many repetitions, e.g. in functions or methods adhering to a
given interface (Numpy style)
"""
- node = astroid.extract_node("""
+ node = astroid.extract_node(
+ """
def function_foo(xarg, yarg):
'''function foo ...
@@ -747,7 +691,8 @@ class TestParamDocChecker(CheckerTestCase):
For the other parameters, see :func:`bla`
'''
return xarg + yarg
- """)
+ """
+ )
with self.assertNoMessages():
self.checker.visit_functiondef(node)
@@ -757,7 +702,8 @@ class TestParamDocChecker(CheckerTestCase):
Everything is completely analogous to functions.
"""
- node = astroid.extract_node("""
+ node = astroid.extract_node(
+ """
class ClassFoo(object):
'''docstring foo
@@ -769,16 +715,11 @@ class TestParamDocChecker(CheckerTestCase):
def __init__(self, x, y):
pass
- """)
+ """
+ )
with self.assertAddsMessages(
- Message(
- msg_id='missing-param-doc',
- node=node,
- args=('x',)),
- Message(
- msg_id='missing-type-doc',
- node=node,
- args=('x, y',))
+ Message(msg_id="missing-param-doc", node=node, args=("x",)),
+ Message(msg_id="missing-type-doc", node=node, args=("x, y",)),
):
self._visit_methods_of_class(node)
@@ -788,7 +729,8 @@ class TestParamDocChecker(CheckerTestCase):
Everything is completely analogous to functions.
"""
- node = astroid.extract_node("""
+ node = astroid.extract_node(
+ """
class ClassFoo(object):
'''docstring foo
@@ -801,16 +743,11 @@ class TestParamDocChecker(CheckerTestCase):
def __init__(self, x, y):
pass
- """)
+ """
+ )
with self.assertAddsMessages(
- Message(
- msg_id='missing-param-doc',
- node=node,
- args=('x',)),
- Message(
- msg_id='missing-type-doc',
- node=node,
- args=('x, y',))
+ Message(msg_id="missing-param-doc", node=node, args=("x",)),
+ Message(msg_id="missing-type-doc", node=node, args=("x, y",)),
):
self._visit_methods_of_class(node)
@@ -820,7 +757,8 @@ class TestParamDocChecker(CheckerTestCase):
Everything is completely analogous to functions.
"""
- node = astroid.extract_node("""
+ node = astroid.extract_node(
+ """
class ClassFoo(object):
'''docstring foo
@@ -835,16 +773,11 @@ class TestParamDocChecker(CheckerTestCase):
def __init__(self, x, y):
pass
- """)
+ """
+ )
with self.assertAddsMessages(
- Message(
- msg_id='missing-param-doc',
- node=node,
- args=('x',)),
- Message(
- msg_id='missing-type-doc',
- node=node,
- args=('x, y',))
+ Message(msg_id="missing-param-doc", node=node, args=("x",)),
+ Message(msg_id="missing-type-doc", node=node, args=("x, y",)),
):
self._visit_methods_of_class(node)
@@ -852,7 +785,8 @@ class TestParamDocChecker(CheckerTestCase):
"""Example of a class with correct constructor parameter documentation
and an attributes section (Numpy style)
"""
- node = astroid.extract_node("""
+ node = astroid.extract_node(
+ """
class ClassFoo(object):
'''
Parameters
@@ -867,7 +801,8 @@ class TestParamDocChecker(CheckerTestCase):
'''
def __init__(self, foo):
self.bar = None
- """)
+ """
+ )
with self.assertNoMessages():
self._visit_methods_of_class(node)
@@ -877,7 +812,8 @@ class TestParamDocChecker(CheckerTestCase):
Everything is completely analogous to functions.
"""
- node = astroid.extract_node("""
+ node = astroid.extract_node(
+ """
class ClassFoo(object):
def __init__(self, x, y):
'''docstring foo constructor
@@ -889,17 +825,12 @@ class TestParamDocChecker(CheckerTestCase):
pass
- """)
+ """
+ )
constructor_node = node.body[0]
with self.assertAddsMessages(
- Message(
- msg_id='missing-param-doc',
- node=constructor_node,
- args=('x',)),
- Message(
- msg_id='missing-type-doc',
- node=constructor_node,
- args=('x, y',))
+ Message(msg_id="missing-param-doc", node=constructor_node, args=("x",)),
+ Message(msg_id="missing-type-doc", node=constructor_node, args=("x, y",)),
):
self._visit_methods_of_class(node)
@@ -909,7 +840,8 @@ class TestParamDocChecker(CheckerTestCase):
Everything is completely analogous to functions.
"""
- node = astroid.extract_node("""
+ node = astroid.extract_node(
+ """
class ClassFoo(object):
def __init__(self, x, y):
'''docstring foo constructor
@@ -921,17 +853,12 @@ class TestParamDocChecker(CheckerTestCase):
'''
pass
- """)
+ """
+ )
constructor_node = node.body[0]
with self.assertAddsMessages(
- Message(
- msg_id='missing-param-doc',
- node=constructor_node,
- args=('x',)),
- Message(
- msg_id='missing-type-doc',
- node=constructor_node,
- args=('x, y',))
+ Message(msg_id="missing-param-doc", node=constructor_node, args=("x",)),
+ Message(msg_id="missing-type-doc", node=constructor_node, args=("x, y",)),
):
self._visit_methods_of_class(node)
@@ -941,7 +868,8 @@ class TestParamDocChecker(CheckerTestCase):
Everything is completely analogous to functions.
"""
- node = astroid.extract_node("""
+ node = astroid.extract_node(
+ """
class ClassFoo(object):
def __init__(self, x, y):
'''docstring foo constructor
@@ -955,23 +883,19 @@ class TestParamDocChecker(CheckerTestCase):
'''
pass
- """)
+ """
+ )
constructor_node = node.body[0]
with self.assertAddsMessages(
- Message(
- msg_id='missing-param-doc',
- node=constructor_node,
- args=('x',)),
- Message(
- msg_id='missing-type-doc',
- node=constructor_node,
- args=('x, y',))
+ Message(msg_id="missing-param-doc", node=constructor_node, args=("x",)),
+ Message(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):
"""Example usage of "For the parameters, see" in class docstring"""
- node = astroid.extract_node("""
+ node = astroid.extract_node(
+ """
class ClassFoo(object):
'''docstring foo
@@ -982,13 +906,15 @@ class TestParamDocChecker(CheckerTestCase):
'''init'''
pass
- """)
+ """
+ )
with self.assertNoMessages():
self._visit_methods_of_class(node)
def test_see_sentence_for_constr_params_in_init(self):
"""Example usage of "For the parameters, see" in init docstring"""
- node = astroid.extract_node("""
+ node = astroid.extract_node(
+ """
class ClassFoo(object):
'''foo'''
@@ -999,11 +925,11 @@ class TestParamDocChecker(CheckerTestCase):
'''
pass
- """)
+ """
+ )
with self.assertNoMessages():
self._visit_methods_of_class(node)
-
def test_constr_params_in_class_and_init_sphinx(self):
"""Example of a class with missing constructor parameter documentation
in both the init docstring and the class docstring
@@ -1011,7 +937,8 @@ class TestParamDocChecker(CheckerTestCase):
Everything is completely analogous to functions.
"""
- node = astroid.extract_node("""
+ node = astroid.extract_node(
+ """
class ClassFoo(object):
'''docstring foo
@@ -1029,29 +956,15 @@ class TestParamDocChecker(CheckerTestCase):
'''
pass
- """)
+ """
+ )
constructor_node = node.body[0]
with self.assertAddsMessages(
- Message(
- msg_id='multiple-constructor-doc',
- node=node,
- args=(node.name,)),
- Message(
- msg_id='missing-param-doc',
- node=node,
- args=('x',)),
- Message(
- msg_id='missing-type-doc',
- node=node,
- args=('x, y',)),
- Message(
- msg_id='missing-param-doc',
- node=constructor_node,
- args=('x',)),
- Message(
- msg_id='missing-type-doc',
- node=constructor_node,
- args=('x, y',)),
+ Message(msg_id="multiple-constructor-doc", node=node, args=(node.name,)),
+ Message(msg_id="missing-param-doc", node=node, args=("x",)),
+ Message(msg_id="missing-type-doc", node=node, args=("x, y",)),
+ Message(msg_id="missing-param-doc", node=constructor_node, args=("x",)),
+ Message(msg_id="missing-type-doc", node=constructor_node, args=("x, y",)),
):
self._visit_methods_of_class(node)
@@ -1062,7 +975,8 @@ class TestParamDocChecker(CheckerTestCase):
Everything is completely analogous to functions.
"""
- node = astroid.extract_node("""
+ node = astroid.extract_node(
+ """
class ClassFoo(object):
'''docstring foo
@@ -1082,29 +996,15 @@ class TestParamDocChecker(CheckerTestCase):
'''
pass
- """)
+ """
+ )
constructor_node = node.body[0]
with self.assertAddsMessages(
- Message(
- msg_id='multiple-constructor-doc',
- node=node,
- args=(node.name,)),
- Message(
- msg_id='missing-param-doc',
- node=node,
- args=('x',)),
- Message(
- msg_id='missing-type-doc',
- node=node,
- args=('x, y',)),
- Message(
- msg_id='missing-param-doc',
- node=constructor_node,
- args=('x',)),
- Message(
- msg_id='missing-type-doc',
- node=constructor_node,
- args=('x, y',)),
+ Message(msg_id="multiple-constructor-doc", node=node, args=(node.name,)),
+ Message(msg_id="missing-param-doc", node=node, args=("x",)),
+ Message(msg_id="missing-type-doc", node=node, args=("x, y",)),
+ Message(msg_id="missing-param-doc", node=constructor_node, args=("x",)),
+ Message(msg_id="missing-type-doc", node=constructor_node, args=("x, y",)),
):
self._visit_methods_of_class(node)
@@ -1115,7 +1015,8 @@ class TestParamDocChecker(CheckerTestCase):
Everything is completely analogous to functions.
"""
- node = astroid.extract_node("""
+ node = astroid.extract_node(
+ """
class ClassFoo(object):
'''docstring foo
@@ -1139,55 +1040,39 @@ class TestParamDocChecker(CheckerTestCase):
'''
pass
- """)
+ """
+ )
constructor_node = node.body[0]
with self.assertAddsMessages(
- Message(
- msg_id='multiple-constructor-doc',
- node=node,
- args=(node.name,)),
- Message(
- msg_id='missing-param-doc',
- node=node,
- args=('x',)),
- Message(
- msg_id='missing-type-doc',
- node=node,
- args=('x, y',)),
- Message(
- msg_id='missing-param-doc',
- node=constructor_node,
- args=('x',)),
- Message(
- msg_id='missing-type-doc',
- node=constructor_node,
- args=('x, y',)),
+ Message(msg_id="multiple-constructor-doc", node=node, args=(node.name,)),
+ Message(msg_id="missing-param-doc", node=node, args=("x",)),
+ Message(msg_id="missing-type-doc", node=node, args=("x, y",)),
+ Message(msg_id="missing-param-doc", node=constructor_node, args=("x",)),
+ Message(msg_id="missing-type-doc", node=constructor_node, args=("x, y",)),
):
self._visit_methods_of_class(node)
@pytest.mark.skipif(sys.version_info[0] != 3, reason="Enabled on Python 3")
def test_kwonlyargs_are_taken_in_account(self):
- node = astroid.extract_node('''
+ node = astroid.extract_node(
+ '''
def my_func(arg, *, kwonly, missing_kwonly):
"""The docstring
:param int arg: The argument.
:param bool kwonly: A keyword-arg.
"""
- ''')
+ '''
+ )
with self.assertAddsMessages(
- Message(
- msg_id='missing-param-doc',
- node=node,
- args=('missing_kwonly', )),
- Message(
- msg_id='missing-type-doc',
- node=node,
- args=('missing_kwonly', ))):
+ Message(msg_id="missing-param-doc", node=node, args=("missing_kwonly",)),
+ Message(msg_id="missing-type-doc", node=node, args=("missing_kwonly",)),
+ ):
self.checker.visit_functiondef(node)
def test_warns_missing_args_sphinx(self):
- node = astroid.extract_node('''
+ node = astroid.extract_node(
+ '''
def my_func(named_arg, *args):
"""The docstring
@@ -1198,16 +1083,16 @@ class TestParamDocChecker(CheckerTestCase):
"""
if args:
return named_arg
- ''')
+ '''
+ )
with self.assertAddsMessages(
- Message(
- msg_id='missing-param-doc',
- node=node,
- args=('args',))):
+ Message(msg_id="missing-param-doc", node=node, args=("args",))
+ ):
self.checker.visit_functiondef(node)
def test_warns_missing_kwargs_sphinx(self):
- node = astroid.extract_node('''
+ node = astroid.extract_node(
+ '''
def my_func(named_arg, **kwargs):
"""The docstring
@@ -1218,16 +1103,16 @@ class TestParamDocChecker(CheckerTestCase):
"""
if kwargs:
return named_arg
- ''')
+ '''
+ )
with self.assertAddsMessages(
- Message(
- msg_id='missing-param-doc',
- node=node,
- args=('kwargs',))):
+ Message(msg_id="missing-param-doc", node=node, args=("kwargs",))
+ ):
self.checker.visit_functiondef(node)
def test_warns_missing_args_google(self):
- node = astroid.extract_node('''
+ node = astroid.extract_node(
+ '''
def my_func(named_arg, *args):
"""The docstring
@@ -1239,16 +1124,16 @@ class TestParamDocChecker(CheckerTestCase):
"""
if args:
return named_arg
- ''')
+ '''
+ )
with self.assertAddsMessages(
- Message(
- msg_id='missing-param-doc',
- node=node,
- args=('args',))):
+ Message(msg_id="missing-param-doc", node=node, args=("args",))
+ ):
self.checker.visit_functiondef(node)
def test_warns_missing_kwargs_google(self):
- node = astroid.extract_node('''
+ node = astroid.extract_node(
+ '''
def my_func(named_arg, **kwargs):
"""The docstring
@@ -1260,16 +1145,16 @@ class TestParamDocChecker(CheckerTestCase):
"""
if kwargs:
return named_arg
- ''')
+ '''
+ )
with self.assertAddsMessages(
- Message(
- msg_id='missing-param-doc',
- node=node,
- args=('kwargs',))):
+ Message(msg_id="missing-param-doc", node=node, args=("kwargs",))
+ ):
self.checker.visit_functiondef(node)
def test_warns_missing_args_numpy(self):
- node = astroid.extract_node('''
+ node = astroid.extract_node(
+ '''
def my_func(named_arg, *args):
"""The docstring
@@ -1285,16 +1170,16 @@ class TestParamDocChecker(CheckerTestCase):
"""
if args:
return named_arg
- ''')
+ '''
+ )
with self.assertAddsMessages(
- Message(
- msg_id='missing-param-doc',
- node=node,
- args=('args',))):
+ Message(msg_id="missing-param-doc", node=node, args=("args",))
+ ):
self.checker.visit_functiondef(node)
def test_warns_missing_kwargs_numpy(self):
- node = astroid.extract_node('''
+ node = astroid.extract_node(
+ '''
def my_func(named_arg, **kwargs):
"""The docstring
@@ -1310,16 +1195,16 @@ class TestParamDocChecker(CheckerTestCase):
"""
if kwargs:
return named_arg
- ''')
+ '''
+ )
with self.assertAddsMessages(
- Message(
- msg_id='missing-param-doc',
- node=node,
- args=('kwargs',))):
+ Message(msg_id="missing-param-doc", node=node, args=("kwargs",))
+ ):
self.checker.visit_functiondef(node)
def test_finds_args_without_type_sphinx(self):
- node = astroid.extract_node('''
+ node = astroid.extract_node(
+ '''
def my_func(named_arg, *args):
"""The docstring
@@ -1331,12 +1216,14 @@ class TestParamDocChecker(CheckerTestCase):
"""
if args:
return named_arg
- ''')
+ '''
+ )
with self.assertNoMessages():
self.checker.visit_functiondef(node)
def test_finds_kwargs_without_type_sphinx(self):
- node = astroid.extract_node('''
+ node = astroid.extract_node(
+ '''
def my_func(named_arg, **kwargs):
"""The docstring
@@ -1348,12 +1235,14 @@ class TestParamDocChecker(CheckerTestCase):
"""
if kwargs:
return named_arg
- ''')
+ '''
+ )
with self.assertNoMessages():
self.checker.visit_functiondef(node)
def test_finds_args_without_type_google(self):
- node = astroid.extract_node('''
+ node = astroid.extract_node(
+ '''
def my_func(named_arg, *args):
"""The docstring
@@ -1366,12 +1255,14 @@ class TestParamDocChecker(CheckerTestCase):
"""
if args:
return named_arg
- ''')
+ '''
+ )
with self.assertNoMessages():
self.checker.visit_functiondef(node)
def test_finds_kwargs_without_type_google(self):
- node = astroid.extract_node('''
+ node = astroid.extract_node(
+ '''
def my_func(named_arg, **kwargs):
"""The docstring
@@ -1384,12 +1275,14 @@ class TestParamDocChecker(CheckerTestCase):
"""
if kwargs:
return named_arg
- ''')
+ '''
+ )
with self.assertNoMessages():
self.checker.visit_functiondef(node)
def test_finds_args_without_type_numpy(self):
- node = astroid.extract_node('''
+ node = astroid.extract_node(
+ '''
def my_func(named_arg, *args):
"""The docstring
@@ -1407,12 +1300,14 @@ class TestParamDocChecker(CheckerTestCase):
"""
if args:
return named_arg
- ''')
+ '''
+ )
with self.assertNoMessages():
self.checker.visit_functiondef(node)
def test_finds_args_with_xref_type_google(self):
- node = astroid.extract_node('''
+ node = astroid.extract_node(
+ '''
def my_func(named_arg, **kwargs):
"""The docstring
@@ -1425,12 +1320,14 @@ class TestParamDocChecker(CheckerTestCase):
"""
if kwargs:
return named_arg
- ''')
+ '''
+ )
with self.assertNoMessages():
self.checker.visit_functiondef(node)
def test_finds_args_with_xref_type_numpy(self):
- node = astroid.extract_node('''
+ node = astroid.extract_node(
+ '''
def my_func(named_arg, *args):
"""The docstring
@@ -1448,12 +1345,14 @@ class TestParamDocChecker(CheckerTestCase):
"""
if args:
return named_arg
- ''')
+ '''
+ )
with self.assertNoMessages():
self.checker.visit_functiondef(node)
def test_finds_kwargs_without_type_numpy(self):
- node = astroid.extract_node('''
+ node = astroid.extract_node(
+ '''
def my_func(named_arg, **kwargs):
"""The docstring
@@ -1471,29 +1370,31 @@ class TestParamDocChecker(CheckerTestCase):
"""
if kwargs:
return named_arg
- ''')
+ '''
+ )
with self.assertNoMessages():
self.checker.visit_functiondef(node)
CONTAINER_TYPES = [
- 'dict(str,str)',
- 'dict[str,str]',
- 'tuple(int)',
- 'list[tokenize.TokenInfo]',
+ "dict(str,str)",
+ "dict[str,str]",
+ "tuple(int)",
+ "list[tokenize.TokenInfo]",
]
COMPLEX_TYPES = CONTAINER_TYPES + [
- '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)',
+ "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)
+ @pytest.mark.parametrize("complex_type", COMPLEX_TYPES)
def test_finds_multiple_types_sphinx(self, complex_type):
- node = astroid.extract_node('''
+ node = astroid.extract_node(
+ '''
def my_func(named_arg):
"""The docstring
@@ -1504,13 +1405,17 @@ class TestParamDocChecker(CheckerTestCase):
:rtype: {0}
"""
return named_arg
- '''.format(complex_type))
+ '''.format(
+ complex_type
+ )
+ )
with self.assertNoMessages():
self.checker.visit_functiondef(node)
- @pytest.mark.parametrize('complex_type', COMPLEX_TYPES)
+ @pytest.mark.parametrize("complex_type", COMPLEX_TYPES)
def test_finds_multiple_types_google(self, complex_type):
- node = astroid.extract_node('''
+ node = astroid.extract_node(
+ '''
def my_func(named_arg):
"""The docstring
@@ -1521,13 +1426,17 @@ class TestParamDocChecker(CheckerTestCase):
{0}: named_arg
"""
return named_arg
- '''.format(complex_type))
+ '''.format(
+ complex_type
+ )
+ )
with self.assertNoMessages():
self.checker.visit_functiondef(node)
- @pytest.mark.parametrize('complex_type', COMPLEX_TYPES)
+ @pytest.mark.parametrize("complex_type", COMPLEX_TYPES)
def test_finds_multiple_types_numpy(self, complex_type):
- node = astroid.extract_node('''
+ node = astroid.extract_node(
+ '''
def my_func(named_arg):
"""The docstring
@@ -1542,13 +1451,17 @@ class TestParamDocChecker(CheckerTestCase):
named_arg
"""
return named_arg
- '''.format(complex_type))
+ '''.format(
+ complex_type
+ )
+ )
with self.assertNoMessages():
self.checker.visit_functiondef(node)
- @pytest.mark.parametrize('container_type', CONTAINER_TYPES)
+ @pytest.mark.parametrize("container_type", CONTAINER_TYPES)
def test_finds_compact_container_types_sphinx(self, container_type):
- node = astroid.extract_node('''
+ node = astroid.extract_node(
+ '''
def my_func(named_arg):
"""The docstring
@@ -1558,12 +1471,16 @@ class TestParamDocChecker(CheckerTestCase):
:rtype: {0}
"""
return named_arg
- '''.format(container_type))
+ '''.format(
+ container_type
+ )
+ )
with self.assertNoMessages():
self.checker.visit_functiondef(node)
def test_ignores_optional_specifier_google(self):
- node = astroid.extract_node('''
+ node = astroid.extract_node(
+ '''
def do_something(param1, param2, param3=(), param4=[], param5=[], param6=True):
"""Do something.
@@ -1579,12 +1496,14 @@ class TestParamDocChecker(CheckerTestCase):
int: Description.
"""
return param1, param2, param3, param4, param5, param6
- ''')
+ '''
+ )
with self.assertNoMessages():
self.checker.visit_functiondef(node)
def test_ignores_optional_specifier_numpy(self):
- node = astroid.extract_node('''
+ node = astroid.extract_node(
+ '''
def do_something(param, param2='all'):
"""Do something.
@@ -1601,12 +1520,14 @@ class TestParamDocChecker(CheckerTestCase):
Description.
"""
return param, param2
- ''')
+ '''
+ )
with self.assertNoMessages():
self.checker.visit_functiondef(node)
def test_finds_short_name_exception(self):
- node = astroid.extract_node('''
+ node = astroid.extract_node(
+ '''
from fake_package import BadError
def do_something(): #@
@@ -1616,7 +1537,8 @@ class TestParamDocChecker(CheckerTestCase):
~fake_package.exceptions.BadError: When something bad happened.
"""
raise BadError("A bad thing happened.")
- ''')
+ '''
+ )
with self.assertNoMessages():
self.checker.visit_functiondef(node)
@@ -1624,7 +1546,8 @@ class TestParamDocChecker(CheckerTestCase):
"""Example of a setter having missing raises documentation in
the Sphinx style docstring of the property
"""
- property_node, node = astroid.extract_node("""
+ property_node, node = astroid.extract_node(
+ """
class Foo(object):
@property
def foo(self): #@
@@ -1637,12 +1560,14 @@ class TestParamDocChecker(CheckerTestCase):
@foo.setter
def foo(self, value):
raise AttributeError() #@
- """)
+ """
+ )
with self.assertAddsMessages(
Message(
- msg_id='missing-raises-doc',
+ msg_id="missing-raises-doc",
node=property_node,
- args=('AttributeError',)),
+ args=("AttributeError",),
+ )
):
self.checker.visit_raise(node)
@@ -1650,7 +1575,8 @@ class TestParamDocChecker(CheckerTestCase):
"""Example of a setter having missing raises documentation in
the Google style docstring of the property
"""
- property_node, node = astroid.extract_node("""
+ property_node, node = astroid.extract_node(
+ """
class Foo(object):
@property
def foo(self): #@
@@ -1668,12 +1594,14 @@ class TestParamDocChecker(CheckerTestCase):
@foo.setter
def foo(self, value):
raises AttributeError() #@
- """)
+ """
+ )
with self.assertAddsMessages(
Message(
- msg_id='missing-raises-doc',
+ msg_id="missing-raises-doc",
node=property_node,
- args=('AttributeError',)),
+ args=("AttributeError",),
+ )
):
self.checker.visit_raise(node)
@@ -1681,7 +1609,8 @@ class TestParamDocChecker(CheckerTestCase):
"""Example of a setter having missing raises documentation in
the Numpy style docstring of the property
"""
- property_node, node = astroid.extract_node("""
+ property_node, node = astroid.extract_node(
+ """
class Foo(object):
@property
def foo(self): #@
@@ -1701,12 +1630,14 @@ class TestParamDocChecker(CheckerTestCase):
@foo.setter
def foo(self, value):
raises AttributeError() #@
- """)
+ """
+ )
with self.assertAddsMessages(
Message(
- msg_id='missing-raises-doc',
+ msg_id="missing-raises-doc",
node=property_node,
- args=('AttributeError',)),
+ args=("AttributeError",),
+ )
):
self.checker.visit_raise(node)
@@ -1714,7 +1645,8 @@ class TestParamDocChecker(CheckerTestCase):
"""Example of a setter having missing raises documentation in
its own Sphinx style docstring
"""
- setter_node, node = astroid.extract_node("""
+ setter_node, node = astroid.extract_node(
+ """
class Foo(object):
@property
def foo(self):
@@ -1733,12 +1665,12 @@ class TestParamDocChecker(CheckerTestCase):
:type: None
'''
raise AttributeError() #@
- """)
+ """
+ )
with self.assertAddsMessages(
Message(
- msg_id='missing-raises-doc',
- node=setter_node,
- args=('AttributeError',)),
+ msg_id="missing-raises-doc", node=setter_node, args=("AttributeError",)
+ )
):
self.checker.visit_raise(node)
@@ -1746,7 +1678,8 @@ class TestParamDocChecker(CheckerTestCase):
"""Example of a setter having missing raises documentation in
its own Google style docstring of the property
"""
- setter_node, node = astroid.extract_node("""
+ setter_node, node = astroid.extract_node(
+ """
class Foo(object):
@property
def foo(self):
@@ -1768,12 +1701,12 @@ class TestParamDocChecker(CheckerTestCase):
if True:
raise AttributeError() #@
raise RuntimeError()
- """)
+ """
+ )
with self.assertAddsMessages(
Message(
- msg_id='missing-raises-doc',
- node=setter_node,
- args=('AttributeError',)),
+ msg_id="missing-raises-doc", node=setter_node, args=("AttributeError",)
+ )
):
self.checker.visit_raise(node)
@@ -1781,7 +1714,8 @@ class TestParamDocChecker(CheckerTestCase):
"""Example of a setter having missing raises documentation in
its own Numpy style docstring of the property
"""
- setter_node, node = astroid.extract_node("""
+ setter_node, node = astroid.extract_node(
+ """
class Foo(object):
@property
def foo(self):
@@ -1807,12 +1741,12 @@ class TestParamDocChecker(CheckerTestCase):
if True:
raise AttributeError() #@
raise RuntimeError()
- """)
+ """
+ )
with self.assertAddsMessages(
Message(
- msg_id='missing-raises-doc',
- node=setter_node,
- args=('AttributeError',)),
+ msg_id="missing-raises-doc", node=setter_node, args=("AttributeError",)
+ )
):
self.checker.visit_raise(node)
@@ -1820,7 +1754,8 @@ class TestParamDocChecker(CheckerTestCase):
"""Example of a property having return documentation in
a Sphinx style docstring
"""
- node = astroid.extract_node("""
+ node = astroid.extract_node(
+ """
class Foo(object):
@property
def foo(self): #@
@@ -1829,7 +1764,8 @@ class TestParamDocChecker(CheckerTestCase):
:type: int
'''
return 10
- """)
+ """
+ )
with self.assertNoMessages():
self.checker.visit_functiondef(node)
@@ -1837,7 +1773,8 @@ class TestParamDocChecker(CheckerTestCase):
"""Example of a property having return documentation in
a Google style docstring
"""
- node = astroid.extract_node("""
+ node = astroid.extract_node(
+ """
class Foo(object):
@property
def foo(self): #@
@@ -1848,7 +1785,8 @@ class TestParamDocChecker(CheckerTestCase):
'''
raise RuntimeError()
return 10
- """)
+ """
+ )
with self.assertNoMessages():
self.checker.visit_functiondef(node)
@@ -1856,7 +1794,8 @@ class TestParamDocChecker(CheckerTestCase):
"""Example of a property having return documentation in
a numpy style docstring
"""
- node = astroid.extract_node("""
+ node = astroid.extract_node(
+ """
class Foo(object):
@property
def foo(self): #@
@@ -1869,7 +1808,8 @@ class TestParamDocChecker(CheckerTestCase):
'''
raise RuntimeError()
return 10
- """)
+ """
+ )
with self.assertNoMessages():
self.checker.visit_functiondef(node)
@@ -1877,7 +1817,8 @@ class TestParamDocChecker(CheckerTestCase):
"""Example of a property having missing return documentation in
a Sphinx style docstring
"""
- property_node, node = astroid.extract_node("""
+ property_node, node = astroid.extract_node(
+ """
class Foo(object):
@property
def foo(self) -> int: #@
@@ -1887,7 +1828,8 @@ class TestParamDocChecker(CheckerTestCase):
'''
raise RuntimeError()
return 10 #@
- """)
+ """
+ )
with self.assertNoMessages():
self.checker.visit_return(node)
@@ -1895,7 +1837,8 @@ class TestParamDocChecker(CheckerTestCase):
"""Example of a property having missing return documentation in
a Sphinx style docstring
"""
- property_node, node = astroid.extract_node("""
+ property_node, node = astroid.extract_node(
+ """
class Foo(object):
@property
def foo(self): #@
@@ -1905,11 +1848,10 @@ class TestParamDocChecker(CheckerTestCase):
'''
raise RuntimeError()
return 10 #@
- """)
+ """
+ )
with self.assertAddsMessages(
- Message(
- msg_id='missing-return-type-doc',
- node=property_node),
+ Message(msg_id="missing-return-type-doc", node=property_node)
):
self.checker.visit_return(node)
@@ -1917,7 +1859,8 @@ class TestParamDocChecker(CheckerTestCase):
"""Example of a property having return documentation in
a Google style docstring
"""
- property_node, node = astroid.extract_node("""
+ property_node, node = astroid.extract_node(
+ """
class Foo(object):
@property
def foo(self) -> int: #@
@@ -1928,7 +1871,8 @@ class TestParamDocChecker(CheckerTestCase):
'''
raise RuntimeError()
return 10 #@
- """)
+ """
+ )
with self.assertNoMessages():
self.checker.visit_return(node)
@@ -1936,7 +1880,8 @@ class TestParamDocChecker(CheckerTestCase):
"""Example of a property having return documentation in
a Google style docstring
"""
- property_node, node = astroid.extract_node("""
+ property_node, node = astroid.extract_node(
+ """
class Foo(object):
@property
def foo(self): #@
@@ -1947,11 +1892,10 @@ class TestParamDocChecker(CheckerTestCase):
'''
raise RuntimeError()
return 10 #@
- """)
+ """
+ )
with self.assertAddsMessages(
- Message(
- msg_id='missing-return-type-doc',
- node=property_node),
+ Message(msg_id="missing-return-type-doc", node=property_node)
):
self.checker.visit_return(node)
@@ -1959,7 +1903,8 @@ class TestParamDocChecker(CheckerTestCase):
"""Example of a property having return documentation in
a numpy style docstring
"""
- property_node, node = astroid.extract_node("""
+ property_node, node = astroid.extract_node(
+ """
class Foo(object):
@property
def foo(self): #@
@@ -1972,11 +1917,10 @@ class TestParamDocChecker(CheckerTestCase):
'''
raise RuntimeError()
return 10 #@
- """)
+ """
+ )
with self.assertAddsMessages(
- Message(
- msg_id='missing-return-type-doc',
- node=property_node),
+ Message(msg_id="missing-return-type-doc", node=property_node)
):
self.checker.visit_return(node)
@@ -1984,7 +1928,8 @@ class TestParamDocChecker(CheckerTestCase):
"""Example of a class function trying to use `type` as return
documentation in a Sphinx style docstring
"""
- func_node, node = astroid.extract_node("""
+ func_node, node = astroid.extract_node(
+ """
class Foo(object):
def foo(self): #@
'''docstring ...
@@ -1992,14 +1937,11 @@ class TestParamDocChecker(CheckerTestCase):
:type: int
'''
return 10 #@
- """)
+ """
+ )
with self.assertAddsMessages(
- Message(
- msg_id='missing-return-doc',
- node=func_node),
- Message(
- msg_id='missing-return-type-doc',
- node=func_node),
+ Message(msg_id="missing-return-doc", node=func_node),
+ Message(msg_id="missing-return-type-doc", node=func_node),
):
self.checker.visit_return(node)
@@ -2007,7 +1949,8 @@ class TestParamDocChecker(CheckerTestCase):
"""Example of a class function trying to use `type` as return
documentation in a Google style docstring
"""
- func_node, node = astroid.extract_node("""
+ func_node, node = astroid.extract_node(
+ """
class Foo(object):
def foo(self): #@
'''int: docstring ...
@@ -2017,14 +1960,11 @@ class TestParamDocChecker(CheckerTestCase):
'''
raise RuntimeError()
return 10 #@
- """)
+ """
+ )
with self.assertAddsMessages(
- Message(
- msg_id='missing-return-doc',
- node=func_node),
- Message(
- msg_id='missing-return-type-doc',
- node=func_node),
+ Message(msg_id="missing-return-doc", node=func_node),
+ Message(msg_id="missing-return-type-doc", node=func_node),
):
self.checker.visit_return(node)
@@ -2032,7 +1972,8 @@ class TestParamDocChecker(CheckerTestCase):
"""Example of a class function trying to use `type` as return
documentation in a numpy style docstring
"""
- func_node, node = astroid.extract_node("""
+ func_node, node = astroid.extract_node(
+ """
class Foo(object):
def foo(self): #@
'''int: docstring ...
@@ -2044,14 +1985,11 @@ class TestParamDocChecker(CheckerTestCase):
'''
raise RuntimeError()
return 10 #@
- """)
+ """
+ )
with self.assertAddsMessages(
- Message(
- msg_id='missing-return-doc',
- node=func_node),
- Message(
- msg_id='missing-return-type-doc',
- node=func_node),
+ Message(msg_id="missing-return-doc", node=func_node),
+ Message(msg_id="missing-return-type-doc", node=func_node),
):
self.checker.visit_return(node)
@@ -2059,7 +1997,8 @@ class TestParamDocChecker(CheckerTestCase):
"""Example of a class function trying to use `type` as return
documentation in a numpy style docstring
"""
- func_node, node = astroid.extract_node("""
+ func_node, node = astroid.extract_node(
+ """
class Foo(object):
def foo(self) -> int: #@
'''int: docstring ...
@@ -2071,11 +2010,10 @@ class TestParamDocChecker(CheckerTestCase):
'''
raise RuntimeError()
return 10 #@
- """)
+ """
+ )
with self.assertAddsMessages(
- Message(
- msg_id='missing-return-doc',
- node=func_node),
+ Message(msg_id="missing-return-doc", node=func_node)
):
self.checker.visit_return(node)
@@ -2083,7 +2021,8 @@ class TestParamDocChecker(CheckerTestCase):
"""Example of an abstract method documenting the return type that an
implementation should return.
"""
- node = astroid.extract_node("""
+ node = astroid.extract_node(
+ """
import abc
class Foo(object):
@abc.abstractmethod
@@ -2094,7 +2033,8 @@ class TestParamDocChecker(CheckerTestCase):
:rtype: int
'''
return 10
- """)
+ """
+ )
with self.assertNoMessages():
self.checker.visit_functiondef(node)
@@ -2102,7 +2042,8 @@ class TestParamDocChecker(CheckerTestCase):
"""Example of an abstract method documenting the return type that an
implementation should return.
"""
- node = astroid.extract_node("""
+ node = astroid.extract_node(
+ """
import abc
class Foo(object):
@abc.abstractmethod
@@ -2113,7 +2054,8 @@ class TestParamDocChecker(CheckerTestCase):
int: Ten
'''
return 10
- """)
+ """
+ )
with self.assertNoMessages():
self.checker.visit_functiondef(node)
@@ -2121,7 +2063,8 @@ class TestParamDocChecker(CheckerTestCase):
"""Example of an abstract method documenting the return type that an
implementation should return.
"""
- node = astroid.extract_node("""
+ node = astroid.extract_node(
+ """
import abc
class Foo(object):
@abc.abstractmethod
@@ -2134,14 +2077,16 @@ class TestParamDocChecker(CheckerTestCase):
Ten
'''
return 10
- """)
+ """
+ )
with self.assertNoMessages():
self.checker.visit_functiondef(node)
def test_ignores_raise_notimplementederror_sphinx(self):
"""Example of an abstract
"""
- node = astroid.extract_node("""
+ node = astroid.extract_node(
+ """
class Foo(object):
def foo(self, arg): #@
'''docstring ...
@@ -2150,7 +2095,8 @@ class TestParamDocChecker(CheckerTestCase):
:type arg: int
'''
raise NotImplementedError()
- """)
+ """
+ )
with self.assertNoMessages():
self.checker.visit_functiondef(node)
@@ -2158,7 +2104,8 @@ class TestParamDocChecker(CheckerTestCase):
"""Example of a method documenting the return type that an
implementation should return.
"""
- node = astroid.extract_node("""
+ node = astroid.extract_node(
+ """
class Foo(object):
def foo(self, arg): #@
'''docstring ...
@@ -2167,7 +2114,8 @@ class TestParamDocChecker(CheckerTestCase):
arg (int): An argument.
'''
raise NotImplementedError()
- """)
+ """
+ )
with self.assertNoMessages():
self.checker.visit_functiondef(node)
@@ -2175,7 +2123,8 @@ class TestParamDocChecker(CheckerTestCase):
"""Example of a method documenting the return type that an
implementation should return.
"""
- node = astroid.extract_node("""
+ node = astroid.extract_node(
+ """
class Foo(object):
def foo(self, arg): #@
'''docstring ...
@@ -2186,6 +2135,7 @@ class TestParamDocChecker(CheckerTestCase):
An argument.
'''
raise NotImplementedError()
- """)
+ """
+ )
with self.assertNoMessages():
self.checker.visit_functiondef(node)