Add artifact_2/tests/test_core.py
This commit is contained in:
parent
1a11211508
commit
f090e9cbdb
1 changed files with 54 additions and 0 deletions
54
artifact_2/tests/test_core.py
Normal file
54
artifact_2/tests/test_core.py
Normal file
|
|
@ -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"])
|
||||||
Loading…
Reference in a new issue