Skip to content

Commit 6fadb95

Browse files
committed
test(test_validate_hook.py): Added correct pyproject.toml and setup.cfg test cases for the exclude_files option
1 parent f4658ac commit 6fadb95

File tree

1 file changed

+66
-39
lines changed

1 file changed

+66
-39
lines changed

numpydoc/tests/hooks/test_validate_hook.py

Lines changed: 66 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -139,45 +139,6 @@ def test_validate_hook_with_toml_config(example_module, tmp_path, capsys):
139139
assert capsys.readouterr().err.strip() == expected
140140

141141

142-
@pytest.mark.parametrize(
143-
"regex, expected_code",
144-
[(""".*/example.*\.py""", 0), (""".*/non_existent_match.*\.py""", 1)],
145-
)
146-
def test_validate_hook_with_toml_config_exclude_files(
147-
example_module, regex, expected_code, tmp_path, capsys
148-
):
149-
"""
150-
Test that a file is correctly processed in the absence of config files
151-
with command line ignore options.
152-
"""
153-
154-
with open(tmp_path / "pyproject.toml", "w") as config_file:
155-
config_file.write(
156-
inspect.cleandoc(
157-
"""
158-
[tool.numpydoc_validation]
159-
checks = [
160-
"all",
161-
"EX01",
162-
"SA01",
163-
"ES01",
164-
]
165-
exclude = '\\.__init__$'
166-
override_SS05 = [
167-
'^Creates',
168-
]
169-
exclude_files = [
170-
"""
171-
+ regex
172-
+ """]
173-
"""
174-
)
175-
)
176-
177-
return_code = run_hook([example_module], config=tmp_path)
178-
assert return_code == expected_code # Should not-report/report findings.
179-
180-
181142
def test_validate_hook_with_setup_cfg(example_module, tmp_path, capsys):
182143
"""
183144
Test that a file is correctly processed with the config coming from
@@ -285,3 +246,69 @@ def test_validate_hook_exclude_option_setup_cfg(example_module, tmp_path, capsys
285246
return_code = run_hook([example_module], config=tmp_path)
286247
assert return_code == 1
287248
assert capsys.readouterr().err.strip() == expected
249+
250+
251+
@pytest.mark.parametrize(
252+
"regex, expected_code",
253+
[(".*(/|\\\\)example.*\.py", 0), (".*/non_existent_match.*\.py", 1)],
254+
)
255+
def test_validate_hook_exclude_files_option_pyproject(
256+
example_module, regex, expected_code, tmp_path
257+
):
258+
"""
259+
Test that the hook correctly processes the toml config and either includes
260+
or excludes files based on the `exclude_files` option.
261+
"""
262+
263+
with open(tmp_path / "pyproject.toml", "w") as config_file:
264+
config_file.write(
265+
inspect.cleandoc(
266+
f"""
267+
[tool.numpydoc_validation]
268+
checks = [
269+
"all",
270+
"EX01",
271+
"SA01",
272+
"ES01",
273+
]
274+
exclude = '\\.__init__$'
275+
override_SS05 = [
276+
'^Creates',
277+
]
278+
exclude_files = [
279+
'{regex}',
280+
]"""
281+
)
282+
)
283+
284+
return_code = run_hook([example_module], config=tmp_path)
285+
assert return_code == expected_code # Should not-report/report findings.
286+
287+
288+
@pytest.mark.parametrize(
289+
"regex, expected_code",
290+
[(".*(/|\\\\)example.*\.py", 0), (".*/non_existent_match.*\.py", 1)],
291+
)
292+
def test_validate_hook_exclude_files_option_setup_cfg(
293+
example_module, regex, expected_code, tmp_path
294+
):
295+
"""
296+
Test that the hook correctly processes the setup config and either includes
297+
or excludes files based on the `exclude_files` option.
298+
"""
299+
300+
with open(tmp_path / "setup.cfg", "w") as config_file:
301+
config_file.write(
302+
inspect.cleandoc(
303+
f"""
304+
[tool:numpydoc_validation]
305+
checks = all,EX01,SA01,ES01
306+
exclude = \\.NewClass$,\\.__init__$
307+
override_SS05 = ^Creates
308+
exclude_files = {regex}
309+
"""
310+
)
311+
)
312+
313+
return_code = run_hook([example_module], config=tmp_path)
314+
assert return_code == expected_code # Should not-report/report findings.

0 commit comments

Comments
 (0)