Coverage for tests / test_tutorial / test_progressbar / test_tutorial001.py: 100%
28 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-02-09 12:36 +0000
« prev ^ index » next coverage.py v7.13.1, created at 2026-02-09 12:36 +0000
1import subprocess 1abcdefgh
2import sys 1abcdefgh
3from unittest.mock import patch 1abcdefgh
5import typer 1abcdefgh
6from typer.testing import CliRunner 1abcdefgh
8import docs_src.progressbar.tutorial001_py39 as mod 1abcdefgh
9from tests.utils import normalize_rich_output 1abcdefgh
11app = mod.app 1abcdefgh
13runner = CliRunner() 1abcdefgh
16def test_cli_one_step(): 1abcdefgh
17 with patch("time.sleep") as sleep_mock: 1abcdefgh
18 sleep_mock.side_effect = typer.Exit() # Exit on first `time.sleep()` call 1abcdefgh
19 result = runner.invoke(app) 1abcdefgh
21 # Replace all Rich formatting with `*` characters
22 normalized_output = normalize_rich_output(result.output) 1abcdefgh
24 assert result.exit_code == 0 1abcdefgh
25 assert "Processing... 0%" in normalized_output 1abcdefgh
28def test_cli(): 1abcdefgh
29 with patch("time.sleep") as mock_sleep: 1abcdefgh
30 result = runner.invoke(app) 1abcdefgh
32 # Replace all Rich formatting with `*` characters
33 normalized_output = normalize_rich_output(result.output) 1abcdefgh
35 assert result.exit_code == 0 1abcdefgh
36 assert mock_sleep.call_count == 100 1abcdefgh
37 assert "Processing..." in normalized_output 1abcdefgh
38 assert "100%" in normalized_output 1abcdefgh
39 assert "Processed 100 things." in normalized_output 1abcdefgh
42def test_script(): 1abcdefgh
43 result = subprocess.run( 1abcdefgh
44 [sys.executable, "-m", "coverage", "run", mod.__file__, "--help"],
45 capture_output=True,
46 encoding="utf-8",
47 )
48 assert "Usage" in result.stdout 1abcdefgh