Skip to content

Commit 6298e1d

Browse files
committed
TST: Update tst paths to pkged paths
* replace relpath in example_module tst fixture. * Update __main__ rel to install path. * Update importlib.resources.path incantation to a pattern that works on 3.12 and 3.14. * Use cwd instead of requests.root_dir
1 parent a496a5d commit 6298e1d

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

numpydoc/tests/hooks/test_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def test_find_project_root(tmp_path, request, reason_file, files, expected_reaso
3030
for file in files:
3131
(tmp_path / file).touch()
3232
else:
33-
expected_dir = request.config.rootdir
33+
expected_dir = Path.cwd()
3434

3535
root_dir, reason = utils.find_project_root(files if not files else [tmp_path])
3636
assert reason == expected_reason

numpydoc/tests/hooks/test_validate_hook.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
"""Test the numpydoc validate pre-commit hook."""
22

3+
import importlib.resources
34
import inspect
45
import re
56
from pathlib import Path
67

78
import pytest
89

10+
import numpydoc
911
from numpydoc.hooks.validate_docstrings import run_hook
1012

1113

1214
@pytest.fixture
1315
def example_module(request):
14-
fullpath = (
15-
Path(request.config.rootdir)
16-
/ "numpydoc"
17-
/ "tests"
18-
/ "hooks"
19-
/ "example_module.py"
20-
)
21-
return str(fullpath.relative_to(request.config.rootdir))
16+
with importlib.resources.path(numpydoc, "tests") as fpath:
17+
fullpath = str(fpath / "hooks/example_module.py")
18+
return str(fullpath)
2219

2320

2421
@pytest.mark.parametrize("config", [None, "fake_dir"])

numpydoc/tests/test_main.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import importlib.resources
12
import inspect
23
import io
34
import sys
@@ -119,12 +120,15 @@ def test_validate_perfect_docstring():
119120

120121
@pytest.mark.parametrize("args", [[], ["--ignore", "SS03"]])
121122
def test_lint(capsys, args):
122-
argv = ["lint", "numpydoc/__main__.py"] + args
123+
with importlib.resources.path(numpydoc, "__main__.py") as fpath:
124+
strpath = str(fpath)
125+
126+
argv = ["lint", strpath] + args
123127
if args:
124128
expected = ""
125129
expected_status = 0
126130
else:
127-
expected = "numpydoc/__main__.py:1: SS03 Summary does not end with a period"
131+
expected = f"{strpath}:1: SS03 Summary does not end with a period"
128132
expected_status = 1
129133

130134
return_status = numpydoc.cli.main(argv)

0 commit comments

Comments
 (0)