Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions render_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@
import pathlib
import sys

from playwright.sync_api import TimeoutError as PlaywrightTimeout
from playwright.sync_api import sync_playwright

HERE = pathlib.Path(__file__).parent
PAGE = (HERE / "web" / "index.html").resolve()
ROW_TIMEOUT_MS = 8000


def shoot(out_dir: pathlib.Path, sizes: list[tuple[int, int]]) -> int:
# Imported here, not at module level: main()'s argument validation — and
# any consumer that merely wants to check a command line — must work
# without the browser driver installed.
from playwright.sync_api import TimeoutError as PlaywrightTimeout
from playwright.sync_api import sync_playwright

out_dir.mkdir(parents=True, exist_ok=True)
problems: list[str] = []
with sync_playwright() as p:
Expand Down Expand Up @@ -101,6 +104,10 @@ def shoot(out_dir: pathlib.Path, sizes: list[tuple[int, int]]) -> int:
def main() -> int:
out = pathlib.Path(sys.argv[1] if len(sys.argv) > 1 else HERE / "shots")
raw = sys.argv[2:]
if len(raw) % 2:
print(f"error: sizes come in width×height pairs; odd argument count {raw!r}",
file=sys.stderr)
return 2
sizes = [(2554, 1400), (1440, 900)] if not raw else [
(int(raw[i]), int(raw[i + 1])) for i in range(0, len(raw) - 1, 2)]
return shoot(out, sizes)
Expand Down
68 changes: 68 additions & 0 deletions tests/test_render_gui_args.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
"""Tests for render_gui.py's command-line argument handling.

The renderer is a CI quality gate (`web-syntax-check.yml` runs it on every web
change), so a command line it silently misreads is a gate that can turn green
without having rendered a single viewport.
"""

import sys

import render_gui


def test_odd_dimension_count_is_refused(tmp_path, monkeypatch, capsys):
recorded: list[list] = []
monkeypatch.setattr(render_gui, "shoot",
lambda out, sizes: recorded.append(list(sizes)) or 0)
monkeypatch.setattr(sys, "argv", ["render_gui.py", str(tmp_path), "1440"])

rc = render_gui.main()

assert rc == 2, "an incomplete size list must be an error, not a silent exit 0"
assert recorded == [], "shoot() must not run with an incomplete size list"
assert "1440" in capsys.readouterr().err


def test_three_arguments_are_refused_too(tmp_path, monkeypatch, capsys):
# A trailing size must not be silently dropped; any incomplete pair is an
# error, whatever the count.
recorded: list[list] = []
monkeypatch.setattr(render_gui, "shoot",
lambda out, sizes: recorded.append(list(sizes)) or 0)
monkeypatch.setattr(
sys, "argv",
["render_gui.py", str(tmp_path), "1280", "720", "1920"],
)

rc = render_gui.main()

assert rc == 2
assert recorded == []
assert "1280" in capsys.readouterr().err


def test_paired_dimensions_reach_shoot_unscathed(tmp_path, monkeypatch):
recorded: list[list] = []
monkeypatch.setattr(render_gui, "shoot",
lambda out, sizes: recorded.append(list(sizes)) or 0)
monkeypatch.setattr(
sys, "argv",
["render_gui.py", str(tmp_path), "1280", "720", "1920", "1080"],
)

rc = render_gui.main()

assert rc == 0
assert recorded == [[(1280, 720), (1920, 1080)]]


def test_no_size_arguments_use_the_default_viewports(tmp_path, monkeypatch):
recorded: list[list] = []
monkeypatch.setattr(render_gui, "shoot",
lambda out, sizes: recorded.append(list(sizes)) or 0)
monkeypatch.setattr(sys, "argv", ["render_gui.py", str(tmp_path)])

rc = render_gui.main()

assert rc == 0
assert recorded == [[(2554, 1400), (1440, 900)]]
Loading