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

20 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-03-26 21:46 +0000

1import subprocess 1abcdefg

2import sys 1abcdefg

3 

4from typer.testing import CliRunner 1abcdefg

5 

6import docs_src.printing.tutorial005_py310 as mod 1abcdefg

7from tests.utils import normalize_rich_output 1abcdefg

8 

9app = mod.app 1abcdefg

10 

11runner = CliRunner() 1abcdefg

12 

13 

14def test_good_true(): 1abcdefg

15 result = runner.invoke(app, color=True) 1abcdefg

16 assert result.exit_code == 0 1abcdefg

17 

18 # Replace all Rich formatting with `*` characters 

19 normalized_output = normalize_rich_output(result.output) 1abcdefg

20 

21 assert "everything is *good*" in normalized_output 1abcdefg

22 # We don't check exact colors here, just that text has formatting 

23 

24 

25def test_good_false(): 1abcdefg

26 result = runner.invoke(app, ["--no-good"], color=True) 1abcdefg

27 assert result.exit_code == 0 1abcdefg

28 

29 # Replace all Rich formatting with `*` characters 

30 normalized_output = normalize_rich_output(result.output) 1abcdefg

31 

32 assert "everything is *bad*" in normalized_output 1abcdefg

33 # We don't check exact colors here, just that text has formatting 

34 

35 

36def test_script(): 1abcdefg

37 result = subprocess.run( 1abcdefg

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

39 capture_output=True, 

40 encoding="utf-8", 

41 ) 

42 assert "Usage" in result.stdout 1abcdefg