Skip to content

Commit 9f38b98

Browse files
committed
test(test_validate_hook.py,-example_module.py): Wrote new example_module tests for AST (AbstractSyntaxTree) discovery of constructor method parent class.
1 parent 4b09325 commit 9f38b98

File tree

2 files changed

+60
-11
lines changed

2 files changed

+60
-11
lines changed

numpydoc/tests/hooks/example_module.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,35 @@ def create(self):
2828

2929

3030
class NewClass:
31-
pass
31+
class GoodConstructor:
32+
"""
33+
A nested class to test constructors via AST hook.
34+
35+
Implements constructor via class docstring.
36+
37+
Parameters
38+
----------
39+
name : str
40+
The name of the new class.
41+
"""
42+
43+
def __init__(self, name):
44+
self.name = name
45+
46+
class BadConstructor:
47+
"""
48+
A nested class to test constructors via AST hook.
49+
50+
Implements a bad constructor docstring despite having a good class docstring.
51+
52+
Parameters
53+
----------
54+
name : str
55+
The name of the new class.
56+
"""
57+
58+
def __init__(self, name):
59+
"""
60+
A failing constructor implementation without parameters.
61+
"""
62+
self.name = name

numpydoc/tests/hooks/test_validate_hook.py

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Test the numpydoc validate pre-commit hook."""
22

33
import inspect
4+
import os
45
from pathlib import Path
56

67
import pytest
@@ -40,8 +41,6 @@ def test_validate_hook(example_module, config, capsys):
4041
4142
numpydoc/tests/hooks/example_module.py:8: EX01 No examples section found
4243
43-
numpydoc/tests/hooks/example_module.py:11: GL08 The object does not have a docstring
44-
4544
numpydoc/tests/hooks/example_module.py:17: ES01 No extended summary found
4645
4746
numpydoc/tests/hooks/example_module.py:17: PR01 Parameters {'**kwargs'} not documented
@@ -61,8 +60,24 @@ def test_validate_hook(example_module, config, capsys):
6160
numpydoc/tests/hooks/example_module.py:26: EX01 No examples section found
6261
6362
numpydoc/tests/hooks/example_module.py:30: GL08 The object does not have a docstring
63+
64+
numpydoc/tests/hooks/example_module.py:31: SA01 See Also section not found
65+
66+
numpydoc/tests/hooks/example_module.py:31: EX01 No examples section found
67+
68+
numpydoc/tests/hooks/example_module.py:46: SA01 See Also section not found
69+
70+
numpydoc/tests/hooks/example_module.py:46: EX01 No examples section found
71+
72+
numpydoc/tests/hooks/example_module.py:58: ES01 No extended summary found
73+
74+
numpydoc/tests/hooks/example_module.py:58: PR01 Parameters {'name'} not documented
75+
76+
numpydoc/tests/hooks/example_module.py:58: SA01 See Also section not found
77+
78+
numpydoc/tests/hooks/example_module.py:58: EX01 No examples section found
6479
"""
65-
)
80+
).replace("/", os.sep)
6681

6782
return_code = run_hook([example_module], config=config)
6883
assert return_code == 1
@@ -79,17 +94,17 @@ def test_validate_hook_with_ignore(example_module, capsys):
7994
"""
8095
numpydoc/tests/hooks/example_module.py:4: PR01 Parameters {'name'} not documented
8196
82-
numpydoc/tests/hooks/example_module.py:11: GL08 The object does not have a docstring
83-
8497
numpydoc/tests/hooks/example_module.py:17: PR01 Parameters {'**kwargs'} not documented
8598
8699
numpydoc/tests/hooks/example_module.py:17: PR07 Parameter "*args" has no description
87100
88101
numpydoc/tests/hooks/example_module.py:26: SS05 Summary must start with infinitive verb, not third person (e.g. use "Generate" instead of "Generates")
89102
90103
numpydoc/tests/hooks/example_module.py:30: GL08 The object does not have a docstring
104+
105+
numpydoc/tests/hooks/example_module.py:58: PR01 Parameters {'name'} not documented
91106
"""
92-
)
107+
).replace("/", os.sep)
93108

94109
return_code = run_hook([example_module], ignore=["ES01", "SA01", "EX01"])
95110

@@ -132,7 +147,7 @@ def test_validate_hook_with_toml_config(example_module, tmp_path, capsys):
132147
133148
numpydoc/tests/hooks/example_module.py:30: GL08 The object does not have a docstring
134149
"""
135-
)
150+
).replace("/", os.sep)
136151

137152
return_code = run_hook([example_module], config=tmp_path)
138153
assert return_code == 1
@@ -167,7 +182,7 @@ def test_validate_hook_with_setup_cfg(example_module, tmp_path, capsys):
167182
168183
numpydoc/tests/hooks/example_module.py:30: GL08 The object does not have a docstring
169184
"""
170-
)
185+
).replace("/", os.sep)
171186

172187
return_code = run_hook([example_module], config=tmp_path)
173188
assert return_code == 1
@@ -208,7 +223,7 @@ def test_validate_hook_exclude_option_pyproject(example_module, tmp_path, capsys
208223
209224
numpydoc/tests/hooks/example_module.py:30: GL08 The object does not have a docstring
210225
"""
211-
)
226+
).replace("/", os.sep)
212227

213228
return_code = run_hook([example_module], config=tmp_path)
214229
assert return_code == 1
@@ -241,8 +256,11 @@ def test_validate_hook_exclude_option_setup_cfg(example_module, tmp_path, capsys
241256
242257
numpydoc/tests/hooks/example_module.py:17: PR07 Parameter "*args" has no description
243258
"""
244-
)
259+
).replace("/", os.sep)
245260

246261
return_code = run_hook([example_module], config=tmp_path)
247262
assert return_code == 1
248263
assert capsys.readouterr().err.strip() == expected
264+
265+
266+
# def test_validate_hook_

0 commit comments

Comments
 (0)