Skip to content

Commit ad9391b

Browse files
authored
MAINT: Add missing hooks tests. (#653)
1 parent 6f40c56 commit ad9391b

File tree

3 files changed

+50
-46
lines changed

3 files changed

+50
-46
lines changed

numpydoc/tests/hooks/test_utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ def test_find_project_root(tmp_path, request, reason_file, files, expected_reaso
2323
(tmp_path / reason_file).touch()
2424

2525
if files:
26-
expected_dir = Path("/") if expected_reason == "file system root" else tmp_path
26+
expected_dir = (
27+
Path(tmp_path.anchor) if expected_reason == "file system root" else tmp_path
28+
)
29+
2730
for file in files:
2831
(tmp_path / file).touch()
2932
else:

numpydoc/tests/hooks/test_validate_hook.py

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -25,42 +25,42 @@ def test_validate_hook(example_module, config, capsys):
2525
"""Test that a file is correctly processed in the absence of config files."""
2626

2727
expected = inspect.cleandoc(
28-
"""
29-
numpydoc/tests/hooks/example_module.py:4: ES01 No extended summary found
28+
f"""
29+
{example_module!s}:4: ES01 No extended summary found
3030
31-
numpydoc/tests/hooks/example_module.py:4: PR01 Parameters {'name'} not documented
31+
{example_module!s}:4: PR01 Parameters {{'name'}} not documented
3232
33-
numpydoc/tests/hooks/example_module.py:4: SA01 See Also section not found
33+
{example_module!s}:4: SA01 See Also section not found
3434
35-
numpydoc/tests/hooks/example_module.py:4: EX01 No examples section found
35+
{example_module!s}:4: EX01 No examples section found
3636
37-
numpydoc/tests/hooks/example_module.py:8: ES01 No extended summary found
37+
{example_module!s}:8: ES01 No extended summary found
3838
39-
numpydoc/tests/hooks/example_module.py:8: SA01 See Also section not found
39+
{example_module!s}:8: SA01 See Also section not found
4040
41-
numpydoc/tests/hooks/example_module.py:8: EX01 No examples section found
41+
{example_module!s}:8: EX01 No examples section found
4242
43-
numpydoc/tests/hooks/example_module.py:11: GL08 The object does not have a docstring
43+
{example_module!s}:11: GL08 The object does not have a docstring
4444
45-
numpydoc/tests/hooks/example_module.py:17: ES01 No extended summary found
45+
{example_module!s}:17: ES01 No extended summary found
4646
47-
numpydoc/tests/hooks/example_module.py:17: PR01 Parameters {'**kwargs'} not documented
47+
{example_module!s}:17: PR01 Parameters {{'**kwargs'}} not documented
4848
49-
numpydoc/tests/hooks/example_module.py:17: PR07 Parameter "*args" has no description
49+
{example_module!s}:17: PR07 Parameter "*args" has no description
5050
51-
numpydoc/tests/hooks/example_module.py:17: SA01 See Also section not found
51+
{example_module!s}:17: SA01 See Also section not found
5252
53-
numpydoc/tests/hooks/example_module.py:17: EX01 No examples section found
53+
{example_module!s}:17: EX01 No examples section found
5454
55-
numpydoc/tests/hooks/example_module.py:26: SS05 Summary must start with infinitive verb, not third person (e.g. use "Generate" instead of "Generates")
55+
{example_module!s}:26: SS05 Summary must start with infinitive verb, not third person (e.g. use "Generate" instead of "Generates")
5656
57-
numpydoc/tests/hooks/example_module.py:26: ES01 No extended summary found
57+
{example_module!s}:26: ES01 No extended summary found
5858
59-
numpydoc/tests/hooks/example_module.py:26: SA01 See Also section not found
59+
{example_module!s}:26: SA01 See Also section not found
6060
61-
numpydoc/tests/hooks/example_module.py:26: EX01 No examples section found
61+
{example_module!s}:26: EX01 No examples section found
6262
63-
numpydoc/tests/hooks/example_module.py:30: GL08 The object does not have a docstring
63+
{example_module!s}:30: GL08 The object does not have a docstring
6464
"""
6565
)
6666

@@ -76,18 +76,18 @@ def test_validate_hook_with_ignore(example_module, capsys):
7676
"""
7777

7878
expected = inspect.cleandoc(
79-
"""
80-
numpydoc/tests/hooks/example_module.py:4: PR01 Parameters {'name'} not documented
79+
f"""
80+
{example_module!s}:4: PR01 Parameters {{'name'}} not documented
8181
82-
numpydoc/tests/hooks/example_module.py:11: GL08 The object does not have a docstring
82+
{example_module!s}:11: GL08 The object does not have a docstring
8383
84-
numpydoc/tests/hooks/example_module.py:17: PR01 Parameters {'**kwargs'} not documented
84+
{example_module!s}:17: PR01 Parameters {{'**kwargs'}} not documented
8585
86-
numpydoc/tests/hooks/example_module.py:17: PR07 Parameter "*args" has no description
86+
{example_module!s}:17: PR07 Parameter "*args" has no description
8787
88-
numpydoc/tests/hooks/example_module.py:26: SS05 Summary must start with infinitive verb, not third person (e.g. use "Generate" instead of "Generates")
88+
{example_module!s}:26: SS05 Summary must start with infinitive verb, not third person (e.g. use "Generate" instead of "Generates")
8989
90-
numpydoc/tests/hooks/example_module.py:30: GL08 The object does not have a docstring
90+
{example_module!s}:30: GL08 The object does not have a docstring
9191
"""
9292
)
9393

@@ -123,14 +123,14 @@ def test_validate_hook_with_toml_config(example_module, tmp_path, capsys):
123123
)
124124

125125
expected = inspect.cleandoc(
126-
"""
127-
numpydoc/tests/hooks/example_module.py:4: PR01 Parameters {'name'} not documented
126+
f"""
127+
{example_module!s}:4: PR01 Parameters {{'name'}} not documented
128128
129-
numpydoc/tests/hooks/example_module.py:17: PR01 Parameters {'**kwargs'} not documented
129+
{example_module!s}:17: PR01 Parameters {{'**kwargs'}} not documented
130130
131-
numpydoc/tests/hooks/example_module.py:17: PR07 Parameter "*args" has no description
131+
{example_module!s}:17: PR07 Parameter "*args" has no description
132132
133-
numpydoc/tests/hooks/example_module.py:30: GL08 The object does not have a docstring
133+
{example_module!s}:30: GL08 The object does not have a docstring
134134
"""
135135
)
136136

@@ -158,14 +158,14 @@ def test_validate_hook_with_setup_cfg(example_module, tmp_path, capsys):
158158
)
159159

160160
expected = inspect.cleandoc(
161-
"""
162-
numpydoc/tests/hooks/example_module.py:4: PR01 Parameters {'name'} not documented
161+
f"""
162+
{example_module!s}:4: PR01 Parameters {{'name'}} not documented
163163
164-
numpydoc/tests/hooks/example_module.py:17: PR01 Parameters {'**kwargs'} not documented
164+
{example_module!s}:17: PR01 Parameters {{'**kwargs'}} not documented
165165
166-
numpydoc/tests/hooks/example_module.py:17: PR07 Parameter "*args" has no description
166+
{example_module!s}:17: PR07 Parameter "*args" has no description
167167
168-
numpydoc/tests/hooks/example_module.py:30: GL08 The object does not have a docstring
168+
{example_module!s}:30: GL08 The object does not have a docstring
169169
"""
170170
)
171171

@@ -203,10 +203,10 @@ def test_validate_hook_exclude_option_pyproject(example_module, tmp_path, capsys
203203
)
204204

205205
expected = inspect.cleandoc(
206-
"""
207-
numpydoc/tests/hooks/example_module.py:4: PR01 Parameters {'name'} not documented
206+
f"""
207+
{example_module!s}:4: PR01 Parameters {{'name'}} not documented
208208
209-
numpydoc/tests/hooks/example_module.py:30: GL08 The object does not have a docstring
209+
{example_module!s}:30: GL08 The object does not have a docstring
210210
"""
211211
)
212212

@@ -234,12 +234,12 @@ def test_validate_hook_exclude_option_setup_cfg(example_module, tmp_path, capsys
234234
)
235235

236236
expected = inspect.cleandoc(
237-
"""
238-
numpydoc/tests/hooks/example_module.py:4: PR01 Parameters {'name'} not documented
237+
f"""
238+
{example_module!s}:4: PR01 Parameters {{'name'}} not documented
239239
240-
numpydoc/tests/hooks/example_module.py:17: PR01 Parameters {'**kwargs'} not documented
240+
{example_module!s}:17: PR01 Parameters {{'**kwargs'}} not documented
241241
242-
numpydoc/tests/hooks/example_module.py:17: PR07 Parameter "*args" has no description
242+
{example_module!s}:17: PR07 Parameter "*args" has no description
243243
"""
244244
)
245245

@@ -250,7 +250,7 @@ def test_validate_hook_exclude_option_setup_cfg(example_module, tmp_path, capsys
250250

251251
@pytest.mark.parametrize(
252252
"regex, expected_code",
253-
[(r".*(/|\\\\)example.*\.py", 0), (r".*/non_existent_match.*\.py", 1)],
253+
[(".*(/|\\\\)example.*\.py", 0), (".*/non_existent_match.*\.py", 1)],
254254
)
255255
def test_validate_hook_exclude_files_option_pyproject(
256256
example_module, regex, expected_code, tmp_path
@@ -287,7 +287,7 @@ def test_validate_hook_exclude_files_option_pyproject(
287287

288288
@pytest.mark.parametrize(
289289
"regex, expected_code",
290-
[(r".*(/|\\\\)example.*\.py", 0), (r".*/non_existent_match.*\.py", 1)],
290+
[(".*(/|\\\\)example.*\.py", 0), (".*/non_existent_match.*\.py", 1)],
291291
)
292292
def test_validate_hook_exclude_files_option_setup_cfg(
293293
example_module, regex, expected_code, tmp_path

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ attr = 'numpydoc.__version__'
168168
[tool.setuptools.package-data]
169169
numpydoc = [
170170
'tests/test_*.py',
171+
'tests/hooks/test_*.py',
171172
'tests/tinybuild/Makefile',
172173
'tests/tinybuild/index.rst',
173174
'tests/tinybuild/*.py',

0 commit comments

Comments
 (0)