fix: survive the screen library's sys.exit, copy all modules into the image, fit -10 degree readouts
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
1 parent
ae8c17d8d5
commit
09f78d1a63
8 files changed
+78
-8
No files matched your search
@@ -0,0 +1,28 @@
|
||||
import fnmatch
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
|
||||
|
||||
def copied_sources():
|
||||
sources = []
|
||||
for line in (ROOT / "Dockerfile").read_text().splitlines():
|
||||
match = re.match(r"^COPY\s+(.+)\s+\S+$", line.strip())
|
||||
if match:
|
||||
sources += match.group(1).split()
|
||||
return sources
|
||||
|
||||
|
||||
def test_dockerfile_copies_every_top_level_module():
|
||||
"""A new view module must reach the image without anyone editing the Dockerfile."""
|
||||
sources = copied_sources()
|
||||
missing = [p.name for p in ROOT.glob("*.py") if not any(fnmatch.fnmatch(p.name, s) for s in sources)]
|
||||
assert missing == []
|
||||
|
||||
|
||||
def test_dockerignore_keeps_dev_files_out_of_the_image_but_not_assets():
|
||||
ignored = (ROOT / ".dockerignore").read_text().split()
|
||||
for name in (".venv", ".git", "tests", "docs", ".superpowers"):
|
||||
assert name in ignored
|
||||
assert "assets" not in ignored
|
||||
@@ -138,3 +138,28 @@ def test_render_error_size_and_has_ink():
|
||||
|
||||
def test_render_error_long_line_does_not_raise():
|
||||
assert runner.render_error(["X" * 500]).size == (480, 320)
|
||||
|
||||
|
||||
def test_open_screen_retries_when_the_library_calls_sys_exit():
|
||||
"""The pinned screen library calls sys.exit(0) when the port is missing; that must not end the process."""
|
||||
attempts, sleeps = [], []
|
||||
|
||||
def factory():
|
||||
attempts.append(1)
|
||||
if len(attempts) < 3:
|
||||
raise SystemExit(0)
|
||||
return "lcd"
|
||||
|
||||
assert runner.open_screen(factory, running=lambda: True, sleep=sleeps.append) == "lcd"
|
||||
assert sleeps == [30.0, 30.0]
|
||||
|
||||
|
||||
def test_run_counts_library_sys_exit_as_a_failed_draw():
|
||||
class ExitingLcd:
|
||||
def DisplayPILImage(self, *a, **k):
|
||||
raise SystemExit(0)
|
||||
|
||||
view = StubView(lambda now: "same")
|
||||
with pytest.raises(SystemExit): # after max_failures; Docker then restarts and open_screen retries
|
||||
runner.run(view, ExitingLcd(), now_fn=clock(T0, 0), running=ticks(50), sleep=lambda s: None, max_failures=3)
|
||||
assert view.renders == 3 # it tried three times first
|
||||
@@ -137,3 +137,10 @@ def test_fewer_than_twelve_hours_still_renders():
|
||||
|
||||
def test_unknown_weather_code_renders():
|
||||
assert view(value=weather(code=999)).render(NOW).size == (480, 320)
|
||||
|
||||
|
||||
def test_two_digit_negative_temps_stay_clear_of_the_divider():
|
||||
for temp in (-10.4, -19.6):
|
||||
img = view(value=weather(temp=temp)).render(NOW)
|
||||
box = ink_bbox(img, (84, 180, 204, 236))
|
||||
assert box is not None and box[2] < 200, temp
|
||||
Reference in new issue
Block a user