From 9d1e3910eeaee359444a45d23c3096b7dc3f1f8d Mon Sep 17 00:00:00 2001 From: Rod Boev Date: Thu, 11 Jun 2026 20:42:51 -0400 Subject: [PATCH] Scope shutdown i18n assertions to the relevant DOM --- ...test_issue4002_shutdown_i18n_code_spans.py | 36 +++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/tests/test_issue4002_shutdown_i18n_code_spans.py b/tests/test_issue4002_shutdown_i18n_code_spans.py index 9f73ba43..b16bd500 100644 --- a/tests/test_issue4002_shutdown_i18n_code_spans.py +++ b/tests/test_issue4002_shutdown_i18n_code_spans.py @@ -1,19 +1,34 @@ from pathlib import Path -import re REPO = Path(__file__).resolve().parents[1] +def _extract_function(src: str, name: str) -> str: + anchor = f"function {name}(" + start = src.find(anchor) + assert start != -1, f"{name}() must exist" + body_start = src.find("{", start) + assert body_start != -1, f"{name}() must have a body" + depth = 1 + idx = body_start + 1 + while depth and idx < len(src): + if src[idx] == "{": + depth += 1 + elif src[idx] == "}": + depth -= 1 + idx += 1 + assert depth == 0, f"{name}() body must balance braces" + return src[start:idx] + + def test_shutdown_description_uses_split_i18n_spans_in_index_html(): html = (REPO / "static" / "index.html").read_text(encoding="utf-8") - block_match = re.search( - r'
(.*?)
', - html, - re.DOTALL, - ) - assert block_match, "Shutdown settings description block must exist." - block = block_match.group(1) + start = html.find('