From 62f464f167907ee288e5d0953bc5a3fc7bbb3b5f Mon Sep 17 00:00:00 2001 From: anor Date: Thu, 10 Sep 2026 23:32:44 +1000 Subject: [PATCH] =?UTF-8?q?test(=D0=B0=D0=B4=D0=BC=D0=B8=D0=BD=D0=BA=D0=B0?= =?UTF-8?q?):=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B8=20=D0=BE?= =?UTF-8?q?=D1=84=D0=BE=D1=80=D0=BC=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B4?= =?UTF-8?q?=D0=B5=D1=80=D0=B6=D0=B0=D1=82=20=D0=B8=D0=BC=D0=B5=D0=BD=D0=B0?= =?UTF-8?q?=20=D1=86=D0=B2=D0=B5=D1=82=D0=BE=D0=B2,=20hsl=20=D0=B8=20?= =?UTF-8?q?=D0=BF=D0=BE=D0=B4=D0=BC=D0=B5=D0=BD=D1=83=20=D1=84=D0=BE=D0=BD?= =?UTF-8?q?=D0=BE=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Рецензия зайки: докстринги обещали больше, чем проверял код. Теперь жёстким цветом считается и имя (white, red), и hsl(); вызовы fillCells проверяются вместе с тем, что она действительно ставит класс выравнивания; беду ищем во всём встроенном виде, а не только в свойстве цвета текста; тело правил узкого экрана берётся до своей закрывающей скобки. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01RuEU1u9Rz24zmoy9TuvWc2 --- tests/test_admin_design_elements.py | 35 +++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/tests/test_admin_design_elements.py b/tests/test_admin_design_elements.py index a8692b9..735a475 100644 --- a/tests/test_admin_design_elements.py +++ b/tests/test_admin_design_elements.py @@ -52,6 +52,22 @@ def _blocks(style: str) -> list: return [(m.group(1).strip(), m.group(2)) for m in re.finditer(r"([^{}]+)\{([^{}]*)\}", clean)] +# Имена цветов, которые пишут по привычке. «transparent» и «currentColor» цветом набора +# не управляют — их держим разрешёнными. +COLOR_WORDS = ("white", "black", "red", "green", "blue", "yellow", "orange", "purple", + "pink", "gray", "grey", "silver", "navy", "teal", "brown", "gold") + + +def _hardcoded_color(text: str) -> bool: + """Цвет, записанный значением, а не переменной: число, имя или hsl().""" + if re.search(r"#[0-9a-fA-F]{3,8}\b", text) or re.search(r"\b(?:rgba?|hsla?)\(", text): + return True + for word in COLOR_WORDS: + if re.search(r"(?::|\s)" + word + r"(?![-\w])", text, re.I): + return True + return False + + def _tokens(body: str) -> dict: return dict(re.findall(r"(--[a-z0-9-]+)\s*:\s*([^;]+)", body)) @@ -66,8 +82,7 @@ def test_token_blocks_are_only_root_selectors(style): for head, body in _blocks(style): if TOKEN_HEAD.match(head.strip()): continue - assert not re.search(r"#[0-9a-fA-F]{3,8}\b", body), head - assert not re.search(r"\brgba?\(", body), head + assert not _hardcoded_color(body), (head, body.strip()[:80]) def test_inline_styles_carry_no_colors_or_shapes(outside): @@ -139,7 +154,7 @@ def test_danger_is_its_own_token(style, outside): not_red.append((name, values["--danger"])) assert not not_red, not_red # В разметке и скриптах беду красят именно бедой. - assert "var(--accent)" not in "".join(re.findall(r'style="([^"]*color[^"]*)"', outside)) + assert "var(--accent)" not in "".join(re.findall(r'style="([^"]*)"', outside)) def test_every_design_defines_the_full_color_set(style): @@ -260,7 +275,9 @@ def test_numbers_are_right_aligned(style, outside): # Мало объявить правило — числовые колонки должны его получать: и в шапке, и в # ячейках, которые скрипт рисует на ходу. assert 'th class="num"' in outside - assert "fillCells(" in outside + body = outside[outside.index("function fillCells"):] + body = body[:body.index("\n}")] + assert "'num'" in body, "ячейки не получают класс выравнивания" assert outside.count("fillCells(") >= 6 @@ -279,9 +296,13 @@ def test_narrow_screen_rules_exist(style): """На узком экране полоса разделов в 220 точек съедает половину, а таблица на одиннадцать колонок выталкивает страницу за край. Порча: убрать правила узкого экрана → упадёт.""" - narrow = re.search(r"@media\s*\([^)]*max-width[^)]*\)\s*\{(.*)", style, re.S) - assert narrow, "правил для узкого экрана нет" - body = narrow.group(1) + at = re.search(r"@media\s*\([^)]*max-width[^)]*\)\s*\{", style) + assert at, "правил для узкого экрана нет" + depth, i = 1, at.end() + while depth and i < len(style): + depth += {"{": 1, "}": -1}.get(style[i], 0) + i += 1 + body = style[at.end():i] assert ".sidebar" in body assert "table" in body