Coverage for tests / test_tutorial / test_launch / test_tutorial002.py: 100%
27 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 pathlib import Path 1abcdefgh
4from unittest.mock import patch 1abcdefgh
6import pytest 1abcdefgh
7import typer 1abcdefgh
8from typer.testing import CliRunner 1abcdefgh
10from docs_src.launch import tutorial002_py39 as mod 1abcdefgh
12runner = CliRunner() 1abcdefgh
15@pytest.fixture(name="app_dir") 1abcdefgh
16def app_dir(): 1abcdefgh
17 app_dir = Path(typer.get_app_dir("my-super-cli-app")) 1abcdefgh
18 if app_dir.exists(): # pragma: no cover 1abcdefgh
19 for item in app_dir.iterdir():
20 if item.is_file():
21 item.unlink()
23 yield app_dir 1abcdefgh
25 if app_dir.exists(): 1abcdefgh
26 for item in app_dir.iterdir(): 1abcdefgh
27 if item.is_file(): 1abcdefgh
28 item.unlink() 1abcdefgh
29 app_dir.rmdir() 1abcdefgh
32def test_cli(app_dir: Path): 1abcdefgh
33 with patch("typer.launch") as launch_mock: 1abcdefgh
34 result = runner.invoke(mod.app) 1abcdefgh
36 assert result.exit_code == 0 1abcdefgh
37 assert "Opening config directory" in result.output 1abcdefgh
38 launch_mock.assert_called_with(str(app_dir / "config.json"), locate=True) 1abcdefgh
41def test_script(): 1abcdefgh
42 result = subprocess.run( 1abcdefgh
43 [sys.executable, "-m", "coverage", "run", mod.__file__, "--help"],
44 capture_output=True,
45 encoding="utf-8",
46 )
47 assert "Usage" in result.stdout 1abcdefgh