from __future__ import annotations import importlib.util from pathlib import Path REPO_ROOT = Path(__file__).resolve().parents[1] GATE_SCRIPT = REPO_ROOT / "scripts" / "check_coverage_gate.py" def _load_gate_module(): spec = importlib.util.spec_from_file_location("coverage_gate_rules", GATE_SCRIPT) assert spec is not None and spec.loader is not None module = importlib.util.module_from_spec(spec) spec.loader.exec_module(module) return module def test_coverage_gate_ignores_test_files_in_ratio(tmp_path): coverage_xml = tmp_path / "coverage.xml" coverage_xml.write_text( """ """, encoding="utf-8", ) gate = _load_gate_module() assert gate.main([str(GATE_SCRIPT), str(coverage_xml)]) == 1 def test_coverage_gate_ignores_docs_and_admin_tests_in_ratio(tmp_path): coverage_xml = tmp_path / "coverage.xml" coverage_xml.write_text( """ """, encoding="utf-8", ) gate = _load_gate_module() assert gate.main([str(GATE_SCRIPT), str(coverage_xml)]) == 1 def test_coverage_gate_accepts_core_entries_without_workspace_prefix(tmp_path): coverage_xml = tmp_path / "coverage.xml" coverage_xml.write_text( """ """, encoding="utf-8", ) gate = _load_gate_module() assert gate.main([str(GATE_SCRIPT), str(coverage_xml)]) == 0