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

20 statements  

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

1import subprocess 1abcdefgh

2import sys 1abcdefgh

3 

4from typer.testing import CliRunner 1abcdefgh

5 

6import docs_src.printing.tutorial005_py39 as mod 1abcdefgh

7from tests.utils import normalize_rich_output 1abcdefgh

8 

9app = mod.app 1abcdefgh

10 

11runner = CliRunner() 1abcdefgh

12 

13 

14def test_good_true(): 1abcdefgh

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

16 assert result.exit_code == 0 1abcdefgh

17 

18 # Replace all Rich formatting with `*` characters 

19 normalized_output = normalize_rich_output(result.output) 1abcdefgh

20 

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

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

23 

24 

25def test_good_false(): 1abcdefgh

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

27 assert result.exit_code == 0 1abcdefgh

28 

29 # Replace all Rich formatting with `*` characters 

30 normalized_output = normalize_rich_output(result.output) 1abcdefgh

31 

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

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

34 

35 

36def test_script(): 1abcdefgh

37 result = subprocess.run( 1abcdefgh

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

39 capture_output=True, 

40 encoding="utf-8", 

41 ) 

42 assert "Usage" in result.stdout 1abcdefgh