Skip to content

Commit 7523ad1

Browse files
Move tests for Google docstrings from TestParamDocChecker to functional tests (#5484)
Co-authored-by: Pierre Sassoulas <[email protected]>
1 parent 7144498 commit 7523ad1

10 files changed

+639
-829
lines changed

tests/extensions/test_check_docs.py

Lines changed: 14 additions & 822 deletions
Large diffs are not rendered by default.

tests/functional/ext/docparams/parameter/missing_param_doc_required_Google.py

Lines changed: 392 additions & 1 deletion
Large diffs are not rendered by default.

tests/functional/ext/docparams/parameter/missing_param_doc_required_Google.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ load-plugins = pylint.extensions.docparams
44
[BASIC]
55
accept-no-param-doc=no
66
docstring-min-length: -1
7+
no-docstring-rgx=^$
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
missing-param-doc:24:0:35:7:test_missing_func_params_in_google_docstring:"""y"" missing in parameter documentation":UNDEFINED
2+
missing-type-doc:24:0:35:7:test_missing_func_params_in_google_docstring:"""x, y"" missing in parameter type documentation":UNDEFINED
3+
missing-type-doc:80:0:92:7:test_missing_func_params_with_partial_annotations_in_google_docstring:"""x"" missing in parameter type documentation":UNDEFINED
4+
differing-param-doc:129:0:142:28:test_func_params_and_wrong_keyword_params_in_google_docstring:"""these"" differing in parameter documentation":UNDEFINED
5+
differing-type-doc:129:0:142:28:test_func_params_and_wrong_keyword_params_in_google_docstring:"""these"" differing in parameter type documentation":UNDEFINED
6+
missing-param-doc:129:0:142:28:test_func_params_and_wrong_keyword_params_in_google_docstring:"""that"" missing in parameter documentation":UNDEFINED
7+
missing-type-doc:129:0:142:28:test_func_params_and_wrong_keyword_params_in_google_docstring:"""that"" missing in parameter type documentation":UNDEFINED
8+
missing-param-doc:146:4:156:11:Foo.test_missing_method_params_in_google_docstring:"""y"" missing in parameter documentation":UNDEFINED
9+
missing-type-doc:146:4:156:11:Foo.test_missing_method_params_in_google_docstring:"""x, y"" missing in parameter type documentation":UNDEFINED
10+
differing-param-doc:177:0:189:22:test_wrong_name_of_func_params_in_google_docstring_one:"""xarg1, zarg1"" differing in parameter documentation":UNDEFINED
11+
differing-type-doc:177:0:189:22:test_wrong_name_of_func_params_in_google_docstring_one:"""xarg1, zarg1"" differing in parameter type documentation":UNDEFINED
12+
missing-param-doc:177:0:189:22:test_wrong_name_of_func_params_in_google_docstring_one:"""xarg, zarg"" missing in parameter documentation":UNDEFINED
13+
missing-type-doc:177:0:189:22:test_wrong_name_of_func_params_in_google_docstring_one:"""xarg, zarg"" missing in parameter type documentation":UNDEFINED
14+
differing-param-doc:192:0:203:22:test_wrong_name_of_func_params_in_google_docstring_two:"""yarg1"" differing in parameter documentation":UNDEFINED
15+
differing-type-doc:192:0:203:22:test_wrong_name_of_func_params_in_google_docstring_two:"""yarg1"" differing in parameter type documentation":UNDEFINED
16+
missing-param-doc:219:0:233:12:ClassFoo:"""x"" missing in parameter documentation":UNDEFINED
17+
missing-type-doc:219:0:233:12:ClassFoo:"""x, y"" missing in parameter type documentation":UNDEFINED
18+
missing-param-doc:237:4:246:11:ClassFoo.__init__:"""x"" missing in parameter documentation":UNDEFINED
19+
missing-type-doc:237:4:246:11:ClassFoo.__init__:"""x, y"" missing in parameter type documentation":UNDEFINED
20+
missing-param-doc:249:0:270:11:ClassFoo:"""x"" missing in parameter documentation":UNDEFINED
21+
missing-type-doc:249:0:270:11:ClassFoo:"""x, y"" missing in parameter type documentation":UNDEFINED
22+
multiple-constructor-doc:249:0:270:11:ClassFoo:"""ClassFoo"" has constructor parameters documented in class and __init__":UNDEFINED
23+
missing-param-doc:263:4:270:11:ClassFoo.__init__:"""x"" missing in parameter documentation":UNDEFINED
24+
missing-type-doc:263:4:270:11:ClassFoo.__init__:"""x, y"" missing in parameter type documentation":UNDEFINED
25+
missing-param-doc:273:0:283:24:test_warns_missing_args_google:"""*args"" missing in parameter documentation":UNDEFINED
26+
missing-param-doc:286:0:296:24:test_warns_missing_kwargs_google:"""**kwargs"" missing in parameter documentation":UNDEFINED

tests/functional/ext/docparams/raise/missing_raises_doc_Google.py

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Tests for missing-raises-doc and missing-raises-type-doc for Google style docstrings"""
22
# pylint: disable=function-redefined, invalid-name, undefined-variable, missing-function-docstring
3-
# pylint: disable=unused-argument, import-outside-toplevel, import-error, try-except-raise
3+
# pylint: disable=unused-argument, import-outside-toplevel, import-error, try-except-raise, too-few-public-methods
44

55

66
def test_find_missing_google_raises(self): # [missing-raises-doc]
@@ -136,3 +136,57 @@ def test_ignores_caught_google_raises(self):
136136
pass
137137

138138
raise NameError("hi")
139+
140+
141+
class Foo:
142+
"""test_finds_missing_raises_from_setter_google
143+
Example of a setter having missing raises documentation in
144+
the Google style docstring of the property
145+
"""
146+
147+
@property
148+
def foo_method(self): # [missing-raises-doc]
149+
"""int: docstring
150+
151+
Include a "Raises" section so that this is identified
152+
as a Google docstring and not a Numpy docstring.
153+
154+
Raises:
155+
RuntimeError: Always
156+
"""
157+
raise RuntimeError()
158+
return 10 # [unreachable]
159+
160+
@foo_method.setter
161+
def foo_method(self, value):
162+
print(self)
163+
raise AttributeError()
164+
165+
166+
class Foo:
167+
"""test_finds_missing_raises_from_setter_google_2
168+
Example of a setter having missing raises documentation in
169+
its own Google style docstring of the property.
170+
"""
171+
172+
@property
173+
def foo_method(self):
174+
"""int: docstring ...
175+
176+
Raises:
177+
RuntimeError: Always
178+
"""
179+
raise RuntimeError()
180+
return 10 # [unreachable]
181+
182+
@foo_method.setter
183+
def foo_method(self, value): # [missing-raises-doc]
184+
"""setter docstring ...
185+
186+
Raises:
187+
RuntimeError: Never
188+
"""
189+
print(self)
190+
if True: # [using-constant-test]
191+
raise AttributeError()
192+
raise RuntimeError()

tests/functional/ext/docparams/raise/missing_raises_doc_Google.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,8 @@ unreachable:95:4:95:30:test_find_multiple_google_raises:Unreachable code:UNDEFIN
77
unreachable:96:4:96:27:test_find_multiple_google_raises:Unreachable code:UNDEFINED
88
missing-raises-doc:99:0:110:25:test_find_rethrown_google_raises:"""RuntimeError"" not documented as being raised":UNDEFINED
99
missing-raises-doc:113:0:124:25:test_find_rethrown_google_multiple_raises:"""RuntimeError, ValueError"" not documented as being raised":UNDEFINED
10+
missing-raises-doc:148:4:158:17:Foo.foo_method:"""AttributeError"" not documented as being raised":UNDEFINED
11+
unreachable:158:8:158:17:Foo.foo_method:Unreachable code:UNDEFINED
12+
unreachable:180:8:180:17:Foo.foo_method:Unreachable code:UNDEFINED
13+
missing-raises-doc:183:4:192:28:Foo.foo_method:"""AttributeError"" not documented as being raised":UNDEFINED
14+
using-constant-test:190:8:191:34:Foo.foo_method:Using a conditional statement with a constant value:UNDEFINED

tests/functional/ext/docparams/return/missing_return_doc_Google.py

Lines changed: 99 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Tests for missing-return-doc and missing-return-type-doc for Google style docstrings"""
22
# pylint: disable=function-redefined, invalid-name, undefined-variable, missing-function-docstring
3-
# pylint: disable=unused-argument
3+
# pylint: disable=unused-argument, too-few-public-methods, unnecessary-pass
4+
import abc
45

56

67
def my_func(self):
@@ -75,3 +76,100 @@ def my_func(self):
7576
if a_func():
7677
return None
7778
return 1
79+
80+
81+
class Foo:
82+
"""test_finds_property_return_type_google
83+
Example of a property having return documentation in
84+
a Google style docstring
85+
"""
86+
87+
@property
88+
def foo_method(self):
89+
"""int: docstring ...
90+
91+
Raises:
92+
RuntimeError: Always
93+
"""
94+
raise RuntimeError()
95+
return 10 # [unreachable]
96+
97+
98+
class Foo:
99+
"""test_finds_annotation_property_return_type_google
100+
Example of a property having return documentation in
101+
a Google style docstring
102+
"""
103+
104+
@property
105+
def foo_method(self) -> int:
106+
"""docstring ...
107+
108+
Raises:
109+
RuntimeError: Always
110+
"""
111+
raise RuntimeError()
112+
return 10 # [unreachable]
113+
114+
115+
class Foo:
116+
"""test_ignores_return_in_abstract_method_google
117+
Example of an abstract method documenting the return type that an
118+
implementation should return.
119+
"""
120+
121+
@abc.abstractmethod
122+
def foo_method(self):
123+
"""docstring ...
124+
125+
Returns:
126+
int: Ten
127+
"""
128+
return 10
129+
130+
131+
class Foo:
132+
"""test_ignores_return_in_abstract_method_google_2
133+
Example of a method documenting the return type that an
134+
implementation should return.
135+
"""
136+
137+
def foo_method(self, arg):
138+
"""docstring ...
139+
140+
Args:
141+
arg (int): An argument.
142+
"""
143+
raise NotImplementedError()
144+
145+
146+
class Foo:
147+
"""test_ignores_ignored_argument_names_google
148+
Example of a method documenting the return type that an
149+
implementation should return.
150+
"""
151+
152+
def foo_method(self, arg, _):
153+
"""docstring ...
154+
155+
Args:
156+
arg (int): An argument.
157+
"""
158+
pass
159+
160+
161+
class Foo:
162+
"""test_useless_docs_ignored_argument_names_google
163+
Example of a method documenting the return type that an
164+
implementation should return.
165+
"""
166+
167+
def foo_method(self, arg, _, _ignored): # [useless-type-doc, useless-param-doc]
168+
"""docstring ...
169+
170+
Args:
171+
arg (int): An argument.
172+
_ (float): Another argument.
173+
_ignored: Ignored argument.
174+
"""
175+
pass
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1-
redundant-returns-doc:42:0:48:15:my_func:Redundant returns documentation:UNDEFINED
2-
redundant-returns-doc:51:0:57:15:my_func:Redundant returns documentation:UNDEFINED
3-
redundant-returns-doc:60:0:66:11:my_func:Redundant returns documentation:UNDEFINED
1+
redundant-returns-doc:43:0:49:15:my_func:Redundant returns documentation:UNDEFINED
2+
redundant-returns-doc:52:0:58:15:my_func:Redundant returns documentation:UNDEFINED
3+
redundant-returns-doc:61:0:67:11:my_func:Redundant returns documentation:UNDEFINED
4+
unreachable:95:8:95:17:Foo.foo_method:Unreachable code:UNDEFINED
5+
unreachable:112:8:112:17:Foo.foo_method:Unreachable code:UNDEFINED
6+
useless-param-doc:167:4:175:12:Foo.foo_method:"""_, _ignored"" useless ignored parameter documentation":UNDEFINED
7+
useless-type-doc:167:4:175:12:Foo.foo_method:"""_"" useless ignored parameter type documentation":UNDEFINED

tests/functional/ext/docparams/return/missing_return_doc_required_Google.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Tests for missing-return-doc and missing-return-type-doc for Google style docstrings
22
with accept-no-returns-doc = no"""
33
# pylint: disable=function-redefined, invalid-name, undefined-variable, missing-function-docstring
4-
# pylint: disable=unused-argument
4+
# pylint: disable=unused-argument, too-few-public-methods
55

66

77
def my_func(self): # [missing-return-type-doc]
@@ -38,3 +38,37 @@ def my_func(self): # [missing-return-doc]
3838
list(:class:`mymodule.Class`):
3939
"""
4040
return [mymodule.Class()]
41+
42+
43+
class Foo:
44+
"""test_finds_missing_property_return_type_google
45+
Example of a property having return documentation in
46+
a Google style docstring
47+
"""
48+
49+
@property
50+
def foo_method(self): # [missing-return-type-doc]
51+
"""docstring ...
52+
53+
Raises:
54+
RuntimeError: Always
55+
"""
56+
raise RuntimeError()
57+
return 10 # [unreachable]
58+
59+
60+
class Foo:
61+
"""test_ignores_non_property_return_type_google
62+
Example of a class function trying to use `type` as return
63+
documentation in a Google style docstring
64+
"""
65+
66+
def foo_method(self): # [missing-return-doc, missing-return-type-doc]
67+
"""int: docstring ...
68+
69+
Raises:
70+
RuntimeError: Always
71+
"""
72+
print(self)
73+
raise RuntimeError()
74+
return 10 # [unreachable]

tests/functional/ext/docparams/return/missing_return_doc_required_Google.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,8 @@ missing-return-doc:16:0:22:16:my_func:Missing return documentation:UNDEFINED
33
missing-return-doc:25:0:31:16:my_func:Missing return documentation:UNDEFINED
44
missing-return-type-doc:25:0:31:16:my_func:Missing return type documentation:UNDEFINED
55
missing-return-doc:34:0:40:29:my_func:Missing return documentation:UNDEFINED
6+
missing-return-type-doc:50:4:57:17:Foo.foo_method:Missing return type documentation:UNDEFINED
7+
unreachable:57:8:57:17:Foo.foo_method:Unreachable code:UNDEFINED
8+
missing-return-doc:66:4:74:17:Foo.foo_method:Missing return documentation:UNDEFINED
9+
missing-return-type-doc:66:4:74:17:Foo.foo_method:Missing return type documentation:UNDEFINED
10+
unreachable:74:8:74:17:Foo.foo_method:Unreachable code:UNDEFINED

0 commit comments

Comments
 (0)