From 874c71c83c3517efcd8a2fedb38f42fa17e25544 Mon Sep 17 00:00:00 2001 From: Mika Date: Thu, 22 Jan 2026 11:58:39 +0000 Subject: [PATCH] Add sanity_check_tool/tests/test_core.py --- sanity_check_tool/tests/test_core.py | 57 ++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 sanity_check_tool/tests/test_core.py diff --git a/sanity_check_tool/tests/test_core.py b/sanity_check_tool/tests/test_core.py new file mode 100644 index 0000000..528404e --- /dev/null +++ b/sanity_check_tool/tests/test_core.py @@ -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 \ No newline at end of file