Coverage for tests / test_tutorial / test_options_autocompletion / test_tutorial009.py: 100%
29 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 importlib 1abcdefgh
2import os 1abcdefgh
3import subprocess 1abcdefgh
4import sys 1abcdefgh
5from pathlib import Path 1abcdefgh
6from types import ModuleType 1abcdefgh
8import pytest 1abcdefgh
9from typer.testing import CliRunner 1abcdefgh
11runner = CliRunner() 1abcdefgh
14@pytest.fixture( 1abcdefgh
15 name="mod",
16 params=[
17 pytest.param("tutorial009_py39"),
18 pytest.param("tutorial009_an_py39"),
19 ],
20)
21def get_mod(request: pytest.FixtureRequest) -> ModuleType: 1abcdefgh
22 module_name = f"docs_src.options_autocompletion.{request.param}" 1abcdefgh
23 mod = importlib.import_module(module_name) 1abcdefgh
24 return mod 1abcdefgh
27def test_completion(mod: ModuleType): 1abcdefgh
28 file_name = Path(mod.__file__).name 1abcdefgh
29 result = subprocess.run( 1abcdefgh
30 [sys.executable, "-m", "coverage", "run", mod.__file__, " "],
31 capture_output=True,
32 encoding="utf-8",
33 env={
34 **os.environ,
35 f"_{file_name.upper()}_COMPLETE": "complete_zsh",
36 "_TYPER_COMPLETE_ARGS": f"{file_name} --name Sebastian --name ",
37 },
38 )
39 assert '"Camila":"The reader of books."' in result.stdout 1abcdefgh
40 assert '"Carlos":"The writer of scripts."' in result.stdout 1abcdefgh
41 assert '"Sebastian":"The type hints guy."' not in result.stdout 1abcdefgh
42 assert "[]" in result.stderr 1abcdefgh
45def test_1(mod: ModuleType): 1abcdefgh
46 result = runner.invoke(mod.app, ["--name", "Camila", "--name", "Sebastian"]) 1abcdefgh
47 assert result.exit_code == 0 1abcdefgh
48 assert "Hello Camila" in result.output 1abcdefgh
49 assert "Hello Sebastian" in result.output 1abcdefgh
52def test_script(mod: ModuleType): 1abcdefgh
53 result = subprocess.run( 1abcdefgh
54 [sys.executable, "-m", "coverage", "run", mod.__file__, "--help"],
55 capture_output=True,
56 encoding="utf-8",
57 )
58 assert "Usage" in result.stdout 1abcdefgh