Add sanity_check_tool/tests/test_core.py

This commit is contained in:
Mika 2026-01-22 11:58:39 +00:00
parent 0010db35c4
commit 874c71c83c

View file

@ -0,0 +1,57 @@
import pytest
from sanity_check_tool import core
@pytest.fixture
def valid_run_summary():
return {
'events': [
{'id': 1, 'type': 'write_pre', 'corr_id': 'abc', 'field': 'value'},
{'id': 2, 'type': 'write_post', 'corr_id': 'abc', 'field': 'value'},
{'id': 3, 'type': 'write_pre', 'corr_id': 'def', 'field': 'value'},
{'id': 4, 'type': 'write_post', 'corr_id': 'def', 'field': 'value'},
]
}
@pytest.fixture
def broken_run_summary():
return {
'events': [
{'id': 1, 'type': 'write_pre', 'corr_id': 'abc', 'field': 'value'},
{'id': 2, 'type': 'write_post', 'corr_id': 'xyz', 'field': 'value'},
{'id': 3, 'type': 'write_pre', 'corr_id': 'def', 'field': ''},
]
}
def test_perform_sanity_check_valid(valid_run_summary):
result = core.perform_sanity_check(valid_run_summary)
assert isinstance(result, dict), "Result should be dict"
assert set(result.keys()) == {'missing_write_pairs', 'broken_corr_ids', 'empty_fields'}
assert result['missing_write_pairs'] == 0
assert result['broken_corr_ids'] == 0
assert result['empty_fields'] == 0
def test_perform_sanity_check_broken(broken_run_summary):
result = core.perform_sanity_check(broken_run_summary)
assert result['missing_write_pairs'] >= 0
assert result['broken_corr_ids'] >= 0
assert result['empty_fields'] >= 0
assert result['broken_corr_ids'] > 0 or result['empty_fields'] > 0
def test_perform_sanity_check_invalid_input():
with pytest.raises((TypeError, KeyError)):
core.perform_sanity_check(None)
with pytest.raises((TypeError, KeyError)):
core.perform_sanity_check({'no_events': []})
def test_perform_sanity_check_edge_empty():
result = core.perform_sanity_check({'events': []})
assert result['missing_write_pairs'] == 0
assert result['broken_corr_ids'] == 0
assert result['empty_fields'] == 0