Skip to content

Commit 230987e

Browse files
mihowclaude
andcommitted
test: compare command help against whitespace-normalized output
The fetch-and-pack help description is long enough that Click wraps it across lines in `--help` output, so the raw single-line help string was no longer a substring of the output and `test_command_help` failed. Collapse whitespace on both sides before the substring check so the assertion is insensitive to terminal-width line wrapping. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent d03746d commit 230987e

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

tests/dataset_tools/test_cli.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
1+
import re
2+
13
import pytest
24
from click.testing import CliRunner
35

46
from src.dataset_tools.cli import COMMAND_KEYS, COMMANDS, COMMANDS_HELP, cli
57

8+
9+
def _normalize_ws(text: str) -> str:
10+
"""Collapse runs of whitespace to a single space.
11+
12+
Click wraps long help text across lines based on terminal width, so the
13+
raw ``--help`` output cannot be compared directly against the single-line
14+
help strings. Normalising whitespace on both sides makes the comparison
15+
insensitive to line wrapping.
16+
"""
17+
return re.sub(r"\s+", " ", text).strip()
18+
19+
620
command_test_parameters = [COMMANDS[cmd_key] for cmd_key in COMMAND_KEYS]
721
command_and_help_test_parameters = [
822
(COMMANDS[cmd_key], COMMANDS_HELP[cmd_key]) for cmd_key in COMMAND_KEYS
@@ -31,7 +45,7 @@ def test_command_help(command, command_help):
3145
result = runner.invoke(cli, [command, "--help"])
3246
assert result.exit_code == 0
3347
assert command in result.output
34-
assert command_help in result.output
48+
assert _normalize_ws(command_help) in _normalize_ws(result.output)
3549

3650

3751
def test_number_of_command_constants():

0 commit comments

Comments
 (0)