Harden main loop and store; by-id device default, BOARD_TZ
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
1 parent
8649d3abd0
commit
44a1b3cf8c
7 files changed
+100
-30
No files matched your search
+16
-2
@@ -1,10 +1,10 @@
|
||||
import os
|
||||
import time as time_module
|
||||
from datetime import datetime, timezone
|
||||
|
||||
import app
|
||||
import board
|
||||
from tests.helpers import FONT_DIR, load_timetables
|
||||
import store
|
||||
from tests.helpers import FONT_DIR, fixture_html, load_timetables
|
||||
|
||||
|
||||
def test_refresh_due_on_first_run():
|
||||
@@ -48,3 +48,17 @@ def test_board_image_renders_real_timetables(cz):
|
||||
fonts = board.load_fonts(FONT_DIR)
|
||||
img = app.board_image(load_timetables(), datetime(2026, 10, 6, 13, 28, 20), fonts, False, cz)
|
||||
assert img is not None and img.size == (480, 320)
|
||||
|
||||
|
||||
def test_load_cache_returns_parsed_timetables_and_fresh_flag(tmp_path):
|
||||
line4 = store.LineConfig("4", "Štípa,u potoka", "https://example.test/4")
|
||||
now = datetime(2026, 10, 6, 12, 0)
|
||||
store.refresh([line4], tmp_path, fetch=lambda url: fixture_html("line4_u_potoka.html"), now=now)
|
||||
timetables, stale = app.load_cache([line4], tmp_path, now, [], True)
|
||||
assert [t.line for t in timetables] == ["4"] and stale is False
|
||||
|
||||
|
||||
def test_load_cache_keeps_previous_values_on_error(tmp_path):
|
||||
previous = load_timetables()
|
||||
timetables, stale = app.load_cache(None, tmp_path, datetime(2026, 10, 6, 12, 0), previous, True)
|
||||
assert timetables is previous and stale is True
|
||||
@@ -1,3 +1,4 @@
|
||||
import json
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
import pytest
|
||||
@@ -79,3 +80,17 @@ def test_load_lines_reads_yaml(tmp_path):
|
||||
def test_repo_lines_yaml_lists_the_four_lines():
|
||||
labels = [c.label for c in store.load_lines(ROOT / "lines.yaml")]
|
||||
assert labels == ["4 Štípa,u potoka", "5 Štípa,u potoka", "35 Štípa,družstvo", "36 Štípa,družstvo"]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("content", ["[]", "null", "42", '"x"'])
|
||||
def test_fetched_json_that_is_not_an_object_is_ignored(tmp_path, content):
|
||||
(tmp_path / store.FETCHED_FILE).write_text(content, encoding="utf-8")
|
||||
assert store.is_stale([LINE4], tmp_path, NOW) is True
|
||||
report = store.refresh([LINE4], tmp_path, fetch=good_page, now=NOW)
|
||||
assert report.updated == [LINE4.label]
|
||||
assert store.is_stale([LINE4], tmp_path, NOW) is False
|
||||
|
||||
|
||||
def test_fetched_json_with_non_string_value_is_stale_not_an_error(tmp_path):
|
||||
(tmp_path / store.FETCHED_FILE).write_text(json.dumps({LINE4.label: 5}), encoding="utf-8")
|
||||
assert store.is_stale([LINE4], tmp_path, NOW) is True
|
||||
Reference in new issue
Block a user