diff --git a/dry_run_mode/tests/test_core.py b/dry_run_mode/tests/test_core.py new file mode 100644 index 0000000..decb5b9 --- /dev/null +++ b/dry_run_mode/tests/test_core.py @@ -0,0 +1,57 @@ +import pytest +import types + +from dry_run_mode import core + + +@pytest.fixture +def sample_drift_report(): + # Simulated drift report with pinned and unpinned strata + return { + 'strata': [ + {'stratum': 'pinned_alpha_low', 'alpha': 0.1, 'offset': 0, 'metrics': {'drift': 0.05}}, + {'stratum': 'pinned_alpha_high', 'alpha': 0.3, 'offset': 0, 'metrics': {'drift': 0.25}}, + {'stratum': 'unpinned_positive', 'alpha': 0.1, 'offset': 1.0, 'metrics': {'drift': 0.15}}, + {'stratum': 'missing_metrics', 'alpha': 0.2, 'offset': 0, 'metrics': {}}, + ] + } + + +def test_dry_run_evaluation_basic(sample_drift_report): + result = core.dry_run_evaluation(sample_drift_report) + assert isinstance(result, dict) + assert 'results' in result + assert isinstance(result['results'], list) + + expected_strata = {s['stratum'] for s in sample_drift_report['strata']} + actual_strata = {r['stratum'] for r in result['results']} + assert expected_strata == actual_strata + + +def test_each_result_has_required_fields(sample_drift_report): + result = core.dry_run_evaluation(sample_drift_report) + for entry in result['results']: + assert {'stratum', 'dry_decision', 'reason'} <= set(entry.keys()) + assert isinstance(entry['stratum'], str) + assert isinstance(entry['dry_decision'], str) + assert isinstance(entry['reason'], str) + + +def test_reason_contains_keywords(sample_drift_report): + result = core.dry_run_evaluation(sample_drift_report) + for entry in result['results']: + # Reason should mention threshold or drift or missing data + reason = entry['reason'].lower() + assert any(k in reason for k in ['threshold', 'drift', 'missing', 'offset']) + + +def test_invalid_input_type_raises(): + with pytest.raises((AssertionError, TypeError, KeyError)): + core.dry_run_evaluation('not_a_dict') + + +def test_handles_empty_report(): + empty_report = {'strata': []} + result = core.dry_run_evaluation(empty_report) + assert isinstance(result, dict) + assert result['results'] == [] \ No newline at end of file