40 lines
1.4 KiB
Python
40 lines
1.4 KiB
Python
import tempfile
|
|
import unittest
|
|
from datetime import datetime, time
|
|
from pathlib import Path
|
|
from zoneinfo import ZoneInfo
|
|
|
|
import snapshot
|
|
|
|
|
|
class ScheduleTests(unittest.TestCase):
|
|
def test_day_window(self):
|
|
now = datetime(2026, 7, 30, 12, 0, tzinfo=ZoneInfo("Europe/Prague"))
|
|
self.assertTrue(snapshot.is_active(now, time(6), time(20)))
|
|
self.assertFalse(snapshot.is_active(now, time(13), time(20)))
|
|
|
|
def test_overnight_window(self):
|
|
late = datetime(2026, 7, 30, 23, 0, tzinfo=ZoneInfo("Europe/Prague"))
|
|
noon = datetime(2026, 7, 30, 12, 0, tzinfo=ZoneInfo("Europe/Prague"))
|
|
self.assertTrue(snapshot.is_active(late, time(20), time(6)))
|
|
self.assertFalse(snapshot.is_active(noon, time(20), time(6)))
|
|
|
|
def test_equal_times_mean_all_day(self):
|
|
now = datetime(2026, 7, 30, 12, 0, tzinfo=ZoneInfo("Europe/Prague"))
|
|
self.assertTrue(snapshot.is_active(now, time(0), time(0)))
|
|
|
|
|
|
class FileTests(unittest.TestCase):
|
|
def test_atomic_copy_replaces_destination(self):
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
root = Path(directory)
|
|
source = root / "dummy.jpg"
|
|
destination = root / "web" / "camera.jpg"
|
|
source.write_bytes(b"dummy")
|
|
snapshot.atomic_copy(source, destination)
|
|
self.assertEqual(destination.read_bytes(), b"dummy")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|