Add sanity_check_tool/tests/test_core.py
This commit is contained in:
parent
6cf46d8513
commit
5f3c92a2cc
1 changed files with 66 additions and 0 deletions
66
sanity_check_tool/tests/test_core.py
Normal file
66
sanity_check_tool/tests/test_core.py
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
import pytest
|
||||
from sanity_check_tool import core
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def valid_run_data():
|
||||
return {
|
||||
"runs": [
|
||||
{"id": 1, "corr_id": "abc", "write_pre": True, "write_post": True, "clock_event": "stable", "core_field": 42},
|
||||
{"id": 2, "corr_id": "bcd", "write_pre": True, "write_post": True, "clock_event": "stable", "core_field": 24}
|
||||
],
|
||||
"sanity_checks": ["missing_pairs", "broken_ids", "empty_fields", "clock_switch_count"]
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def invalid_run_data():
|
||||
return {
|
||||
"runs": [
|
||||
{"id": 1, "corr_id": "abc", "write_pre": True, "write_post": False, "clock_event": "switch", "core_field": None},
|
||||
{"id": 2, "corr_id": None, "write_pre": True, "write_post": False, "clock_event": "switch", "core_field": ""}
|
||||
],
|
||||
"sanity_checks": ["missing_pairs", "broken_ids", "empty_fields", "clock_switch_count"]
|
||||
}
|
||||
|
||||
|
||||
def test_perform_sanity_checks_valid(valid_run_data):
|
||||
result = core.perform_sanity_checks(valid_run_data)
|
||||
assert isinstance(result, dict)
|
||||
assert set(result.keys()) == {"missing_pairs", "broken_ids", "empty_fields", "clock_switch_count"}
|
||||
assert all(isinstance(v, int) for v in result.values())
|
||||
assert result["missing_pairs"] == 0
|
||||
assert result["broken_ids"] == 0
|
||||
assert result["empty_fields"] == 0
|
||||
assert result["clock_switch_count"] == 0
|
||||
|
||||
|
||||
def test_perform_sanity_checks_invalid(invalid_run_data):
|
||||
result = core.perform_sanity_checks(invalid_run_data)
|
||||
assert isinstance(result, dict)
|
||||
assert result["missing_pairs"] > 0
|
||||
assert result["broken_ids"] >= 0
|
||||
assert result["empty_fields"] > 0
|
||||
assert result["clock_switch_count"] >= 0
|
||||
|
||||
|
||||
def test_perform_sanity_checks_input_type():
|
||||
with pytest.raises((TypeError, ValueError)):
|
||||
core.perform_sanity_checks(None)
|
||||
with pytest.raises((TypeError, ValueError)):
|
||||
core.perform_sanity_checks([])
|
||||
|
||||
|
||||
def test_perform_sanity_checks_edge_case_empty():
|
||||
run_data = {"runs": [], "sanity_checks": []}
|
||||
result = core.perform_sanity_checks(run_data)
|
||||
assert isinstance(result, dict)
|
||||
for k, v in result.items():
|
||||
assert v == 0
|
||||
|
||||
|
||||
def test_perform_sanity_checks_missing_keys():
|
||||
bad_data = {"runs": [{"foo": "bar"}], "sanity_checks": ["missing_pairs"]}
|
||||
result = core.perform_sanity_checks(bad_data)
|
||||
assert "missing_pairs" in result
|
||||
assert isinstance(result["missing_pairs"], int)
|
||||
Loading…
Reference in a new issue