Coverage for tests / test_tutorial / test_printing / test_tutorial003.py: 100%

15 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-11-18 11:12 +0000

1import subprocess 1abcdefghij

2import sys 1abcdefghij

3 

4from typer.testing import CliRunner 1abcdefghij

5 

6import docs_src.printing.tutorial003 as mod 1abcdefghij

7from tests.utils import normalize_rich_output 1abcdefghij

8 

9app = mod.app 1abcdefghij

10 

11runner = CliRunner() 1abcdefghij

12 

13 

14def test_cli(): 1abcdefghij

15 result = runner.invoke(app) 1abcdefghij

16 

17 # Replace all Rich formatting with `*` characters 

18 normalized_output = normalize_rich_output(result.output) 1abcdefghij

19 

20 assert result.exit_code == 0 1abcdefghij

21 assert ( 1abcdefghij

22 "*\n* Name * Item *\n*\n* Rick * Portal Gun *\n* Morty * Plumbus *\n*\n" 

23 ) in normalized_output 

24 

25 

26def test_script(): 1abcdefghij

27 result = subprocess.run( 1abcdefghij

28 [sys.executable, "-m", "coverage", "run", mod.__file__, "--help"], 

29 capture_output=True, 

30 encoding="utf-8", 

31 ) 

32 assert "Usage" in result.stdout 1abcdefghij