Skip to content

Commit b6ce59a

Browse files
yeldarbyclaude
andcommitted
fix(tests): strip ANSI codes from help output assertions
Typer's Rich-based help rendering emits ANSI escape codes in CI (GitHub Actions), which breaks string containment checks for hyphenated flags like --api-key. The escape codes split the text across color boundaries, so "api-key" as a contiguous substring is not found. Add _strip_ansi() helper to affected test files and use it when asserting on help output text. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 7673bbf commit b6ce59a

2 files changed

Lines changed: 23 additions & 7 deletions

File tree

tests/cli/test_auth.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Tests for the auth CLI handler."""
22

3+
import re
34
import unittest
45

56
from typer.testing import CliRunner
@@ -8,6 +9,12 @@
89

910
runner = CliRunner()
1011

12+
_ANSI_RE = re.compile(r"\x1b\[[0-9;]*m")
13+
14+
15+
def _strip_ansi(text: str) -> str:
16+
return _ANSI_RE.sub("", text)
17+
1118

1219
class TestAuthRegistration(unittest.TestCase):
1320
"""Verify auth handler registers expected subcommands."""
@@ -28,8 +35,9 @@ def test_auth_login_exists(self) -> None:
2835
def test_auth_login_help_shows_flags(self) -> None:
2936
result = runner.invoke(app, ["auth", "login", "--help"])
3037
self.assertEqual(result.exit_code, 0)
31-
self.assertIn("api-key", result.output.lower())
32-
self.assertIn("force", result.output.lower())
38+
output = _strip_ansi(result.output).lower()
39+
self.assertIn("api-key", output)
40+
self.assertIn("force", output)
3341

3442
def test_auth_set_workspace_exists(self) -> None:
3543
result = runner.invoke(app, ["auth", "set-workspace", "--help"])

tests/cli/test_discovery.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Tests use typer.testing.CliRunner instead of argparse internals.
44
"""
55

6+
import re
67
import unittest
78

89
from typer.testing import CliRunner
@@ -11,6 +12,12 @@
1112

1213
runner = CliRunner()
1314

15+
_ANSI_RE = re.compile(r"\x1b\[[0-9;]*m")
16+
17+
18+
def _strip_ansi(text: str) -> str:
19+
return _ANSI_RE.sub("", text)
20+
1421

1522
class TestCLIDiscovery(unittest.TestCase):
1623
"""Verify the CLI app loads and has expected structure."""
@@ -87,7 +94,7 @@ class TestAliases(unittest.TestCase):
8794
def test_login_alias(self) -> None:
8895
result = runner.invoke(app, ["login", "--help"])
8996
self.assertEqual(result.exit_code, 0)
90-
self.assertIn("login", result.output.lower())
97+
self.assertIn("login", _strip_ansi(result.output).lower())
9198

9299
def test_whoami_alias(self) -> None:
93100
result = runner.invoke(app, ["whoami", "--help"])
@@ -104,13 +111,14 @@ def test_import_alias(self) -> None:
104111
def test_download_alias(self) -> None:
105112
result = runner.invoke(app, ["download", "--help"])
106113
self.assertEqual(result.exit_code, 0)
107-
self.assertIn("dataseturl", result.output.lower())
114+
self.assertIn("dataseturl", _strip_ansi(result.output).lower())
108115

109116
def test_hidden_aliases_not_in_help(self) -> None:
110117
result = runner.invoke(app, ["--help"])
111-
self.assertNotIn("upload_model", result.output)
112-
self.assertNotIn("get_workspace_info", result.output)
113-
self.assertNotIn("run_video_inference_api", result.output)
118+
output = _strip_ansi(result.output)
119+
self.assertNotIn("upload_model", output)
120+
self.assertNotIn("get_workspace_info", output)
121+
self.assertNotIn("run_video_inference_api", output)
114122

115123
def test_hidden_alias_still_works(self) -> None:
116124
result = runner.invoke(app, ["upload_model", "--help"])

0 commit comments

Comments
 (0)