Spaces:
Sleeping
Sleeping
| from __future__ import annotations | |
| import importlib.util | |
| from pathlib import Path | |
| ROOT = Path(__file__).resolve().parents[2] | |
| SCRIPT = ROOT / "scripts" / "check_critical_coverage.py" | |
| def _module(): | |
| spec = importlib.util.spec_from_file_location("check_critical_coverage", SCRIPT) | |
| assert spec and spec.loader | |
| module = importlib.util.module_from_spec(spec) | |
| spec.loader.exec_module(module) | |
| return module | |
| def test_critical_coverage_gate_rejects_missing_and_below_threshold() -> None: | |
| module = _module() | |
| report = {"files": {}} | |
| errors = module.validate(report) | |
| assert len(errors) == len(module.THRESHOLDS) | |
| report = { | |
| "files": { | |
| path: {"summary": {"percent_covered": threshold - 0.01}} | |
| for path, threshold in module.THRESHOLDS.items() | |
| } | |
| } | |
| assert len(module.validate(report)) == len(module.THRESHOLDS) | |
| def test_critical_coverage_gate_accepts_thresholds() -> None: | |
| module = _module() | |
| report = { | |
| "files": { | |
| path: {"summary": {"percent_covered": threshold}} | |
| for path, threshold in module.THRESHOLDS.items() | |
| } | |
| } | |
| assert module.validate(report) == [] | |