Files
2026-11-02 16:46:20 +03:00

39 lines
1.2 KiB
Python

#!/usr/bin/env python3
import os
import sys
import unittest
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from history import History # noqa: E402
class HistoryTests(unittest.TestCase):
def test_ring_keeps_newest(self):
h = History(limit=2)
h.add("aa:bb:cc:dd:ee:ff", 1.0, 10, 32, -60)
h.add("AA:BB:CC:DD:EE:FF", 2.0, 20, 30, None)
h.add("AA:BB:CC:DD:EE:FF", 3.0, None, 255, -70)
rows = h.to_dict()["AA:BB:CC:DD:EE:FF"]
self.assertEqual(len(rows), 2)
self.assertEqual(rows[0]["ts"], 2.0)
self.assertEqual(rows[1]["raw_mm"], None)
self.assertEqual(rows[1]["battery"], 255)
def test_load_trims(self):
h = History(limit=1)
h.load_dict(
{
"aa:bb:cc:dd:ee:01": [
{"ts": 1, "raw_mm": 5, "battery": 32, "rssi": -40},
{"ts": 2, "raw_mm": 6, "battery": 31, "rssi": -41},
]
}
)
rows = h.to_dict()["AA:BB:CC:DD:EE:01"]
self.assertEqual(len(rows), 1)
self.assertEqual(rows[0]["ts"], 2)
if __name__ == "__main__":
unittest.main()