Add policy_eval/tests/test_core.py
This commit is contained in:
parent
bae235cd3c
commit
b902cbe289
1 changed files with 61 additions and 0 deletions
61
policy_eval/tests/test_core.py
Normal file
61
policy_eval/tests/test_core.py
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
import pytest
|
||||
from policy_eval import core
|
||||
|
||||
@pytest.fixture
|
||||
def sample_drift_report():
|
||||
return {
|
||||
"reports": [
|
||||
{"status": "warn"},
|
||||
{"status": "fail"},
|
||||
{"status": "unknown"},
|
||||
{"status": "manual_override"},
|
||||
{"status": "warn"}
|
||||
]
|
||||
}
|
||||
|
||||
@pytest.fixture
|
||||
def incomplete_drift_report():
|
||||
return {
|
||||
"reports": [
|
||||
{"status": "warn"},
|
||||
{},
|
||||
{"status": "manual_override"}
|
||||
]
|
||||
}
|
||||
|
||||
@pytest.fixture
|
||||
def empty_drift_report():
|
||||
return {}
|
||||
|
||||
|
||||
def test_evaluate_policy_nominal(sample_drift_report):
|
||||
result = core.evaluate_policy(sample_drift_report)
|
||||
assert isinstance(result, dict)
|
||||
assert set(result.keys()) == {"total_warn", "total_fail", "unknowns", "manual_overrides"}
|
||||
assert result["total_warn"] == 2
|
||||
assert result["total_fail"] == 1
|
||||
assert result["unknowns"] == 1
|
||||
assert result["manual_overrides"] == 1
|
||||
|
||||
|
||||
def test_evaluate_policy_incomplete_fields(incomplete_drift_report):
|
||||
result = core.evaluate_policy(incomplete_drift_report)
|
||||
assert result["total_warn"] == 1
|
||||
assert result["total_fail"] == 0
|
||||
assert result["manual_overrides"] == 1
|
||||
assert result["unknowns"] >= 1 # missing field should count as unknown
|
||||
|
||||
|
||||
def test_evaluate_policy_empty_report(empty_drift_report):
|
||||
result = core.evaluate_policy(empty_drift_report)
|
||||
assert all(result[k] == 0 for k in result.keys())
|
||||
|
||||
|
||||
def test_evaluate_policy_invalid_type():
|
||||
with pytest.raises((TypeError, KeyError, ValueError)):
|
||||
core.evaluate_policy(None)
|
||||
|
||||
|
||||
def test_output_format_values_are_ints(sample_drift_report):
|
||||
result = core.evaluate_policy(sample_drift_report)
|
||||
assert all(isinstance(result[k], int) for k in result.keys())
|
||||
Loading…
Reference in a new issue