Coverage for tests/test_rich_utils.py: 100%
27 statements
« prev ^ index » next coverage.py v7.6.1, created at 2025-04-14 00:18 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2025-04-14 00:18 +0000
1import typer 1iabcdefgh
2import typer.completion 1iabcdefgh
3from typer.testing import CliRunner 1iabcdefgh
5runner = CliRunner() 1iabcdefgh
8def test_rich_utils_click_rewrapp(): 1iabcdefgh
9 app = typer.Typer(rich_markup_mode="markdown") 1iabcdefgh
11 @app.command() 1iabcdefgh
12 def main(): 1abcdefgh
13 """
14 \b
15 Some text
17 Some unwrapped text
18 """
19 print("Hello World") 1iabcdefgh
21 @app.command() 1iabcdefgh
22 def secondary(): 1abcdefgh
23 """
24 \b
25 Secondary text
27 Some unwrapped text
28 """
29 print("Hello Secondary World") 1iabcdefgh
31 result = runner.invoke(app, ["--help"]) 1iabcdefgh
32 assert "Some text" in result.stdout 1iabcdefgh
33 assert "Secondary text" in result.stdout 1iabcdefgh
34 assert "\b" not in result.stdout 1iabcdefgh
35 result = runner.invoke(app, ["main"]) 1iabcdefgh
36 assert "Hello World" in result.stdout 1iabcdefgh
37 result = runner.invoke(app, ["secondary"]) 1iabcdefgh
38 assert "Hello Secondary World" in result.stdout 1iabcdefgh
41def test_rich_help_no_commands(): 1iabcdefgh
42 """Ensure that the help still works for a Typer instance with no commands, but with a callback."""
43 app = typer.Typer(help="My cool Typer app") 1iabcdefgh
45 @app.callback(invoke_without_command=True, no_args_is_help=True) 1iabcdefgh
46 def main() -> None: 1iabcdefgh
47 return None # pragma: no cover
49 result = runner.invoke(app, ["--help"]) 1iabcdefgh
51 assert result.exit_code == 0 1iabcdefgh
52 assert "Show this message" in result.stdout 1iabcdefgh