Coverage for tests/test_rich_utils.py: 100%
27 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-09-09 18:26 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-09-09 18:26 +0000
1import typer 1habcdefg
2import typer.completion 1habcdefg
3from typer.testing import CliRunner 1habcdefg
5runner = CliRunner() 1habcdefg
8def test_rich_utils_click_rewrapp(): 1habcdefg
9 app = typer.Typer(rich_markup_mode="markdown") 1habcdefg
11 @app.command() 1habcdefg
12 def main(): 1abcdefg
13 """
14 \b
15 Some text
17 Some unwrapped text
18 """
19 print("Hello World") 1habcdefg
21 @app.command() 1habcdefg
22 def secondary(): 1abcdefg
23 """
24 \b
25 Secondary text
27 Some unwrapped text
28 """
29 print("Hello Secondary World") 1habcdefg
31 result = runner.invoke(app, ["--help"]) 1habcdefg
32 assert "Some text" in result.stdout 1habcdefg
33 assert "Secondary text" in result.stdout 1habcdefg
34 assert "\b" not in result.stdout 1habcdefg
35 result = runner.invoke(app, ["main"]) 1habcdefg
36 assert "Hello World" in result.stdout 1habcdefg
37 result = runner.invoke(app, ["secondary"]) 1habcdefg
38 assert "Hello Secondary World" in result.stdout 1habcdefg
41def test_rich_help_no_commands(): 1habcdefg
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") 1habcdefg
45 @app.callback(invoke_without_command=True, no_args_is_help=True) 1habcdefg
46 def main() -> None: 1habcdefg
47 return None # pragma: no cover
49 result = runner.invoke(app, ["--help"]) 1habcdefg
51 assert result.exit_code == 0 1habcdefg
52 assert "Show this message" in result.stdout 1habcdefg