From e16606d68d3dc13d25c0f32d2a100fd202929ac4 Mon Sep 17 00:00:00 2001 From: Ross Barnowski Date: Sat, 18 Oct 2025 10:49:02 -0700 Subject: [PATCH 1/7] MAINT: Add missing hooks tests. --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index cfc58d90..ae6e7b96 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -168,6 +168,7 @@ attr = 'numpydoc.__version__' [tool.setuptools.package-data] numpydoc = [ 'tests/test_*.py', + 'tests/hooks/test_*.py', 'tests/tinybuild/Makefile', 'tests/tinybuild/index.rst', 'tests/tinybuild/*.py', From 50b66367690ffbf10d407dab102009065cffef73 Mon Sep 17 00:00:00 2001 From: Ross Barnowski Date: Fri, 17 Oct 2025 13:55:14 -0700 Subject: [PATCH 2/7] TST: Fix hook tests for windows. * replace path separators on windows * Add drive to path for windows --- numpydoc/tests/hooks/test_utils.py | 6 +++++- numpydoc/tests/hooks/test_validate_hook.py | 13 +++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/numpydoc/tests/hooks/test_utils.py b/numpydoc/tests/hooks/test_utils.py index 5db63762..918b9045 100644 --- a/numpydoc/tests/hooks/test_utils.py +++ b/numpydoc/tests/hooks/test_utils.py @@ -23,7 +23,11 @@ def test_find_project_root(tmp_path, request, reason_file, files, expected_reaso (tmp_path / reason_file).touch() if files: - expected_dir = Path("/") if expected_reason == "file system root" else tmp_path + if expected_reason == "file system root": + expected_dir = Path(tmp_path.drive + tmp_path.root) + else: + expected_dir = tmp_path + for file in files: (tmp_path / file).touch() else: diff --git a/numpydoc/tests/hooks/test_validate_hook.py b/numpydoc/tests/hooks/test_validate_hook.py index 7d4d2378..371df389 100644 --- a/numpydoc/tests/hooks/test_validate_hook.py +++ b/numpydoc/tests/hooks/test_validate_hook.py @@ -2,6 +2,7 @@ import inspect from pathlib import Path +import sys import pytest @@ -63,6 +64,8 @@ def test_validate_hook(example_module, config, capsys): numpydoc/tests/hooks/example_module.py:30: GL08 The object does not have a docstring """ ) + if sys.platform == "win32": + expected = expected.replace("/", "\\") return_code = run_hook([example_module], config=config) assert return_code == 1 @@ -90,6 +93,8 @@ def test_validate_hook_with_ignore(example_module, capsys): numpydoc/tests/hooks/example_module.py:30: GL08 The object does not have a docstring """ ) + if sys.platform == "win32": + expected = expected.replace("/", "\\") return_code = run_hook([example_module], ignore=["ES01", "SA01", "EX01"]) @@ -133,6 +138,8 @@ def test_validate_hook_with_toml_config(example_module, tmp_path, capsys): numpydoc/tests/hooks/example_module.py:30: GL08 The object does not have a docstring """ ) + if sys.platform == "win32": + expected = expected.replace("/", "\\") return_code = run_hook([example_module], config=tmp_path) assert return_code == 1 @@ -168,6 +175,8 @@ def test_validate_hook_with_setup_cfg(example_module, tmp_path, capsys): numpydoc/tests/hooks/example_module.py:30: GL08 The object does not have a docstring """ ) + if sys.platform == "win32": + expected = expected.replace("/", "\\") return_code = run_hook([example_module], config=tmp_path) assert return_code == 1 @@ -209,6 +218,8 @@ def test_validate_hook_exclude_option_pyproject(example_module, tmp_path, capsys numpydoc/tests/hooks/example_module.py:30: GL08 The object does not have a docstring """ ) + if sys.platform == "win32": + expected = expected.replace("/", "\\") return_code = run_hook([example_module], config=tmp_path) assert return_code == 1 @@ -242,6 +253,8 @@ def test_validate_hook_exclude_option_setup_cfg(example_module, tmp_path, capsys numpydoc/tests/hooks/example_module.py:17: PR07 Parameter "*args" has no description """ ) + if sys.platform == "win32": + expected = expected.replace("/", "\\") return_code = run_hook([example_module], config=tmp_path) assert return_code == 1 From d5bb8f20f796171e45c350a732ad7e57e0df3582 Mon Sep 17 00:00:00 2001 From: Ross Barnowski Date: Sat, 18 Oct 2025 12:26:26 -0700 Subject: [PATCH 3/7] Lint. --- numpydoc/tests/hooks/test_validate_hook.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numpydoc/tests/hooks/test_validate_hook.py b/numpydoc/tests/hooks/test_validate_hook.py index 371df389..16385fe1 100644 --- a/numpydoc/tests/hooks/test_validate_hook.py +++ b/numpydoc/tests/hooks/test_validate_hook.py @@ -1,8 +1,8 @@ """Test the numpydoc validate pre-commit hook.""" import inspect -from pathlib import Path import sys +from pathlib import Path import pytest From 0f38d76750c93c36ec686a313d0ce614a90f12aa Mon Sep 17 00:00:00 2001 From: Ross Barnowski Date: Tue, 11 Nov 2025 13:17:45 -0800 Subject: [PATCH 4/7] TST: Switch to f-strings for expected logs. Co-authored-by: Stefanie Molin <24376333+stefmolin@users.noreply.github.com> --- numpydoc/tests/hooks/test_validate_hook.py | 98 ++++++++++------------ 1 file changed, 43 insertions(+), 55 deletions(-) diff --git a/numpydoc/tests/hooks/test_validate_hook.py b/numpydoc/tests/hooks/test_validate_hook.py index 16385fe1..13d3165a 100644 --- a/numpydoc/tests/hooks/test_validate_hook.py +++ b/numpydoc/tests/hooks/test_validate_hook.py @@ -26,46 +26,44 @@ def test_validate_hook(example_module, config, capsys): """Test that a file is correctly processed in the absence of config files.""" expected = inspect.cleandoc( - """ - numpydoc/tests/hooks/example_module.py:4: ES01 No extended summary found + f""" + {example_module!s}:4: ES01 No extended summary found - numpydoc/tests/hooks/example_module.py:4: PR01 Parameters {'name'} not documented + {example_module!s}:4: PR01 Parameters {{'name'}} not documented - numpydoc/tests/hooks/example_module.py:4: SA01 See Also section not found + {example_module!s}:4: SA01 See Also section not found - numpydoc/tests/hooks/example_module.py:4: EX01 No examples section found + {example_module!s}:4: EX01 No examples section found - numpydoc/tests/hooks/example_module.py:8: ES01 No extended summary found + {example_module!s}:8: ES01 No extended summary found - numpydoc/tests/hooks/example_module.py:8: SA01 See Also section not found + {example_module!s}:8: SA01 See Also section not found - numpydoc/tests/hooks/example_module.py:8: EX01 No examples section found + {example_module!s}:8: EX01 No examples section found - numpydoc/tests/hooks/example_module.py:11: GL08 The object does not have a docstring + {example_module!s}:11: GL08 The object does not have a docstring - numpydoc/tests/hooks/example_module.py:17: ES01 No extended summary found + {example_module!s}:17: ES01 No extended summary found - numpydoc/tests/hooks/example_module.py:17: PR01 Parameters {'**kwargs'} not documented + {example_module!s}:17: PR01 Parameters {{'**kwargs'}} not documented - numpydoc/tests/hooks/example_module.py:17: PR07 Parameter "*args" has no description + {example_module!s}:17: PR07 Parameter "*args" has no description - numpydoc/tests/hooks/example_module.py:17: SA01 See Also section not found + {example_module!s}:17: SA01 See Also section not found - numpydoc/tests/hooks/example_module.py:17: EX01 No examples section found + {example_module!s}:17: EX01 No examples section found - numpydoc/tests/hooks/example_module.py:26: SS05 Summary must start with infinitive verb, not third person (e.g. use "Generate" instead of "Generates") + {example_module!s}:26: SS05 Summary must start with infinitive verb, not third person (e.g. use "Generate" instead of "Generates") - numpydoc/tests/hooks/example_module.py:26: ES01 No extended summary found + {example_module!s}:26: ES01 No extended summary found - numpydoc/tests/hooks/example_module.py:26: SA01 See Also section not found + {example_module!s}:26: SA01 See Also section not found - numpydoc/tests/hooks/example_module.py:26: EX01 No examples section found + {example_module!s}:26: EX01 No examples section found - numpydoc/tests/hooks/example_module.py:30: GL08 The object does not have a docstring + {example_module!s}:30: GL08 The object does not have a docstring """ ) - if sys.platform == "win32": - expected = expected.replace("/", "\\") return_code = run_hook([example_module], config=config) assert return_code == 1 @@ -79,22 +77,20 @@ def test_validate_hook_with_ignore(example_module, capsys): """ expected = inspect.cleandoc( - """ - numpydoc/tests/hooks/example_module.py:4: PR01 Parameters {'name'} not documented + f""" + {example_module!s}:4: PR01 Parameters {{'name'}} not documented - numpydoc/tests/hooks/example_module.py:11: GL08 The object does not have a docstring + {example_module!s}:11: GL08 The object does not have a docstring - numpydoc/tests/hooks/example_module.py:17: PR01 Parameters {'**kwargs'} not documented + {example_module!s}:17: PR01 Parameters {{'**kwargs'}} not documented - numpydoc/tests/hooks/example_module.py:17: PR07 Parameter "*args" has no description + {example_module!s}:17: PR07 Parameter "*args" has no description - numpydoc/tests/hooks/example_module.py:26: SS05 Summary must start with infinitive verb, not third person (e.g. use "Generate" instead of "Generates") + {example_module!s}:26: SS05 Summary must start with infinitive verb, not third person (e.g. use "Generate" instead of "Generates") - numpydoc/tests/hooks/example_module.py:30: GL08 The object does not have a docstring + {example_module!s}:30: GL08 The object does not have a docstring """ ) - if sys.platform == "win32": - expected = expected.replace("/", "\\") return_code = run_hook([example_module], ignore=["ES01", "SA01", "EX01"]) @@ -128,18 +124,16 @@ def test_validate_hook_with_toml_config(example_module, tmp_path, capsys): ) expected = inspect.cleandoc( - """ - numpydoc/tests/hooks/example_module.py:4: PR01 Parameters {'name'} not documented + f""" + {example_module!s}:4: PR01 Parameters {{'name'}} not documented - numpydoc/tests/hooks/example_module.py:17: PR01 Parameters {'**kwargs'} not documented + {example_module!s}:17: PR01 Parameters {{'**kwargs'}} not documented - numpydoc/tests/hooks/example_module.py:17: PR07 Parameter "*args" has no description + {example_module!s}:17: PR07 Parameter "*args" has no description - numpydoc/tests/hooks/example_module.py:30: GL08 The object does not have a docstring + {example_module!s}:30: GL08 The object does not have a docstring """ ) - if sys.platform == "win32": - expected = expected.replace("/", "\\") return_code = run_hook([example_module], config=tmp_path) assert return_code == 1 @@ -165,18 +159,16 @@ def test_validate_hook_with_setup_cfg(example_module, tmp_path, capsys): ) expected = inspect.cleandoc( - """ - numpydoc/tests/hooks/example_module.py:4: PR01 Parameters {'name'} not documented + f""" + {example_module!s}:4: PR01 Parameters {{'name'}} not documented - numpydoc/tests/hooks/example_module.py:17: PR01 Parameters {'**kwargs'} not documented + {example_module!s}:17: PR01 Parameters {{'**kwargs'}} not documented - numpydoc/tests/hooks/example_module.py:17: PR07 Parameter "*args" has no description + {example_module!s}:17: PR07 Parameter "*args" has no description - numpydoc/tests/hooks/example_module.py:30: GL08 The object does not have a docstring + {example_module!s}:30: GL08 The object does not have a docstring """ ) - if sys.platform == "win32": - expected = expected.replace("/", "\\") return_code = run_hook([example_module], config=tmp_path) assert return_code == 1 @@ -212,14 +204,12 @@ def test_validate_hook_exclude_option_pyproject(example_module, tmp_path, capsys ) expected = inspect.cleandoc( - """ - numpydoc/tests/hooks/example_module.py:4: PR01 Parameters {'name'} not documented + f""" + {example_module!s}:4: PR01 Parameters {{'name'}} not documented - numpydoc/tests/hooks/example_module.py:30: GL08 The object does not have a docstring + {example_module!s}:30: GL08 The object does not have a docstring """ ) - if sys.platform == "win32": - expected = expected.replace("/", "\\") return_code = run_hook([example_module], config=tmp_path) assert return_code == 1 @@ -245,16 +235,14 @@ def test_validate_hook_exclude_option_setup_cfg(example_module, tmp_path, capsys ) expected = inspect.cleandoc( - """ - numpydoc/tests/hooks/example_module.py:4: PR01 Parameters {'name'} not documented + f""" + {example_module!s}:4: PR01 Parameters {{'name'}} not documented - numpydoc/tests/hooks/example_module.py:17: PR01 Parameters {'**kwargs'} not documented + {example_module!s}:17: PR01 Parameters {{'**kwargs'}} not documented - numpydoc/tests/hooks/example_module.py:17: PR07 Parameter "*args" has no description + {example_module!s}:17: PR07 Parameter "*args" has no description """ ) - if sys.platform == "win32": - expected = expected.replace("/", "\\") return_code = run_hook([example_module], config=tmp_path) assert return_code == 1 From d98679825a9d48f1838a6a1ec7c25c27ad175798 Mon Sep 17 00:00:00 2001 From: Ross Barnowski Date: Tue, 11 Nov 2025 13:52:18 -0800 Subject: [PATCH 5/7] WIP: regex munging - revert #655. --- numpydoc/tests/hooks/test_validate_hook.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/numpydoc/tests/hooks/test_validate_hook.py b/numpydoc/tests/hooks/test_validate_hook.py index 13d3165a..4bd64481 100644 --- a/numpydoc/tests/hooks/test_validate_hook.py +++ b/numpydoc/tests/hooks/test_validate_hook.py @@ -251,7 +251,7 @@ def test_validate_hook_exclude_option_setup_cfg(example_module, tmp_path, capsys @pytest.mark.parametrize( "regex, expected_code", - [(r".*(/|\\\\)example.*\.py", 0), (r".*/non_existent_match.*\.py", 1)], + [(".*(/|\\\\)example.*\.py", 0), (".*/non_existent_match.*\.py", 1)], ) def test_validate_hook_exclude_files_option_pyproject( example_module, regex, expected_code, tmp_path @@ -288,7 +288,7 @@ def test_validate_hook_exclude_files_option_pyproject( @pytest.mark.parametrize( "regex, expected_code", - [(r".*(/|\\\\)example.*\.py", 0), (r".*/non_existent_match.*\.py", 1)], + [(".*(/|\\\\)example.*\.py", 0), (".*/non_existent_match.*\.py", 1)], ) def test_validate_hook_exclude_files_option_setup_cfg( example_module, regex, expected_code, tmp_path From 4bc8baf98ded3bf828aeecb423296e25c5db37b4 Mon Sep 17 00:00:00 2001 From: Ross Barnowski Date: Tue, 11 Nov 2025 13:59:33 -0800 Subject: [PATCH 6/7] TST: use path anchor instead of drive + root. Co-authored-by: Matt Gebert --- numpydoc/tests/hooks/test_utils.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/numpydoc/tests/hooks/test_utils.py b/numpydoc/tests/hooks/test_utils.py index 918b9045..7aa11cf3 100644 --- a/numpydoc/tests/hooks/test_utils.py +++ b/numpydoc/tests/hooks/test_utils.py @@ -23,10 +23,9 @@ def test_find_project_root(tmp_path, request, reason_file, files, expected_reaso (tmp_path / reason_file).touch() if files: - if expected_reason == "file system root": - expected_dir = Path(tmp_path.drive + tmp_path.root) - else: - expected_dir = tmp_path + expected_dir = ( + Path(tmp_path.anchor) if expected_reason == "file system root" else tmp_path + ) for file in files: (tmp_path / file).touch() From 401bad6a078f96889978b937914040453a5085ae Mon Sep 17 00:00:00 2001 From: Ross Barnowski Date: Tue, 11 Nov 2025 14:07:21 -0800 Subject: [PATCH 7/7] MAINT: rm unnecessary sys import. --- numpydoc/tests/hooks/test_validate_hook.py | 1 - 1 file changed, 1 deletion(-) diff --git a/numpydoc/tests/hooks/test_validate_hook.py b/numpydoc/tests/hooks/test_validate_hook.py index 4bd64481..85fc346e 100644 --- a/numpydoc/tests/hooks/test_validate_hook.py +++ b/numpydoc/tests/hooks/test_validate_hook.py @@ -1,7 +1,6 @@ """Test the numpydoc validate pre-commit hook.""" import inspect -import sys from pathlib import Path import pytest