The snapshot comparison moves into compare_snapshots.py with offline tests, run by verify.sh. It agrees with today's two hand-checked installs. It refuses to install while Orbit is playing, and keeps the last three backups per room. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
58 lines
2.5 KiB
Python
58 lines
2.5 KiB
Python
#!/usr/bin/env python3
|
|
"""Offline tests for compare_snapshots.py (9 November 2026), with made-up snapshots. Run: python3 tools/test_compare_snapshots.py"""
|
|
import json, os, shutil, sys, tempfile, unittest
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
from compare_snapshots import compare
|
|
|
|
|
|
def write(root, rel, obj):
|
|
p = os.path.join(root, rel); os.makedirs(os.path.dirname(p), exist_ok=True)
|
|
with open(p, "w") as f:
|
|
f.write(obj if isinstance(obj, str) else json.dumps(obj))
|
|
|
|
|
|
def snapshot(root, bookings=("a", "b"), schedule=((100, "x"), (200, "y"), (300, "z")), history="h1"):
|
|
write(root, "shared_prefs/orbit_profiles.xml", "<map/>")
|
|
write(root, "files/history-1.json", history)
|
|
write(root, "files/taste/events.json", "[]")
|
|
write(root, "files/booked-1.json", {"bookings": [{"id": b} for b in bookings]})
|
|
write(root, "no_backup/schedule/schedule-101.json", {"entries": [{"a": a, "t": t} for a, t in schedule]})
|
|
|
|
|
|
class CompareSnapshotsTest(unittest.TestCase):
|
|
def setUp(self):
|
|
self.dir = tempfile.mkdtemp(); self.b = os.path.join(self.dir, "before"); self.a = os.path.join(self.dir, "after")
|
|
snapshot(self.b)
|
|
|
|
def tearDown(self):
|
|
shutil.rmtree(self.dir)
|
|
|
|
def test_identical_is_unchanged(self):
|
|
snapshot(self.a); self.assertEqual([], compare(self.b, self.a)[1])
|
|
|
|
def test_new_bookings_and_planning_ahead_are_fine(self):
|
|
snapshot(self.a, bookings=("a", "b", "c"), schedule=((200, "y"), (300, "z"), (400, "w")))
|
|
self.assertEqual([], compare(self.b, self.a)[1])
|
|
|
|
def test_lost_booking_is_a_problem(self):
|
|
snapshot(self.a, bookings=("a",)); self.assertIn("bookings lost: 1", compare(self.b, self.a)[1])
|
|
|
|
def test_changed_programme_is_a_problem(self):
|
|
snapshot(self.a, schedule=((100, "x"), (200, "CHANGED"), (300, "z")))
|
|
self.assertIn("planned programmes changed: 1", compare(self.b, self.a)[1])
|
|
|
|
def test_changed_history_is_a_problem(self):
|
|
snapshot(self.a, history="h2"); self.assertIn("history changed: 1 files", compare(self.b, self.a)[1])
|
|
|
|
def test_missing_file_is_a_problem(self):
|
|
snapshot(self.a); os.remove(os.path.join(self.a, "files/taste/events.json"))
|
|
self.assertIn("missing after install: 1", compare(self.b, self.a)[1])
|
|
|
|
def test_temporary_files_are_ignored(self):
|
|
write(self.b, "files/history-1.json.writing", "partial"); snapshot(self.a)
|
|
self.assertEqual([], compare(self.b, self.a)[1])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main(verbosity=1)
|