Skip to content

Commit 2408684

Browse files
authored
fix: add real coverage measurement and direct-import tests (#6)
## Summary The test suite was running scripts via subprocess, which meant pytest-cov couldn't instrument them — **coverage was silently 0% while the 90% threshold appeared to pass**. The quality gate this repo ships to downstream repos was never enforced on itself. - Make `scripts/` importable (add `__init__.py`, configure `pythonpath=["."]`) - Add `--cov=scripts --cov-report=term-missing` to `pyproject.toml` addopts - Add 79 direct-import tests across 3 new test files - Allow `_find_project_root()` to accept an optional start path for testability ## Coverage: 0% → 92% | Script | Before | After | |--------|--------|-------| | check_lint.py | 0% | 98% | | check_tests.py | 0% | 95% | | check_types.py | 0% | 92% | | check_package.py | 0% | 91% | | qa.py | 0% | 91% | | sync.py | 0% | 90% | | check_spelling.py | 0% | 90% | | check_security.py | 0% | 88% | | **Total** | **0%** | **92%** | ## Test plan - [x] 79 new direct-import tests all pass locally - [x] Lint and format clean - [x] Coverage threshold (90%) now actually enforced - [x] Existing subprocess smoke tests preserved for CI integration coverage
1 parent 3cc88f0 commit 2408684

File tree

6 files changed

+1021
-5
lines changed

6 files changed

+1021
-5
lines changed

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ strict = true
4545
files = ["scripts", "tests"]
4646

4747
[tool.pytest.ini_options]
48-
addopts = "-ra --import-mode=importlib --cov-fail-under=90"
48+
addopts = "-ra --import-mode=importlib --cov=scripts --cov-report=term-missing --cov-fail-under=90"
4949
testpaths = ["tests"]
50+
pythonpath = ["."]
5051

5152
[tool.codespell]
5253
skip = ".venv,dist,.git,.mypy_cache,.ruff_cache,.pytest_cache,reference"

scripts/__init__.py

Whitespace-only changes.

scripts/qa.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020
SCRIPT_DIR = Path(__file__).resolve().parent
2121

2222

23-
def _find_project_root() -> Path:
24-
"""Walk up from SCRIPT_DIR to find the directory containing pyproject.toml."""
25-
d = SCRIPT_DIR
23+
def _find_project_root(start: Path | None = None) -> Path:
24+
"""Walk up from *start* (default SCRIPT_DIR) to find pyproject.toml."""
25+
d = start or SCRIPT_DIR
2626
while d != d.parent:
2727
if (d / "pyproject.toml").exists():
2828
return d
2929
d = d.parent
30-
print(f"Error: could not find pyproject.toml above {SCRIPT_DIR}", file=sys.stderr)
30+
print(f"Error: could not find pyproject.toml above {d}", file=sys.stderr)
3131
sys.exit(1)
3232

3333

0 commit comments

Comments
 (0)