Add sanity_check_tool/tests/test_core.py
This commit is contained in:
parent
0010db35c4
commit
874c71c83c
1 changed files with 57 additions and 0 deletions
57
sanity_check_tool/tests/test_core.py
Normal file
57
sanity_check_tool/tests/test_core.py
Normal 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
|
||||
Loading…
Reference in a new issue