""" tests/test_ui_renderers.py — Unit tests for app.py UI renderer functions. Covers: render_quip, render_deadlines_html, render_footer, render_panic_meter, render_mascot, select_result_state (Plan 03). Run: BUREAUCAT_NO_MODEL=1 .venv/bin/python -m pytest tests/test_ui_renderers.py -x -q """ import os import sys # Set escape hatch BEFORE importing app so model weights are never downloaded. os.environ["BUREAUCAT_NO_MODEL"] = "1" # Ensure the project root is on the path when running from tests/ sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) import app # noqa: E402 # --------------------------------------------------------------------------- # render_quip # --------------------------------------------------------------------------- class TestRenderQuip: def test_empty_string_returns_empty(self): assert app.render_quip("") == "" def test_whitespace_only_returns_empty(self): assert app.render_quip(" ") == "" def test_none_like_empty(self): # render_quip is typed str -> str but test falsy behavior assert app.render_quip("") == "" def test_quip_contains_prefix_exactly_once(self): result = app.render_quip("witty remark") assert result.count("Bureaucat says:") == 1 def test_quip_contains_prefix_exactly_once_with_existing_prefix(self): # Even if quip itself mentions the prefix, we only add it once result = app.render_quip("Skatteverket wants your money") assert result.count("Bureaucat says:") == 1 def test_quip_contains_quip_text(self): result = app.render_quip("witty") assert "witty" in result def test_quip_no_double_prefix(self): # parse_output already stripped "Bureaucat says:" from quip; renderer adds once result = app.render_quip("the cat is watching") count = result.count("Bureaucat says:") assert count == 1, f"Expected exactly 1 prefix occurrence, got {count}: {result!r}" def test_quip_is_markdown_not_raw_html(self): # Should use Markdown formatting (**...**) not raw HTML tags for safety result = app.render_quip("test quip") assert "Bureaucat says:" in result assert "test quip" in result # --------------------------------------------------------------------------- # render_deadlines_html # --------------------------------------------------------------------------- class TestRenderDeadlinesHtml: def test_value_line_contains_mark_tag(self): result = app.render_deadlines_html("- 15 juni 2026 — last day") assert "alert(1) — test") assert "