Skip to content

Commit 43f9258

Browse files
committed
🐛 FIX: Make CLI error assertions resilient to terminal width Typer wraps error messages in Rich panels whose line breaks depend on terminal width. In CI environments with narrow terminals, long assertion substrings get split across lines by box-drawing characters, causing test_analyse_config_negative (and similar) to fail. Add _normalize_output() helper that strips Rich panel formatting and collapses whitespace before substring matching. Applied to test_analyse_config_negative, test_analyse_project_negative, and test_write_rst_negative.
Typer wraps error messages in Rich panels whose line breaks depend on terminal width. In CI environments with narrow terminals, long assertion substrings get split across lines by box-drawing characters, causing test_analyse_config_negative (and similar) to fail. Add _normalize_output() helper that strips Rich panel formatting and collapses whitespace before substring matching. Applied to test_analyse_config_negative, test_analyse_project_negative, and test_write_rst_negative.
1 parent 4f323e6 commit 43f9258

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

tests/test_cmd.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,19 @@
4646
runner = CliRunner()
4747

4848

49+
def _normalize_output(text: str) -> str:
50+
"""Normalize rich panel output by collapsing box-drawing chars and whitespace.
51+
52+
Typer wraps error messages in rich panels whose line breaks depend on terminal
53+
width, which can cause substring assertions to fail.
54+
"""
55+
import re
56+
57+
# Remove box-drawing characters (─│╭╮╯╰) and collapse resulting whitespace
58+
text = re.sub(r"[─│╭╮╯╰]", " ", text)
59+
return re.sub(r"\s+", " ", text).strip()
60+
61+
4962
@pytest.mark.parametrize(
5063
("config_path"),
5164
[
@@ -215,8 +228,9 @@ def test_analyse_config_negative(
215228
]
216229
result = runner.invoke(app, options)
217230
assert result.exit_code != 0
231+
normalized = _normalize_output(result.stdout)
218232
for line in output_lines:
219-
assert line in result.stdout
233+
assert line in normalized
220234

221235

222236
@pytest.mark.parametrize(
@@ -248,8 +262,9 @@ def test_analyse_project_negative(projects, output_lines, tmp_path: Path) -> Non
248262
options.extend(projects_config)
249263
result = runner.invoke(app, options)
250264
assert result.exit_code != 0
265+
normalized = _normalize_output(result.stdout)
251266
for line in output_lines:
252-
assert line in result.stdout
267+
assert line in normalized
253268

254269

255270
def test_write_rst_invalid_json(tmp_path: Path) -> None:
@@ -318,8 +333,9 @@ def test_write_rst_negative(json_objs: list[dict], output_lines, tmp_path) -> No
318333
result = runner.invoke(app, options)
319334

320335
assert result.exit_code != 0
336+
normalized = _normalize_output(result.stdout)
321337
for line in output_lines:
322-
assert line in result.stdout
338+
assert line in normalized
323339

324340

325341
def test_analyse_with_relative_git_root(tmp_path: Path) -> None:

0 commit comments

Comments
 (0)