Skip to content

Commit f8b23eb

Browse files
authored
Move Numpy tests from TestParamDocChecker to functional tests (#5507)
1 parent cbf3976 commit f8b23eb

File tree

5 files changed

+134
-151
lines changed

5 files changed

+134
-151
lines changed

tests/extensions/test_check_docs.py

-140
Original file line numberDiff line numberDiff line change
@@ -184,146 +184,6 @@ def do_something(): #@
184184
with self.assertNoMessages():
185185
self.checker.visit_functiondef(node)
186186

187-
def test_finds_missing_raises_from_setter_numpy_2(self) -> None:
188-
"""Example of a setter having missing raises documentation in
189-
its own Numpy style docstring of the property
190-
"""
191-
setter_node, node = astroid.extract_node(
192-
"""
193-
class Foo(object):
194-
@property
195-
def foo(self):
196-
'''int: docstring ...
197-
198-
Raises
199-
------
200-
RuntimeError
201-
Always
202-
'''
203-
raise RuntimeError()
204-
return 10
205-
206-
@foo.setter
207-
def foo(self, value): #@
208-
'''setter docstring ...
209-
210-
Raises
211-
------
212-
RuntimeError
213-
Never
214-
'''
215-
if True:
216-
raise AttributeError() #@
217-
raise RuntimeError()
218-
"""
219-
)
220-
with self.assertAddsMessages(
221-
MessageTest(
222-
msg_id="missing-raises-doc", node=setter_node, args=("AttributeError",)
223-
)
224-
):
225-
self.checker.visit_raise(node)
226-
227-
def test_finds_property_return_type_numpy(self) -> None:
228-
"""Example of a property having return documentation in
229-
a numpy style docstring
230-
"""
231-
node = astroid.extract_node(
232-
"""
233-
class Foo(object):
234-
@property
235-
def foo(self): #@
236-
'''int: docstring ...
237-
238-
Raises
239-
------
240-
RuntimeError
241-
Always
242-
'''
243-
raise RuntimeError()
244-
return 10
245-
"""
246-
)
247-
with self.assertNoMessages():
248-
self.checker.visit_functiondef(node)
249-
250-
@set_config(accept_no_return_doc="no")
251-
def test_finds_missing_property_return_type_numpy(self) -> None:
252-
"""Example of a property having return documentation in
253-
a numpy style docstring
254-
"""
255-
property_node, node = astroid.extract_node(
256-
"""
257-
class Foo(object):
258-
@property
259-
def foo(self): #@
260-
'''docstring ...
261-
262-
Raises
263-
------
264-
RuntimeError
265-
Always
266-
'''
267-
raise RuntimeError()
268-
return 10 #@
269-
"""
270-
)
271-
with self.assertAddsMessages(
272-
MessageTest(msg_id="missing-return-type-doc", node=property_node)
273-
):
274-
self.checker.visit_return(node)
275-
276-
@set_config(accept_no_return_doc="no")
277-
def test_ignores_non_property_return_type_numpy(self) -> None:
278-
"""Example of a class function trying to use `type` as return
279-
documentation in a numpy style docstring
280-
"""
281-
func_node, node = astroid.extract_node(
282-
"""
283-
class Foo(object):
284-
def foo(self): #@
285-
'''int: docstring ...
286-
287-
Raises
288-
------
289-
RuntimeError
290-
Always
291-
'''
292-
raise RuntimeError()
293-
return 10 #@
294-
"""
295-
)
296-
with self.assertAddsMessages(
297-
MessageTest(msg_id="missing-return-doc", node=func_node),
298-
MessageTest(msg_id="missing-return-type-doc", node=func_node),
299-
):
300-
self.checker.visit_return(node)
301-
302-
@set_config(accept_no_return_doc="no")
303-
def test_non_property_annotation_return_type_numpy(self) -> None:
304-
"""Example of a class function trying to use `type` as return
305-
documentation in a numpy style docstring
306-
"""
307-
func_node, node = astroid.extract_node(
308-
"""
309-
class Foo(object):
310-
def foo(self) -> int: #@
311-
'''int: docstring ...
312-
313-
Raises
314-
------
315-
RuntimeError
316-
Always
317-
'''
318-
raise RuntimeError()
319-
return 10 #@
320-
"""
321-
)
322-
with self.assertAddsMessages(
323-
MessageTest(msg_id="missing-return-doc", node=func_node)
324-
):
325-
self.checker.visit_return(node)
326-
327187
@set_config_directly(no_docstring_rgx=re.compile(r"^_(?!_).*$"))
328188
def test_skip_no_docstring_rgx(self) -> None:
329189
"""Example of a function that matches the default 'no-docstring-rgx' config option

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

+58-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
"""Tests for missing-raises-doc and missing-raises-type-doc for Numpy style docstrings"""
1+
"""Tests for missing-raises-doc and missing-raises-type-doc for Numpy style docstrings
2+
3+
Styleguide:
4+
https://numpydoc.readthedocs.io/en/latest/format.html#docstring-standard
5+
"""
26
# pylint: disable=function-redefined, invalid-name, undefined-variable, missing-function-docstring
37
# pylint: disable=unused-argument, try-except-raise, import-outside-toplevel
4-
# pylint: disable=too-few-public-methods, disallowed-name
8+
# pylint: disable=too-few-public-methods, disallowed-name, using-constant-test
59

610

711
def test_find_missing_numpy_raises(self): # [missing-raises-doc]
@@ -157,3 +161,55 @@ def foo(self): # [missing-raises-doc]
157161
def foo(self, value):
158162
print(self)
159163
raise AttributeError()
164+
165+
166+
class Foo:
167+
"""test_finds_missing_raises_from_setter_numpy_2
168+
Example of a setter having missing raises documentation in
169+
its own Numpy style docstring of the property
170+
"""
171+
172+
@property
173+
def foo(self):
174+
"""int: docstring ...
175+
176+
Raises
177+
------
178+
RuntimeError
179+
Always
180+
"""
181+
raise RuntimeError()
182+
return 10 # [unreachable]
183+
184+
@foo.setter
185+
def foo(self, value): # [missing-raises-doc]
186+
"""setter docstring ...
187+
188+
Raises
189+
------
190+
RuntimeError
191+
Never
192+
"""
193+
print(self)
194+
if True:
195+
raise AttributeError()
196+
raise RuntimeError()
197+
198+
199+
class Foo:
200+
"""test_finds_property_return_type_numpy
201+
Example of a property having return documentation in
202+
a numpy style docstring
203+
"""
204+
205+
@property
206+
def foo(self):
207+
"""int: docstring ...
208+
209+
Raises
210+
------
211+
RuntimeError
212+
Always
213+
"""
214+
raise RuntimeError()
215+
return 10 # [unreachable]
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
missing-raises-doc:7:0:16:25:test_find_missing_numpy_raises:"""RuntimeError"" not documented as being raised":UNDEFINED
2-
unreachable:16:4:16:25:test_find_missing_numpy_raises:Unreachable code:UNDEFINED
3-
unreachable:30:4:30:25:test_find_all_numpy_raises:Unreachable code:UNDEFINED
4-
missing-raises-doc:33:0:46:25:test_find_rethrown_numpy_raises:"""RuntimeError"" not documented as being raised":UNDEFINED
5-
missing-raises-doc:49:0:62:25:test_find_rethrown_numpy_multiple_raises:"""RuntimeError, ValueError"" not documented as being raised":UNDEFINED
6-
missing-raises-doc:107:0:117:21:test_find_valid_missing_numpy_attr_raises:"""error"" not documented as being raised":UNDEFINED
7-
missing-raises-doc:142:4:154:17:Foo.foo:"""AttributeError"" not documented as being raised":UNDEFINED
8-
unreachable:154:8:154:17:Foo.foo:Unreachable code:UNDEFINED
1+
missing-raises-doc:11:0:20:25:test_find_missing_numpy_raises:"""RuntimeError"" not documented as being raised":UNDEFINED
2+
unreachable:20:4:20:25:test_find_missing_numpy_raises:Unreachable code:UNDEFINED
3+
unreachable:34:4:34:25:test_find_all_numpy_raises:Unreachable code:UNDEFINED
4+
missing-raises-doc:37:0:50:25:test_find_rethrown_numpy_raises:"""RuntimeError"" not documented as being raised":UNDEFINED
5+
missing-raises-doc:53:0:66:25:test_find_rethrown_numpy_multiple_raises:"""RuntimeError, ValueError"" not documented as being raised":UNDEFINED
6+
missing-raises-doc:111:0:121:21:test_find_valid_missing_numpy_attr_raises:"""error"" not documented as being raised":UNDEFINED
7+
missing-raises-doc:146:4:158:17:Foo.foo:"""AttributeError"" not documented as being raised":UNDEFINED
8+
unreachable:158:8:158:17:Foo.foo:Unreachable code:UNDEFINED
9+
unreachable:182:8:182:17:Foo.foo:Unreachable code:UNDEFINED
10+
missing-raises-doc:185:4:196:28:Foo.foo:"""AttributeError"" not documented as being raised":UNDEFINED
11+
unreachable:215:8:215:17:Foo.foo:Unreachable code:UNDEFINED

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

+58-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Tests for missing-return-doc and missing-return-type-doc for Numpy 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, doc_type): # [missing-return-doc]
@@ -38,3 +38,60 @@ 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_numpy
45+
Example of a property having return documentation in
46+
a numpy style docstring
47+
"""
48+
49+
@property
50+
def foo_prop(self): # [missing-return-type-doc]
51+
"""docstring ...
52+
53+
Raises
54+
------
55+
RuntimeError
56+
Always
57+
"""
58+
raise RuntimeError()
59+
return 10 # [unreachable]
60+
61+
62+
class Foo:
63+
"""test_ignores_non_property_return_type_numpy
64+
Example of a class function trying to use `type` as return
65+
documentation in a numpy style docstring
66+
"""
67+
68+
def foo_method(self): # [missing-return-doc, missing-return-type-doc]
69+
"""int: docstring ...
70+
71+
Raises
72+
------
73+
RuntimeError
74+
Always
75+
"""
76+
print(self)
77+
raise RuntimeError()
78+
return 10 # [unreachable]
79+
80+
81+
class Foo:
82+
"""test_non_property_annotation_return_type_numpy
83+
Example of a class function trying to use `type` as return
84+
documentation in a numpy style docstring
85+
"""
86+
87+
def foo_method(self) -> int: # [missing-return-doc]
88+
"""int: docstring ...
89+
90+
Raises
91+
------
92+
RuntimeError
93+
Always
94+
"""
95+
print(self)
96+
raise RuntimeError()
97+
return 10 # [unreachable]

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

+7
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,10 @@ missing-return-doc:7:0:19:16:my_func:Missing return documentation:UNDEFINED
22
missing-return-doc:22:0:30:16:my_func:Missing return documentation:UNDEFINED
33
missing-return-type-doc:22:0:30:16:my_func:Missing return type documentation:UNDEFINED
44
missing-return-doc:33:0:40:29:my_func:Missing return documentation:UNDEFINED
5+
missing-return-type-doc:50:4:59:17:Foo.foo_prop:Missing return type documentation:UNDEFINED
6+
unreachable:59:8:59:17:Foo.foo_prop:Unreachable code:UNDEFINED
7+
missing-return-doc:68:4:78:17:Foo.foo_method:Missing return documentation:UNDEFINED
8+
missing-return-type-doc:68:4:78:17:Foo.foo_method:Missing return type documentation:UNDEFINED
9+
unreachable:78:8:78:17:Foo.foo_method:Unreachable code:UNDEFINED
10+
missing-return-doc:87:4:97:17:Foo.foo_method:Missing return documentation:UNDEFINED
11+
unreachable:97:8:97:17:Foo.foo_method:Unreachable code:UNDEFINED

0 commit comments

Comments
 (0)