mirror of
https://github.com/elder-plinius/OBLITERATUS.git
synced 2026-08-17 16:37:30 +02:00
test: add quality-depth gates and mature CPU coverage
This commit is contained in:
@@ -2,15 +2,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
SCRIPT = Path(__file__).parents[1] / "scripts" / "check_coverage_thresholds.py"
|
||||
SPEC = importlib.util.spec_from_file_location("check_coverage_thresholds", SCRIPT)
|
||||
assert SPEC is not None and SPEC.loader is not None
|
||||
MODULE = importlib.util.module_from_spec(SPEC)
|
||||
SPEC.loader.exec_module(MODULE)
|
||||
from scripts import check_coverage_thresholds as MODULE
|
||||
|
||||
|
||||
def _report(line: float = 55.0, branch: float = 42.0) -> dict[str, object]:
|
||||
@@ -86,6 +78,30 @@ def test_validate_coverage_enforces_critical_file_floors():
|
||||
]
|
||||
|
||||
|
||||
def test_critical_file_validation_continues_and_rejects_malformed_values():
|
||||
report = _report()
|
||||
report["files"]["bool.py"] = {
|
||||
"summary": {"percent_statements_covered": True},
|
||||
}
|
||||
report["files"]["text.py"] = {
|
||||
"summary": {"percent_statements_covered": "70"},
|
||||
}
|
||||
assert MODULE.validate_coverage(
|
||||
report,
|
||||
min_line=55.0,
|
||||
min_branch=42.0,
|
||||
file_floors={
|
||||
"missing.py": 70.0,
|
||||
"bool.py": 70.0,
|
||||
"text.py": 70.0,
|
||||
},
|
||||
) == [
|
||||
"coverage report is missing critical file missing.py",
|
||||
"coverage report is missing numeric line coverage for bool.py",
|
||||
"coverage report is missing numeric line coverage for text.py",
|
||||
]
|
||||
|
||||
|
||||
def test_parse_changed_lines_and_measurement_ignore_non_executable_lines():
|
||||
diff = """diff --git a/obliteratus/example.py b/obliteratus/example.py
|
||||
+++ b/obliteratus/example.py
|
||||
@@ -111,3 +127,41 @@ def test_changed_line_gate_passes_when_diff_has_no_measured_source():
|
||||
0,
|
||||
100.0,
|
||||
)
|
||||
|
||||
|
||||
def test_changed_line_parser_ignores_hunks_before_paths_and_defaults_count_to_one():
|
||||
diff = """@@ -1 +99 @@
|
||||
+++ b/obliteratus/example.py
|
||||
@@ -2 +3 @@
|
||||
"""
|
||||
assert MODULE.parse_changed_lines(diff) == {"obliteratus/example.py": {3}}
|
||||
|
||||
|
||||
def test_changed_line_measurement_handles_missing_fields_and_multiple_files():
|
||||
report = {
|
||||
"files": {
|
||||
"obliteratus/no-fields.py": {"summary": {}},
|
||||
"obliteratus/first.py": {
|
||||
"executed_lines": [1],
|
||||
"missing_lines": [2],
|
||||
},
|
||||
"obliteratus/second.py": {
|
||||
"executed_lines": [4],
|
||||
"missing_lines": [5],
|
||||
},
|
||||
},
|
||||
}
|
||||
changed = {
|
||||
"missing-entry.py": {1},
|
||||
"obliteratus/no-fields.py": {1},
|
||||
"obliteratus/first.py": {1, 2, 99},
|
||||
"obliteratus/second.py": {4, 5, 100},
|
||||
}
|
||||
assert MODULE.changed_line_coverage(report, changed) == (2, 4, 50.0)
|
||||
|
||||
|
||||
def test_changed_line_gate_accepts_exact_floor():
|
||||
changed = {"obliteratus/example.py": {1, 2, 3, 4}}
|
||||
assert MODULE.validate_changed_coverage(
|
||||
_report(), changed, minimum=75.0,
|
||||
) == []
|
||||
|
||||
Reference in New Issue
Block a user