summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDaniƫl van Noord <13665637+DanielNoord@users.noreply.github.com>2021-10-17 10:40:51 +0200
committerGitHub <noreply@github.com>2021-10-17 10:40:51 +0200
commitd3b27d8aeeb27441405d4183feb7b18a91925093 (patch)
tree56b4e256bc0f3acb8c5a8cfeae68166dfe1d1fe2 /tests
parent97048ded8e7528e927f7f7818beb3d5d79662b03 (diff)
downloadpylint-git-d3b27d8aeeb27441405d4183feb7b18a91925093.tar.gz
Fix ``missing-function-docstring`` not checking ``__init__`` (#5147)
* Fix ``missing-function-docstring`` not checking ``__init__`` * Ignore ``object``
Diffstat (limited to 'tests')
-rw-r--r--tests/checkers/unittest_base.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/checkers/unittest_base.py b/tests/checkers/unittest_base.py
index 48b48a450..616a0a8e7 100644
--- a/tests/checkers/unittest_base.py
+++ b/tests/checkers/unittest_base.py
@@ -58,6 +58,21 @@ class TestDocstring(CheckerTestCase):
with self.assertAddsMessages(message):
self.checker.visit_module(module)
+ @set_config(no_docstring_rgx=re.compile("^(?!__init__$)_"))
+ def test_empty_docstring_on_init(self) -> None:
+ node = astroid.extract_node(
+ """
+ #pylint disable=missing-module-docstring, too-few-public-methods,
+ class MyClass:
+ def __init__(self, my_param: int) -> None:
+ '''
+ '''
+ """
+ )
+ message = MessageTest("empty-docstring", node=node.body[0], args=("method",))
+ with self.assertAddsMessages(message):
+ self.checker.visit_functiondef(node.body[0])
+
def test_empty_docstring_function(self) -> None:
func = astroid.extract_node(
"""
@@ -116,6 +131,37 @@ class TestDocstring(CheckerTestCase):
with self.assertNoMessages():
self.checker.visit_functiondef(func)
+ @set_config(no_docstring_rgx=re.compile("^(?!__init__$)_"))
+ def test_missing_docstring_on_init(self) -> None:
+ node = astroid.extract_node(
+ """
+ #pylint disable=missing-module-docstring, too-few-public-methods,
+ class MyClass:
+ def __init__(self, my_param: int) -> None:
+ pass
+ """
+ )
+ message = MessageTest("missing-function-docstring", node=node.body[0])
+ with self.assertAddsMessages(message):
+ self.checker.visit_functiondef(node.body[0])
+
+ @set_config(no_docstring_rgx=re.compile("^(?!__eq__$)_"))
+ def test_missing_docstring_on_inherited_magic(self) -> None:
+ module = astroid.parse(
+ """
+ #pylint disable=missing-module-docstring, too-few-public-methods,
+ class MyClass:
+ pass
+
+ class Child(MyClass):
+ def __eq__(self, other):
+ return True
+ """
+ )
+ message = MessageTest("missing-function-docstring", node=module.body[1].body[0])
+ with self.assertAddsMessages(message):
+ self.checker.visit_functiondef(module.body[1].body[0])
+
def test_class_no_docstring(self) -> None:
klass = astroid.extract_node(
"""