Coverage for tests / test_tutorial / test_progressbar / test_tutorial006.py: 100%

18 statements  

« 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

4 

5from typer.testing import CliRunner 1abcdefghij

6 

7import docs_src.progressbar.tutorial006 as mod 1abcdefghij

8from tests.utils import normalize_rich_output 1abcdefghij

9 

10app = mod.app 1abcdefghij

11 

12runner = CliRunner() 1abcdefghij

13 

14 

15def test_cli(): # Checking only final state of progress bar 1abcdefghij

16 with patch("time.sleep") as mock_sleep: 1abcdefghij

17 result = runner.invoke(app) 1abcdefghij

18 

19 # Replace all Rich formatting with `*` characters 

20 normalized_output = normalize_rich_output(result.output) 1abcdefghij

21 

22 assert result.exit_code == 0 1abcdefghij

23 assert mock_sleep.call_count == 4 1abcdefghij

24 assert "Processed 1000 things in batches." in normalized_output 1abcdefghij

25 

26 

27def test_script(): 1abcdefghij

28 result = subprocess.run( 1abcdefghij

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

30 capture_output=True, 

31 encoding="utf-8", 

32 ) 

33 assert "Usage" in result.stdout 1abcdefghij