Coverage for tests / test_tutorial / test_options_autocompletion / test_tutorial004_tutorial005.py: 100%
27 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-11-18 11:12 +0000
« prev ^ index » next coverage.py v7.13.1, created at 2026-11-18 11:12 +0000
1import importlib 1abcdefghij
2import os 1abcdefghij
3import subprocess 1abcdefghij
4import sys 1abcdefghij
5from pathlib import Path 1abcdefghij
6from types import ModuleType 1abcdefghij
8import pytest 1abcdefghij
9from typer.testing import CliRunner 1abcdefghij
11runner = CliRunner() 1abcdefghij
14@pytest.fixture( 1abcdefghij
15 name="mod",
16 params=[
17 pytest.param("tutorial004_non_an"),
18 pytest.param("tutorial004"),
19 pytest.param("tutorial005_non_an"),
20 pytest.param("tutorial005"),
21 ],
22)
23def get_mod(request: pytest.FixtureRequest) -> ModuleType: 1abcdefghij
24 module_name = f"docs_src.options_autocompletion.{request.param}" 1abcdefghij
25 mod = importlib.import_module(module_name) 1abcdefghij
26 return mod 1abcdefghij
29def test_completion(mod: ModuleType): 1abcdefghij
30 file_name = Path(mod.__file__).name 1abcdefghij
31 result = subprocess.run( 1abcdefghij
32 [sys.executable, "-m", "coverage", "run", mod.__file__, " "],
33 capture_output=True,
34 encoding="utf-8",
35 env={
36 **os.environ,
37 f"_{file_name.upper()}_COMPLETE": "complete_zsh",
38 "_TYPER_COMPLETE_ARGS": f"{file_name} --name ",
39 },
40 )
41 assert '"Camila":"The reader of books."' in result.stdout 1abcdefghij
42 assert '"Carlos":"The writer of scripts."' in result.stdout 1abcdefghij
43 assert '"Sebastian":"The type hints guy."' in result.stdout 1abcdefghij
46def test_1(mod: ModuleType): 1abcdefghij
47 result = runner.invoke(mod.app, ["--name", "Camila"]) 1abcdefghij
48 assert result.exit_code == 0 1abcdefghij
49 assert "Hello Camila" in result.output 1abcdefghij
52def test_script(mod: ModuleType): 1abcdefghij
53 result = subprocess.run( 1abcdefghij
54 [sys.executable, "-m", "coverage", "run", mod.__file__, "--help"],
55 capture_output=True,
56 encoding="utf-8",
57 )
58 assert "Usage" in result.stdout 1abcdefghij