Add 3.snapshot_comparator/tests/test_core.py
This commit is contained in:
parent
2833ef6b2d
commit
01fc054911
1 changed files with 55 additions and 0 deletions
55
3.snapshot_comparator/tests/test_core.py
Normal file
55
3.snapshot_comparator/tests/test_core.py
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
import pytest
|
||||
from snapshot_comparator import core
|
||||
|
||||
@pytest.fixture
|
||||
def sample_snapshots():
|
||||
snapshot1 = [
|
||||
{"artifact_key": "A", "status_before": "present", "status_after": "present"},
|
||||
{"artifact_key": "B", "status_before": "missing", "status_after": "missing"},
|
||||
{"artifact_key": "C", "status_before": "present", "status_after": "missing"},
|
||||
]
|
||||
snapshot2 = [
|
||||
{"artifact_key": "A", "status_before": "present", "status_after": "present"},
|
||||
{"artifact_key": "B", "status_before": "missing", "status_after": "present"},
|
||||
{"artifact_key": "D", "status_before": "missing", "status_after": "present"},
|
||||
]
|
||||
return snapshot1, snapshot2
|
||||
|
||||
|
||||
def test_compare_snapshots_basic_diff(sample_snapshots):
|
||||
snapshot1, snapshot2 = sample_snapshots
|
||||
result = core.compare_snapshots(snapshot1, snapshot2)
|
||||
assert isinstance(result, dict)
|
||||
# Artifact A should remain unchanged
|
||||
assert 'A' not in result
|
||||
# Artifact B changes from missing to present
|
||||
assert 'B' in result
|
||||
assert result['B']['before'] == 'missing'
|
||||
assert result['B']['after'] == 'present'
|
||||
# Artifact C missing in later snapshot
|
||||
assert 'C' in result
|
||||
assert result['C']['before'] == 'present'
|
||||
assert result['C']['after'] == 'missing'
|
||||
# Artifact D new in later snapshot
|
||||
assert 'D' in result
|
||||
assert result['D']['before'] == 'missing'
|
||||
assert result['D']['after'] == 'present'
|
||||
|
||||
|
||||
def test_compare_snapshots_empty_lists():
|
||||
result = core.compare_snapshots([], [])
|
||||
assert result == {}
|
||||
|
||||
|
||||
def test_compare_snapshots_identical_snapshots():
|
||||
snapshots = [
|
||||
{"artifact_key": "A", "status_before": "present", "status_after": "present"},
|
||||
{"artifact_key": "B", "status_before": "missing", "status_after": "missing"}
|
||||
]
|
||||
result = core.compare_snapshots(snapshots, snapshots)
|
||||
assert result == {}
|
||||
|
||||
|
||||
def test_compare_snapshots_input_validation():
|
||||
with pytest.raises((TypeError, KeyError)):
|
||||
core.compare_snapshots([{"artifact_key": "X"}], [123])
|
||||
Loading…
Reference in a new issue