Add results_analysis/tests/test_core.py
This commit is contained in:
parent
a37d5d9a23
commit
bf485d2b9b
1 changed files with 62 additions and 0 deletions
62
results_analysis/tests/test_core.py
Normal file
62
results_analysis/tests/test_core.py
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
import pytest
|
||||
from results_analysis import core
|
||||
|
||||
|
||||
def test_create_confusion_matrix_basic():
|
||||
previous = [
|
||||
{"run_id": "r1", "decision": "PASS"},
|
||||
{"run_id": "r2", "decision": "FAIL"},
|
||||
{"run_id": "r3", "decision": "PASS"},
|
||||
{"run_id": "r4", "decision": "FAIL"},
|
||||
]
|
||||
new = [
|
||||
{"run_id": "r1", "decision": "PASS"}, # TP-like
|
||||
{"run_id": "r2", "decision": "FAIL"}, # TN-like
|
||||
{"run_id": "r3", "decision": "FAIL"}, # FN-like
|
||||
{"run_id": "r4", "decision": "PASS"}, # FP-like
|
||||
]
|
||||
|
||||
matrix_dict = core.create_confusion_matrix(previous, new)
|
||||
assert set(matrix_dict.keys()) == {"TP", "TN", "FP", "FN"}
|
||||
assert matrix_dict["TP"] == 1
|
||||
assert matrix_dict["TN"] == 1
|
||||
assert matrix_dict["FP"] == 1
|
||||
assert matrix_dict["FN"] == 1
|
||||
|
||||
|
||||
def test_confusion_matrix_class_to_json():
|
||||
cm = core.ConfusionMatrix(TP=2, TN=3, FP=1, FN=0)
|
||||
as_json = cm.to_json()
|
||||
assert as_json == {"TP": 2, "TN": 3, "FP": 1, "FN": 0}
|
||||
|
||||
|
||||
def test_get_deltas_detects_changes():
|
||||
previous = [
|
||||
{"run_id": "a", "decision": "PASS"},
|
||||
{"run_id": "b", "decision": "FAIL"},
|
||||
{"run_id": "c", "decision": "WARN"},
|
||||
]
|
||||
new = [
|
||||
{"run_id": "a", "decision": "PASS"},
|
||||
{"run_id": "b", "decision": "PASS"},
|
||||
{"run_id": "c", "decision": "FAIL"},
|
||||
]
|
||||
deltas = core.get_deltas(previous, new)
|
||||
ids = {d["run_id"] for d in deltas}
|
||||
assert ids == {"b", "c"}
|
||||
|
||||
|
||||
def test_empty_inputs_handling():
|
||||
# Both empty lists should yield zero-matrix and no deltas
|
||||
prev, new = [], []
|
||||
matrix_dict = core.create_confusion_matrix(prev, new)
|
||||
assert all(v == 0 for v in matrix_dict.values())
|
||||
deltas = core.get_deltas(prev, new)
|
||||
assert deltas == []
|
||||
|
||||
|
||||
def test_input_validation_typing():
|
||||
with pytest.raises((TypeError, ValueError)):
|
||||
core.create_confusion_matrix("notalist", [])
|
||||
with pytest.raises((TypeError, ValueError)):
|
||||
core.get_deltas([], "notalist")
|
||||
Loading…
Reference in a new issue