mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-27 19:49:05 +01:00
Test the requirements --testpaths closure
Some checks are pending
md-naming / markdown naming convention (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (mypy, mypy) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (pylint, pylint) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (rest, ) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (shellcheck, shellcheck) (push) Waiting to run
Python tests / test (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Shell tests / shell-tests (push) Waiting to run
Shell tests / lib-tests (push) Waiting to run
Shell tests / arch-tests (push) Waiting to run
Some checks are pending
md-naming / markdown naming convention (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (mypy, mypy) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (pylint, pylint) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (rest, ) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (shellcheck, shellcheck) (push) Waiting to run
Python tests / test (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Shell tests / shell-tests (push) Waiting to run
Shell tests / lib-tests (push) Waiting to run
Shell tests / arch-tests (push) Waiting to run
Bug-class-check: linux_configuration/tests/test_requirements_closure.py Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
6cc5cb75c7
commit
c2f4040acc
@ -4,7 +4,8 @@
|
||||
"meta/requirements-test.txt and meta/requirements.txt: pin hypothesis==6.170.17 and jeepney==0.9.0 (newest stable)",
|
||||
"meta/scripts/check_requirements_sync.py: new --testpaths mode; meta/scripts/_requirements_closure.py walks the import closure",
|
||||
".pre-commit-config.yaml: requirements-test-sync hook uses --testpaths and triggers on linux_configuration and meta/scripts .py files",
|
||||
"Non-goal: the --package mode used by requirements-sync is unchanged"
|
||||
"Non-goal: the --package mode used by requirements-sync is unchanged",
|
||||
"linux_configuration/tests/test_requirements_closure.py: regression test for the --testpaths mode"
|
||||
],
|
||||
"changes": [
|
||||
"The old check skipped tests/ directories and never looked at linux_configuration, so a test-only import (hypothesis in phone_lease tests) and a dependency of a script that linux_configuration/tests loads (jeepney via game_rec_dbus) passed locally and failed CI",
|
||||
@ -25,6 +26,11 @@
|
||||
"command": "check_requirements_sync.py --package python_pkg (with and without --requirements meta/requirements-test.txt)",
|
||||
"result": "pass",
|
||||
"evidence": "exit 0 both, old mode unchanged"
|
||||
},
|
||||
{
|
||||
"command": "python3 -m pytest -q linux_configuration/tests/test_requirements_closure.py",
|
||||
"result": "pass",
|
||||
"evidence": "2 passed; with the TYPE_CHECKING skip disabled both fail (red first)"
|
||||
}
|
||||
],
|
||||
"risks": [
|
||||
|
||||
58
linux_configuration/tests/test_requirements_closure.py
Normal file
58
linux_configuration/tests/test_requirements_closure.py
Normal file
@ -0,0 +1,58 @@
|
||||
"""Tests for check_requirements_sync.py --testpaths (the pytest import closure).
|
||||
|
||||
The tree mimics the repo: a package whose tests import a test-only library,
|
||||
and a script directory whose tests load a sibling helper that imports a
|
||||
library lazily. Both must be reported; a TYPE_CHECKING-only import must not.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from _requirements_closure import import_closure
|
||||
from check_requirements_sync import main
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from pathlib import Path
|
||||
|
||||
_TESTPATHS = ["pkg", "lc/tests"]
|
||||
|
||||
|
||||
def _tree(root: Path) -> None:
|
||||
"""Write the fake repo under ``root``."""
|
||||
files = {
|
||||
"pkg/__init__.py": "",
|
||||
"pkg/core.py": "import requests\n",
|
||||
"pkg/tests/test_core.py": "import hyp\nfrom pkg import core\n",
|
||||
"lc/tests/test_tool.py": (
|
||||
"from typing import TYPE_CHECKING\n"
|
||||
"if TYPE_CHECKING:\n"
|
||||
" import typeonly\n"
|
||||
"import helper\n"
|
||||
),
|
||||
"lc/tools/helper.py": "def run():\n import lazydep\n",
|
||||
"lc/tools/unused.py": "import notreached\n",
|
||||
}
|
||||
for rel, text in files.items():
|
||||
path = root / rel
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
path.write_text(text, encoding="utf-8")
|
||||
|
||||
|
||||
def test_closure_follows_local_imports_and_skips_type_checking(
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
"""Report test-only and transitive imports; skip unreached and typing-only."""
|
||||
_tree(tmp_path)
|
||||
assert import_closure(tmp_path, _TESTPATHS) == {"hyp", "lazydep", "requests"}
|
||||
|
||||
|
||||
def test_main_fails_until_every_import_is_declared(tmp_path: Path) -> None:
|
||||
"""Exit 1 while a closure import is undeclared, 0 once all are pinned."""
|
||||
_tree(tmp_path)
|
||||
reqs = tmp_path / "req.txt"
|
||||
reqs.write_text("requests==1\n", encoding="utf-8")
|
||||
argv = ["--root", str(tmp_path), "--requirements", "req.txt", "--testpaths"]
|
||||
assert main([*argv, *_TESTPATHS]) == 1
|
||||
reqs.write_text("requests==1\nhyp==1\nlazydep==1\n", encoding="utf-8")
|
||||
assert main([*argv, *_TESTPATHS]) == 0
|
||||
Loading…
Reference in New Issue
Block a user