Coverage for tests / test_tutorial / test_printing / test_tutorial002.py: 100%
23 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-11-18 11:12 +0000
« prev ^ index » next coverage.py v7.13.1, created at 2026-11-18 11:12 +0000
1import subprocess 1abcdefghij
2import sys 1abcdefghij
3from unittest.mock import patch 1abcdefghij
5from rich.console import Console # noqa: TID251 1abcdefghij
6from typer.testing import CliRunner 1abcdefghij
8import docs_src.printing.tutorial002 as mod 1abcdefghij
9from tests.utils import normalize_rich_output 1abcdefghij
11app = mod.app 1abcdefghij
13runner = CliRunner() 1abcdefghij
16def test_cli(): 1abcdefghij
17 console = Console(force_terminal=True, width=100) 1abcdefghij
18 with patch("rich.get_console", return_value=console): 1abcdefghij
19 result = runner.invoke(app) 1abcdefghij
21 # Replace all Rich formatting with `*` characters
22 normalized_output = normalize_rich_output(result.output) 1abcdefghij
24 assert result.exit_code == 0 1abcdefghij
25 assert "*Alert!* *Portal gun* shooting! *" in normalized_output 1abcdefghij
28def test_cli_without_formatting(): 1abcdefghij
29 result = runner.invoke(app) 1abcdefghij
31 assert result.exit_code == 0 1abcdefghij
32 assert "Alert! Portal gun shooting! 💥" in result.output 1abcdefghij
35def test_script(): 1abcdefghij
36 result = subprocess.run( 1abcdefghij
37 [sys.executable, "-m", "coverage", "run", mod.__file__, "--help"],
38 capture_output=True,
39 encoding="utf-8",
40 )
41 assert "Usage" in result.stdout 1abcdefghij