22# Copyright (c) Alibaba, Inc. and its affiliates.
33
44import os
5+ import re
56import subprocess
67import sys
78from types import SimpleNamespace
1617from dashscope .common .error import AuthenticationError
1718
1819
20+ def strip_ansi_codes (text ):
21+ """Remove ANSI escape codes from text."""
22+ ansi_escape = re .compile (r"\x1b\[[0-9;]*m" )
23+ return ansi_escape .sub ("" , text )
24+
25+
1926# pylint: disable=too-many-public-methods
2027class TestCliMain :
2128 def test_main_prints_authentication_error_without_traceback (
@@ -46,7 +53,8 @@ def test_top_level_help_shows_global_api_key(self):
4653 result = CliRunner ().invoke (cli_app , ["--help" ])
4754
4855 assert result .exit_code == 0
49- assert "--api-key" in result .output
56+ clean_output = strip_ansi_codes (result .output )
57+ assert "--api-key" in clean_output
5058
5159 def test_python_module_help_suppresses_urllib3_warning (self ):
5260 result = subprocess .run (
@@ -84,7 +92,8 @@ def test_rl_register_functions_hyphen_alias_help(self):
8492 )
8593
8694 assert result .exit_code == 0
87- assert "rollout-classpaths" in result .output
95+ clean_output = strip_ansi_codes (result .output )
96+ assert "rollout-classpaths" in clean_output
8897
8998 def test_rl_test_functions_hyphen_alias_help (self ):
9099 result = CliRunner ().invoke (
@@ -93,7 +102,8 @@ def test_rl_test_functions_hyphen_alias_help(self):
93102 )
94103
95104 assert result .exit_code == 0
96- assert "--input" in result .output
105+ clean_output = strip_ansi_codes (result .output )
106+ assert "--input" in clean_output
97107
98108 def test_rl_upload_data_hyphen_alias_help (self ):
99109 result = CliRunner ().invoke (
@@ -102,7 +112,8 @@ def test_rl_upload_data_hyphen_alias_help(self):
102112 )
103113
104114 assert result .exit_code == 0
105- assert "training-files" in result .output
115+ clean_output = strip_ansi_codes (result .output )
116+ assert "training-files" in clean_output
106117
107118 def test_missing_global_api_key_value_does_not_consume_command (
108119 self ,
0 commit comments