Add rerun_analysis/tests/test_core.py
This commit is contained in:
parent
26b18cb7fa
commit
ceaf395666
1 changed files with 47 additions and 0 deletions
47
rerun_analysis/tests/test_core.py
Normal file
47
rerun_analysis/tests/test_core.py
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
import pytest
|
||||
from rerun_analysis import core
|
||||
|
||||
@pytest.fixture
|
||||
def sample_audit_records():
|
||||
return [
|
||||
core.AuditRecord(stratum="A", pinned=False, decision_before="FAIL", decision_after="PASS"), # helps
|
||||
core.AuditRecord(stratum="A", pinned=False, decision_before="WARN", decision_after="WARN"), # shifts (neutral)
|
||||
core.AuditRecord(stratum="A", pinned=False, decision_before="PASS", decision_after="FAIL"), # hurts
|
||||
core.AuditRecord(stratum="B", pinned=False, decision_before="FAIL", decision_after="FAIL"), # neutral
|
||||
core.AuditRecord(stratum="B", pinned=False, decision_before="WARN", decision_after="PASS"), # helps
|
||||
]
|
||||
|
||||
|
||||
def test_rerun_analysis_results_to_json():
|
||||
results = core.RerunAnalysisResults(helps=2, shifts=1, hurts=1)
|
||||
data = results.to_json()
|
||||
assert isinstance(data, dict)
|
||||
assert set(data.keys()) == {"helps", "shifts", "hurts"}
|
||||
assert data["helps"] == 2
|
||||
assert data["shifts"] == 1
|
||||
assert data["hurts"] == 1
|
||||
|
||||
|
||||
def test_calculate_rerun_effects_counts(sample_audit_records):
|
||||
result = core.calculate_rerun_effects(sample_audit_records)
|
||||
assert isinstance(result, core.RerunAnalysisResults)
|
||||
out = result.to_json()
|
||||
assert out["helps"] == 2 # FAIL->PASS and WARN->PASS
|
||||
assert out["hurts"] == 1 # PASS->FAIL
|
||||
# For shifts, depending on interpretation: decision unchanged but rerun executed
|
||||
assert out["shifts"] >= 1
|
||||
|
||||
|
||||
def test_calculate_rerun_effects_empty():
|
||||
result = core.calculate_rerun_effects([])
|
||||
assert result.to_json() == {"helps": 0, "shifts": 0, "hurts": 0}
|
||||
|
||||
|
||||
def test_input_validation_types():
|
||||
with pytest.raises(TypeError):
|
||||
core.calculate_rerun_effects([{"decision_before": "FAIL", "decision_after": "PASS"}])
|
||||
|
||||
# Valid single record should not error
|
||||
record = core.AuditRecord(stratum="X", pinned=False, decision_before="FAIL", decision_after="PASS")
|
||||
res = core.calculate_rerun_effects([record])
|
||||
assert isinstance(res, core.RerunAnalysisResults)
|
||||
Loading…
Reference in a new issue