|
5 | 5 | import pytest |
6 | 6 |
|
7 | 7 | import cmd2 |
| 8 | +from cmd2 import string_utils as su |
8 | 9 | from cmd2 import utils |
9 | 10 |
|
10 | 11 | from .conftest import run_cmd |
@@ -127,7 +128,7 @@ def test_typer_execution(typer_app: TyperApp, cmd_input: str, expected: list[str |
127 | 128 |
|
128 | 129 | def test_typer_invalid_syntax(typer_app: TyperApp) -> None: |
129 | 130 | _out, err = run_cmd(typer_app, 'add "') |
130 | | - assert err[0] == 'Invalid syntax: No closing quotation' |
| 131 | + assert su.strip_style(err[0]) == 'Invalid syntax: No closing quotation' |
131 | 132 |
|
132 | 133 |
|
133 | 134 | def test_typer_with_no_args(typer_app: TyperApp) -> None: |
@@ -159,21 +160,23 @@ def test_typer_help_uses_app_stdout(typer_app: TyperApp, capsys: pytest.CaptureF |
159 | 160 |
|
160 | 161 | typer_app.onecmd_plus_hooks('help add') |
161 | 162 |
|
162 | | - out = typer_app.stdout.getvalue() |
| 163 | + out = su.strip_style(typer_app.stdout.getvalue()) |
163 | 164 | assert 'Usage: add' in out |
164 | 165 | assert '--b' in out |
165 | 166 | assert capsys.readouterr().out == '' |
166 | 167 |
|
167 | 168 |
|
168 | 169 | def test_typer_help_uses_docstring(typer_app: TyperApp) -> None: |
169 | 170 | out, _err = run_cmd(typer_app, 'help documented') |
170 | | - assert any('Usage: documented' in line for line in out) |
171 | | - assert any('Documented typer command.' in line for line in out) |
| 171 | + plain = [su.strip_style(line) for line in out] |
| 172 | + assert any('Usage: documented' in line for line in plain) |
| 173 | + assert any('Documented typer command.' in line for line in plain) |
172 | 174 |
|
173 | 175 |
|
174 | 176 | def test_typer_help_prog_name(typer_app: TyperApp) -> None: |
175 | 177 | out, _err = run_cmd(typer_app, 'help add') |
176 | | - usage_line = next(line for line in out if 'Usage: add' in line) |
| 178 | + plain = [su.strip_style(line) for line in out] |
| 179 | + usage_line = next(line for line in plain if 'Usage: add' in line) |
177 | 180 | assert usage_line.strip().startswith('Usage: add') |
178 | 181 |
|
179 | 182 |
|
@@ -215,8 +218,9 @@ def test_typer_commandset_binding() -> None: |
215 | 218 | def test_typer_commandset_help() -> None: |
216 | 219 | app = TyperApp(command_sets=[TyperCommandSet()]) |
217 | 220 | out, _err = run_cmd(app, 'help scale') |
218 | | - assert any('Usage: scale' in line for line in out) |
219 | | - assert any('--factor' in line for line in out) |
| 221 | + plain = [su.strip_style(line) for line in out] |
| 222 | + assert any('Usage: scale' in line for line in plain) |
| 223 | + assert any('--factor' in line for line in plain) |
220 | 224 |
|
221 | 225 |
|
222 | 226 | # --------------------------------------------------------------------------- |
@@ -289,8 +293,9 @@ def test_typer_subcommand_invalid(subcmd_app: TyperApp) -> None: |
289 | 293 | ) |
290 | 294 | def test_typer_subcommand_help(subcmd_app: TyperApp, cmd_input: str, expected_strings: list[str]) -> None: |
291 | 295 | out, _err = run_cmd(subcmd_app, cmd_input) |
| 296 | + plain = [su.strip_style(line) for line in out] |
292 | 297 | for s in expected_strings: |
293 | | - assert any(s in line for line in out) |
| 298 | + assert any(s in line for line in plain) |
294 | 299 |
|
295 | 300 |
|
296 | 301 | def test_typer_subcommand_parse_error_stays_in_repl( |
|
0 commit comments