Coverage for tests / test_tutorial / test_commands / test_help / test_tutorial007.py: 100%
46 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 types import ModuleType 1abcdefgh
7import pytest 1abcdefgh
8from typer.testing import CliRunner 1abcdefgh
10from ....utils import needs_py310 1abcdefgh
12runner = CliRunner() 1abcdefgh
15@pytest.fixture( 1abcdefgh
16 name="mod",
17 params=[
18 pytest.param("tutorial007_py39"),
19 pytest.param("tutorial007_py310", marks=needs_py310),
20 pytest.param("tutorial007_an_py39"),
21 pytest.param("tutorial007_an_py310", marks=needs_py310),
22 ],
23)
24def get_mod(request: pytest.FixtureRequest) -> ModuleType: 1abcdefgh
25 module_name = f"docs_src.commands.help.{request.param}" 1abcdefgh
26 mod = importlib.import_module(module_name) 1abcdefgh
27 return mod 1abcdefgh
30def test_main_help(mod: ModuleType): 1abcdefgh
31 result = runner.invoke(mod.app, ["--help"]) 1abcdefgh
32 assert result.exit_code == 0 1abcdefgh
33 assert "create" in result.output 1abcdefgh
34 assert "Create a new user. ✨" in result.output 1abcdefgh
35 assert "Utils and Configs" in result.output 1abcdefgh
36 assert "config" in result.output 1abcdefgh
37 assert "Configure the system. ⚙" in result.output 1abcdefgh
40def test_create_help(mod: ModuleType): 1abcdefgh
41 result = runner.invoke(mod.app, ["create", "--help"]) 1abcdefgh
42 assert result.exit_code == 0 1abcdefgh
43 assert "username" in result.output 1abcdefgh
44 assert "The username to create" in result.output 1abcdefgh
45 assert "Secondary Arguments" in result.output 1abcdefgh
46 assert "lastname" in result.output 1abcdefgh
47 assert "The last name of the new user" in result.output 1abcdefgh
48 assert "--force" in result.output 1abcdefgh
49 assert "--no-force" in result.output 1abcdefgh
50 assert "Force the creation of the user" in result.output 1abcdefgh
51 assert "Additional Data" in result.output 1abcdefgh
52 assert "--age" in result.output 1abcdefgh
53 assert "The age of the new user" in result.output 1abcdefgh
54 assert "--favorite-color" in result.output 1abcdefgh
55 assert "The favorite color of the new user" in result.output 1abcdefgh
58def test_call(mod: ModuleType): 1abcdefgh
59 # Mainly for coverage
60 result = runner.invoke(mod.app, ["create", "Morty"]) 1abcdefgh
61 assert result.exit_code == 0 1abcdefgh
62 result = runner.invoke(mod.app, ["config", "Morty"]) 1abcdefgh
63 assert result.exit_code == 0 1abcdefgh
66def test_script(mod: ModuleType): 1abcdefgh
67 result = subprocess.run( 1abcdefgh
68 [sys.executable, "-m", "coverage", "run", mod.__file__, "--help"],
69 capture_output=True,
70 encoding="utf-8",
71 env={**os.environ, "PYTHONIOENCODING": "utf-8"},
72 )
73 assert "Usage" in result.stdout 1abcdefgh