From f090e9cbdbc2f14b64ec24c3a0dee31f36550b39 Mon Sep 17 00:00:00 2001 From: Mika Date: Sun, 29 Mar 2026 10:41:48 +0000 Subject: [PATCH] Add artifact_2/tests/test_core.py --- artifact_2/tests/test_core.py | 54 +++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 artifact_2/tests/test_core.py diff --git a/artifact_2/tests/test_core.py b/artifact_2/tests/test_core.py new file mode 100644 index 0000000..adb8005 --- /dev/null +++ b/artifact_2/tests/test_core.py @@ -0,0 +1,54 @@ +import pytest +from artifact_2 import core + +@pytest.fixture +def valid_log_entries(): + return [ + core.LogEntry(epoch_ms=1000, monotonic_ns=1000000, tz_offset_minutes=0, run_id="run1", step_id="step1"), + core.LogEntry(epoch_ms=2000, monotonic_ns=2000000, tz_offset_minutes=0, run_id="run1", step_id="step2"), + core.LogEntry(epoch_ms=3000, monotonic_ns=3000000, tz_offset_minutes=0, run_id="run1", step_id="step3"), + ] + +@pytest.fixture +def log_entries_with_tz_change(): + return [ + core.LogEntry(epoch_ms=1000, monotonic_ns=1000000, tz_offset_minutes=0, run_id="run2", step_id="step1"), + core.LogEntry(epoch_ms=2000, monotonic_ns=2000000, tz_offset_minutes=60, run_id="run2", step_id="step2"), + core.LogEntry(epoch_ms=3000, monotonic_ns=3000000, tz_offset_minutes=60, run_id="run2", step_id="step3"), + ] + +@pytest.fixture +def inconsistent_log_entries(): + # Negative time delta (epoch decreases) + return [ + core.LogEntry(epoch_ms=2000, monotonic_ns=2000000, tz_offset_minutes=0, run_id="run3", step_id="s1"), + core.LogEntry(epoch_ms=1500, monotonic_ns=3000000, tz_offset_minutes=0, run_id="run3", step_id="s2"), + ] + +@pytest.fixture +def inconsistent_tz_entries(): + # Multiple tz changes not allowed + return [ + core.LogEntry(epoch_ms=1000, monotonic_ns=1, tz_offset_minutes=0, run_id="run4", step_id="a"), + core.LogEntry(epoch_ms=2000, monotonic_ns=2, tz_offset_minutes=60, run_id="run4", step_id="b"), + core.LogEntry(epoch_ms=3000, monotonic_ns=3, tz_offset_minutes=120, run_id="run4", step_id="c"), + ] + +def test_valid_consistency(valid_log_entries): + assert core.check_timestamp_consistency(valid_log_entries) is True + +def test_tz_change_allowed_once(log_entries_with_tz_change): + assert core.check_timestamp_consistency(log_entries_with_tz_change) is True + +def test_inconsistent_negative_time_delta(inconsistent_log_entries): + assert core.check_timestamp_consistency(inconsistent_log_entries) is False + +def test_multiple_tz_change_not_allowed(inconsistent_tz_entries): + assert core.check_timestamp_consistency(inconsistent_tz_entries) is False + +def test_empty_input_returns_true(): + assert core.check_timestamp_consistency([]) is True + +def test_invalid_entry_type(): + with pytest.raises((AttributeError, TypeError)): + core.check_timestamp_consistency(["not_a_logentry"]) \ No newline at end of file