11"""Test the numpydoc validate pre-commit hook."""
22
33import inspect
4+ import re
45from pathlib import Path
56
67import pytest
@@ -249,16 +250,17 @@ def test_validate_hook_exclude_option_setup_cfg(example_module, tmp_path, capsys
249250
250251
251252@pytest .mark .parametrize (
252- "regex , expected_code" ,
253- [(".*(/| \\ \\ )example.*\.py" , 0 ), (".*/non_existent_match.*\.py" , 1 )],
253+ "file_exists , expected_code" ,
254+ [(True , 0 ), (False , 1 )],
254255)
255256def test_validate_hook_exclude_files_option_pyproject (
256- example_module , regex , expected_code , tmp_path
257+ example_module , file_exists , expected_code , tmp_path
257258):
258259 """
259260 Test that the hook correctly processes the toml config and either includes
260261 or excludes files based on the `exclude_files` option.
261262 """
263+ exclude = str (example_module ) if file_exists else "does_not_exist.py"
262264
263265 with open (tmp_path / "pyproject.toml" , "w" ) as config_file :
264266 config_file .write (
@@ -276,7 +278,7 @@ def test_validate_hook_exclude_files_option_pyproject(
276278 '^Creates',
277279 ]
278280 exclude_files = [
279- '{ regex } ',
281+ '{ re . escape ( exclude ) } ',
280282 ]"""
281283 )
282284 )
@@ -286,16 +288,17 @@ def test_validate_hook_exclude_files_option_pyproject(
286288
287289
288290@pytest .mark .parametrize (
289- "regex , expected_code" ,
290- [(".*(/| \\ \\ )example.*\.py" , 0 ), (".*/non_existent_match.*\.py" , 1 )],
291+ "file_exists , expected_code" ,
292+ [(True , 0 ), (False , 1 )],
291293)
292294def test_validate_hook_exclude_files_option_setup_cfg (
293- example_module , regex , expected_code , tmp_path
295+ example_module , file_exists , expected_code , tmp_path
294296):
295297 """
296298 Test that the hook correctly processes the setup config and either includes
297299 or excludes files based on the `exclude_files` option.
298300 """
301+ exclude = str (example_module ) if file_exists else "does_not_exist.py"
299302
300303 with open (tmp_path / "setup.cfg" , "w" ) as config_file :
301304 config_file .write (
@@ -305,7 +308,7 @@ def test_validate_hook_exclude_files_option_setup_cfg(
305308 checks = all,EX01,SA01,ES01
306309 exclude = \\ .NewClass$,\\ .__init__$
307310 override_SS05 = ^Creates
308- exclude_files = { regex }
311+ exclude_files = { re . escape ( exclude ) }
309312 """
310313 )
311314 )
0 commit comments