diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index dc85fadc..a8145b58 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -182,3 +182,42 @@ jobs: - name: Test coverage run: | codecov + + test-sdist: + runs-on: ${{ matrix.os }}-latest + strategy: + matrix: + os: [ubuntu] + python-version: ["3.14"] + steps: + - uses: actions/checkout@v5 + + - name: Python setup + uses: actions/setup-python@v6 + with: + python-version: ${{ matrix.python-version }} + + - name: Setup environment + run: | + python -m pip install --upgrade pip wheel setuptools build + python -m pip list + + - name: Install dependencies + run: | + python -m pip install --group test --group doc + pip list + + - name: Build numpydoc + run: python -m build + + - name: Install numpydoc from source tarball + run: | + python -m pip install --no-binary numpydoc dist/*.tar.gz + pip list + + - name: Run test suite + # NOTE: Move outside of source directory to prevent any file pickup - + # ensure all tests/tests files are derived from the package *only* + run: | + mkdir foo && cd foo + pytest -v --pyargs numpydoc diff --git a/numpydoc/tests/hooks/test_utils.py b/numpydoc/tests/hooks/test_utils.py index 7aa11cf3..f0e64b01 100644 --- a/numpydoc/tests/hooks/test_utils.py +++ b/numpydoc/tests/hooks/test_utils.py @@ -30,7 +30,7 @@ def test_find_project_root(tmp_path, request, reason_file, files, expected_reaso for file in files: (tmp_path / file).touch() else: - expected_dir = request.config.rootdir + expected_dir = Path.cwd() root_dir, reason = utils.find_project_root(files if not files else [tmp_path]) assert reason == expected_reason diff --git a/numpydoc/tests/hooks/test_validate_hook.py b/numpydoc/tests/hooks/test_validate_hook.py index 6281ceef..543cd818 100644 --- a/numpydoc/tests/hooks/test_validate_hook.py +++ b/numpydoc/tests/hooks/test_validate_hook.py @@ -1,24 +1,25 @@ """Test the numpydoc validate pre-commit hook.""" +import importlib.resources import inspect import re from pathlib import Path import pytest +import numpydoc from numpydoc.hooks.validate_docstrings import run_hook @pytest.fixture def example_module(request): - fullpath = ( - Path(request.config.rootdir) - / "numpydoc" - / "tests" - / "hooks" - / "example_module.py" - ) - return str(fullpath.relative_to(request.config.rootdir)) + # TODO: When Python3.13 is the minimum version supported version, this + # can be simplified to: + # with importlib.resources.path(numpydoc, "tests/hooks/example_module.py") as fpath: + # fullpath = str(fpath) + with importlib.resources.path(numpydoc, "tests") as fpath: + fullpath = str(fpath / "hooks/example_module.py") + return str(fullpath) @pytest.mark.parametrize("config", [None, "fake_dir"]) diff --git a/numpydoc/tests/test_main.py b/numpydoc/tests/test_main.py index e07e7df2..12a5a086 100644 --- a/numpydoc/tests/test_main.py +++ b/numpydoc/tests/test_main.py @@ -1,3 +1,4 @@ +import importlib.resources import inspect import io import sys @@ -119,12 +120,15 @@ def test_validate_perfect_docstring(): @pytest.mark.parametrize("args", [[], ["--ignore", "SS03"]]) def test_lint(capsys, args): - argv = ["lint", "numpydoc/__main__.py"] + args + with importlib.resources.path(numpydoc, "__main__.py") as fpath: + strpath = str(fpath) + + argv = ["lint", strpath] + args if args: expected = "" expected_status = 0 else: - expected = "numpydoc/__main__.py:1: SS03 Summary does not end with a period" + expected = f"{strpath}:1: SS03 Summary does not end with a period" expected_status = 1 return_status = numpydoc.cli.main(argv) diff --git a/pyproject.toml b/pyproject.toml index ae6e7b96..6cae975e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -168,7 +168,7 @@ attr = 'numpydoc.__version__' [tool.setuptools.package-data] numpydoc = [ 'tests/test_*.py', - 'tests/hooks/test_*.py', + 'tests/hooks/*.py', 'tests/tinybuild/Makefile', 'tests/tinybuild/index.rst', 'tests/tinybuild/*.py',