Add gate_decision/tests/test_core.py
This commit is contained in:
parent
e2c53be770
commit
37562d68fd
1 changed files with 58 additions and 0 deletions
58
gate_decision/tests/test_core.py
Normal file
58
gate_decision/tests/test_core.py
Normal file
|
|
@ -0,0 +1,58 @@
|
||||||
|
import pytest
|
||||||
|
import json
|
||||||
|
from gate_decision import core
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def valid_summary_pass():
|
||||||
|
return {
|
||||||
|
"mischfenster_p95": 0.8,
|
||||||
|
"retry_free_in_window_rate": 0.99,
|
||||||
|
"max_value": 1.2
|
||||||
|
}
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def valid_summary_fail():
|
||||||
|
return {
|
||||||
|
"mischfenster_p95": 5.0,
|
||||||
|
"retry_free_in_window_rate": 0.5,
|
||||||
|
"max_value": 10.0
|
||||||
|
}
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def invalid_summary():
|
||||||
|
return {
|
||||||
|
"mischfenster_p95": "invalid",
|
||||||
|
"retry_free_in_window_rate": 0.9
|
||||||
|
}
|
||||||
|
|
||||||
|
def test_make_decision_pass(valid_summary_pass):
|
||||||
|
result = core.make_decision(valid_summary_pass)
|
||||||
|
assert isinstance(result, dict)
|
||||||
|
assert result.get("decision") == "pass"
|
||||||
|
assert "explanation" in result
|
||||||
|
|
||||||
|
|
||||||
|
def test_make_decision_fail(valid_summary_fail):
|
||||||
|
result = core.make_decision(valid_summary_fail)
|
||||||
|
assert isinstance(result, dict)
|
||||||
|
assert result.get("decision") == "fail"
|
||||||
|
assert "explanation" in result
|
||||||
|
|
||||||
|
|
||||||
|
def test_make_decision_invalid_type(invalid_summary):
|
||||||
|
with pytest.raises((AssertionError, ValueError, TypeError)):
|
||||||
|
_ = core.make_decision(invalid_summary)
|
||||||
|
|
||||||
|
|
||||||
|
def test_deterministic_behavior(valid_summary_pass):
|
||||||
|
result1 = core.make_decision(valid_summary_pass)
|
||||||
|
result2 = core.make_decision(valid_summary_pass)
|
||||||
|
assert result1 == result2
|
||||||
|
|
||||||
|
|
||||||
|
def test_output_is_json_serializable(valid_summary_pass):
|
||||||
|
result = core.make_decision(valid_summary_pass)
|
||||||
|
json_str = json.dumps(result)
|
||||||
|
assert isinstance(json_str, str)
|
||||||
|
decoded = json.loads(json_str)
|
||||||
|
assert decoded == result
|
||||||
Loading…
Reference in a new issue