From 24226695748cc9593348879c175a35662abe13a3 Mon Sep 17 00:00:00 2001 From: Ralf Steinert <122486565+steitec@users.noreply.github.com> Date: Mon, 9 Nov 2026 16:40:08 +0100 Subject: [PATCH] Keep result table content inside its columns Limit sources wrap instead of overflowing, the tolerance band scales to its column, and the band has literal colours because WeasyPrint does not resolve CSS variables in SVG attributes. --- CHANGELOG.md | 7 +++++++ src/test_protocol/html.py | 14 +++++++++----- tests/test_html.py | 26 ++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 49bf9ad..851bce6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## Unreleased + +- Result tables: the limit source wraps instead of running into the tolerance + band, and the tolerance band scales to its column instead of touching the + status badge +- Tolerance bands are no longer black in PDFs made with WeasyPrint + ## 0.1.1 — 2026-11-08 - Docker image `ghcr.io/steitec/test-protocol` with WeasyPrint and its system libraries, diff --git a/src/test_protocol/html.py b/src/test_protocol/html.py index 7c30824..b5baa16 100644 --- a/src/test_protocol/html.py +++ b/src/test_protocol/html.py @@ -75,6 +75,7 @@ def _limits(item: Item, lang: str) -> str: text = f"≤ {fmt_number(item.high, lang)}" else: return "—" + text = f'{text}' if item.limit_source: text += f' ({_e(item.limit_source)})' return text @@ -93,10 +94,10 @@ def x(v: float) -> float: return 4 + 112 * (min(max(v, lo), hi) - lo) / (hi - lo) color = _STATUS_COLORS["PASS" if low <= value <= high else "FAIL"] - return (f'' - f'' + return (f'' + f'' f'' + f'class="gauge-band" fill="#aceebb"/>' f'') @@ -141,7 +142,7 @@ def _summary(p: Protocol, lang: str) -> str: else: rows.append(f"
{_e(group.name)}{_e(item.name)}" f'{_value(item, lang)}' - f'{_limits(item, lang)}' + f'{_limits(item, lang)}' f"{_e(item.message)}{_badge(item.status or 'FAIL')}
") table = (f'

{t(lang, "failures")}

' f'' @@ -162,7 +163,7 @@ def _group(group: Group, lang: str) -> str: status = _badge(item.status) if item.status in STATUSES else "" rows.append(f"" f'' - f'' + f'' f"") table = "" if rows: @@ -242,6 +243,9 @@ def _signatures(p: Protocol, opts: RenderOptions) -> str: .group .grid { table-layout:fixed; } .group .grid th:nth-child(1) { width:32%; } .group .grid th:nth-child(2) { width:16%; } .group .grid th:nth-child(3) { width:24%; } .group .grid th:nth-child(4) { width:16%; } .num { font-variant-numeric:tabular-nums; white-space:nowrap; } +.limit { overflow-wrap:anywhere; } +.gauge { display:block; width:100%; max-width:120px; height:auto; } +.gauge-track { fill:var(--track); } .gauge-band { fill:var(--band); } .hash { font-family:ui-monospace, monospace; font-size:11px; word-break:break-all; } .note { color:var(--muted); font-size:12px; } .counts .badge { margin-left:10px; } .counts .badge:first-child { margin-left:0; } diff --git a/tests/test_html.py b/tests/test_html.py index ef89a16..d881bf0 100644 --- a/tests/test_html.py +++ b/tests/test_html.py @@ -137,3 +137,29 @@ def test_print_css(): assert "size: A4" in out assert "counter(pages)" in out assert "@media screen and (prefers-color-scheme: dark)" in out + + +def _gauge_item() -> Item: + return Item("3V3", "PASS", value=3.3, low=3.234, high=3.366) + + +def test_limit_source_can_wrap_in_its_fixed_width_column(): + item = _gauge_item() + item.limit_source = "limits.toml" + p = Protocol(header={"serial": "S"}, groups=[Group("g", [item])]) + out = render(p) + assert '
{t(lang, "group")}{t(lang, "item")}
{_e(item.name)}{message}{_value(item, lang)}{_limits(item, lang)}{_limits(item, lang)}{_gauge(item)}{status}
3.234 … 3.366 ' in out + assert ".limit { overflow-wrap:anywhere; }" in out + + +def test_gauge_scales_to_its_column(): + p = Protocol(header={"serial": "S"}, groups=[Group("g", [_gauge_item()])]) + out = render(p) + assert 'viewBox="0 0 120 14"' in out + assert '", 1)[0] + assert 'fill="var(' not in svg