Files
radar_system/python_app/tests/test_collection_identity.py
2026-10-06 12:32:26 +03:00

32 lines
1.5 KiB
Python

"""Exact acquisition identity survives stage timestamps and reused IDs."""
import unittest
from python_app.models.collection_identity import collection_key, history_collection_removed, index_collections
from python_app.models.dataset_model import ResultCollection, SweepCollection
class CollectionIdentityTest(unittest.TestCase):
def test_stage_lookup_uses_only_id_and_capture_start(self) -> None:
old = SweepCollection(1, 500, capture_start_ns=10, capture_end_ns=20)
fresh = SweepCollection(1, 100, capture_start_ns=30, capture_end_ns=40)
index = index_collections([old, fresh])
result = ResultCollection(1, 900, capture_start_ns=30, capture_end_ns=40)
self.assertIs(index.get(collection_key(result)), fresh)
self.assertNotIn((1, 31), index)
self.assertNotIn((2, 30), index)
def test_clear_and_remove_ignore_stage_timestamp_and_capture_end(self) -> None:
deleted = [{"collection_id": 1, "capture_start_ns": 30}]
for timestamp, end in ((1, 30), (900, 800)):
result = ResultCollection(1, timestamp, capture_start_ns=30, capture_end_ns=end)
self.assertTrue(history_collection_removed(result, 30, []))
self.assertTrue(history_collection_removed(result, 0, deleted))
self.assertFalse(history_collection_removed(result, 29, []))
fresh = ResultCollection(1, 1, capture_start_ns=31, capture_end_ns=32)
self.assertFalse(history_collection_removed(fresh, 30, deleted))
if __name__ == "__main__":
unittest.main()