feat: departure board image and vendored Roboto fonts
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
1 parent
e199600140
commit
baaaeff917
10 files changed
+425
-6
No files matched your search
@@ -0,0 +1,80 @@
|
||||
from datetime import datetime, time
|
||||
|
||||
import pytest
|
||||
from PIL import Image
|
||||
|
||||
import board
|
||||
from schedule import Upcoming
|
||||
from tests.helpers import FONT_DIR
|
||||
from timetable import Departure
|
||||
|
||||
NOW = datetime(2026, 10, 6, 13, 28, 20)
|
||||
|
||||
|
||||
def up(line, stop, h, m, minutes, next_day=False):
|
||||
return Upcoming(Departure(line, stop, time(h, m)), datetime(2026, 10, 6, h, m), minutes, next_day)
|
||||
|
||||
|
||||
FIVE = [
|
||||
up("4", "Štípa,u potoka", 13, 33, 5),
|
||||
up("4", "Štípa,u potoka", 13, 53, 25),
|
||||
up("4", "Štípa,u potoka", 14, 8, 40),
|
||||
up("5", "Štípa,u potoka", 14, 25, 57),
|
||||
up("36", "Štípa,družstvo", 14, 27, 59),
|
||||
]
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def fonts():
|
||||
return board.load_fonts(FONT_DIR)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"minutes, next_day, countdown, hero",
|
||||
[
|
||||
(0, False, "teď", "teď"),
|
||||
(7, False, "za 7 min", "7 min"),
|
||||
(59, False, "za 59 min", "59 min"),
|
||||
(60, False, "za 1 h 00 min", "1 h 00"),
|
||||
(76, False, "za 1 h 16 min", "1 h 16"),
|
||||
(264, True, "zítra", "zítra"),
|
||||
],
|
||||
)
|
||||
def test_countdown_text(minutes, next_day, countdown, hero):
|
||||
u = up("4", "Štípa,u potoka", 13, 33, minutes, next_day)
|
||||
assert board.countdown_text(u) == countdown
|
||||
assert board.hero_text(u) == hero
|
||||
|
||||
|
||||
def test_board_has_screen_size(fonts):
|
||||
assert board.render_board(FIVE, NOW, fonts).size == (480, 320)
|
||||
|
||||
|
||||
def test_board_marks_the_next_bus_with_accent_badge(fonts):
|
||||
img = board.render_board(FIVE, NOW, fonts)
|
||||
assert img.getpixel((30, 30)) == board.ACCENT
|
||||
|
||||
|
||||
def test_empty_board_shows_message_not_badge(fonts):
|
||||
img = board.render_board([], NOW, fonts)
|
||||
assert img.size == (480, 320)
|
||||
assert img.getpixel((30, 30)) == board.BG
|
||||
blank = Image.new("RGB", (board.W, board.H), board.BG)
|
||||
assert img.tobytes() != blank.tobytes() # the "Žádné odjezdy" text was drawn
|
||||
|
||||
|
||||
def test_single_departure_and_overflow_do_not_crash(fonts):
|
||||
assert board.render_board(FIVE[:1], NOW, fonts).size == (480, 320)
|
||||
many = FIVE * 3 # more than the board can show
|
||||
assert board.render_board(many, NOW, fonts).size == (480, 320)
|
||||
|
||||
|
||||
def test_stale_marker_changes_the_image(fonts):
|
||||
fresh = board.render_board(FIVE, NOW, fonts, stale=False).tobytes()
|
||||
stale = board.render_board(FIVE, NOW, fonts, stale=True).tobytes()
|
||||
assert fresh != stale
|
||||
|
||||
|
||||
def test_long_stop_name_does_not_crash(fonts):
|
||||
long = [up("4", "Zlín,Lešná,ZOO – velmi dlouhý název zastávky", 13, 33, 5)] * 2
|
||||
assert board.render_board(long, NOW, fonts).size == (480, 320)
|
||||
Reference in new issue
Block a user