fix(tests): strip ANSI in --log-level help-visible assertion

CI's narrower terminal width forced Rich to split the flag literal across
ANSI colour escapes (`\x1b[1;36m-\x1b[0m\x1b[1;36m-log\x1b[0m\x1b[1;36m-level\x1b[0m`),
so the contiguous substring `--log-level` was not present in result.output
even though the flag is registered correctly. Strip ANSI codes before the
substring check — same pattern applied to similar Typer/Rich help-text
tests in other Python projects. No code change.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Alpamys 2026-04-28 13:25:54 +05:00
parent 2cc4b5aa20
commit 5ff8d87227
1 changed files with 11 additions and 1 deletions

View File

@ -3,6 +3,7 @@
from __future__ import annotations
import logging
import re
import pytest
from typer.testing import CliRunner
@ -16,6 +17,15 @@ from soup_cli.utils.log_level import (
setup_logging,
)
# Rich help renderer can split a flag like --log-level with ANSI colour
# escapes between `--`, `-log`, `-level` when the terminal is narrow (CI
# runners have a narrower default width than local shells). Strip ANSI so
# substring assertions are robust across all CI matrix jobs.
_ANSI_ESCAPE = re.compile(r"\x1b\[[0-9;]*[mK]")
def _strip_ansi(text: str) -> str:
return _ANSI_ESCAPE.sub("", text)
class TestLogLevelEnum:
def test_four_tiers_defined(self):
@ -86,7 +96,7 @@ class TestCliFlag:
def test_log_level_help_visible(self):
runner = CliRunner()
result = runner.invoke(app, ["--help"])
assert "--log-level" in result.output
assert "--log-level" in _strip_ansi(result.output), result.output
def test_log_level_invalid_rejected(self):
runner = CliRunner()