Coverage for tests / test_tutorial / test_commands / test_help / test_tutorial001.py: 100%
83 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 subprocess 1abcdefghij
3import sys 1abcdefghij
4from types import ModuleType 1abcdefghij
6import pytest 1abcdefghij
7from typer.testing import CliRunner 1abcdefghij
9runner = CliRunner() 1abcdefghij
12@pytest.fixture( 1abcdefghij
13 name="mod",
14 params=[
15 pytest.param("tutorial001_non_an"),
16 pytest.param("tutorial001"),
17 ],
18)
19def get_mod(request: pytest.FixtureRequest) -> ModuleType: 1abcdefghij
20 module_name = f"docs_src.commands.help.{request.param}" 1abcdefghij
21 mod = importlib.import_module(module_name) 1abcdefghij
22 return mod 1abcdefghij
25def test_help(mod: ModuleType): 1abcdefghij
26 result = runner.invoke(mod.app, ["--help"]) 1abcdefghij
27 assert result.exit_code == 0 1abcdefghij
28 assert "Awesome CLI user manager." in result.output 1abcdefghij
29 assert "create" in result.output 1abcdefghij
30 assert "Create a new user with username." in result.output 1abcdefghij
31 assert "delete" in result.output 1abcdefghij
32 assert "Delete a user with username." in result.output 1abcdefghij
33 assert "delete-all" in result.output 1abcdefghij
34 assert "Delete ALL users in the database." in result.output 1abcdefghij
35 assert "init" in result.output 1abcdefghij
36 assert "Initialize the users database." in result.output 1abcdefghij
39def test_help_create(mod: ModuleType): 1abcdefghij
40 result = runner.invoke(mod.app, ["create", "--help"]) 1abcdefghij
41 assert result.exit_code == 0 1abcdefghij
42 assert "create [OPTIONS] {username}" in result.output 1abcdefghij
43 assert "Create a new user with username." in result.output 1abcdefghij
46def test_help_delete(mod: ModuleType): 1abcdefghij
47 result = runner.invoke(mod.app, ["delete", "--help"]) 1abcdefghij
48 assert result.exit_code == 0 1abcdefghij
49 assert "delete [OPTIONS] {username}" in result.output 1abcdefghij
50 assert "Delete a user with username." in result.output 1abcdefghij
51 assert "--force" in result.output 1abcdefghij
52 assert "--no-force" in result.output 1abcdefghij
53 assert "Force deletion without confirmation." in result.output 1abcdefghij
56def test_help_delete_all(mod: ModuleType): 1abcdefghij
57 result = runner.invoke(mod.app, ["delete-all", "--help"]) 1abcdefghij
58 assert result.exit_code == 0 1abcdefghij
59 assert "delete-all [OPTIONS]" in result.output 1abcdefghij
60 assert "Delete ALL users in the database." in result.output 1abcdefghij
61 assert "If --force is not used, will ask for confirmation." in result.output 1abcdefghij
62 assert "[required]" in result.output 1abcdefghij
63 assert "--force" in result.output 1abcdefghij
64 assert "--no-force" in result.output 1abcdefghij
65 assert "Force deletion without confirmation." in result.output 1abcdefghij
68def test_help_init(mod: ModuleType): 1abcdefghij
69 result = runner.invoke(mod.app, ["init", "--help"]) 1abcdefghij
70 assert result.exit_code == 0 1abcdefghij
71 assert "init [OPTIONS]" in result.output 1abcdefghij
72 assert "Initialize the users database." in result.output 1abcdefghij
75def test_create(mod: ModuleType): 1abcdefghij
76 result = runner.invoke(mod.app, ["create", "Camila"]) 1abcdefghij
77 assert result.exit_code == 0 1abcdefghij
78 assert "Creating user: Camila" in result.output 1abcdefghij
81def test_delete(mod: ModuleType): 1abcdefghij
82 result = runner.invoke(mod.app, ["delete", "Camila"], input="y\n") 1abcdefghij
83 assert result.exit_code == 0 1abcdefghij
84 assert "Are you sure you want to delete the user? [y/n]:" in result.output 1abcdefghij
85 assert "Deleting user: Camila" in result.output 1abcdefghij
88def test_no_delete(mod: ModuleType): 1abcdefghij
89 result = runner.invoke(mod.app, ["delete", "Camila"], input="n\n") 1abcdefghij
90 assert result.exit_code == 0 1abcdefghij
91 assert "Are you sure you want to delete the user? [y/n]:" in result.output 1abcdefghij
92 assert "Operation cancelled" in result.output 1abcdefghij
95def test_delete_all(mod: ModuleType): 1abcdefghij
96 result = runner.invoke(mod.app, ["delete-all"], input="y\n") 1abcdefghij
97 assert result.exit_code == 0 1abcdefghij
98 assert "Are you sure you want to delete ALL users? [y/n]:" in result.output 1abcdefghij
99 assert "Deleting all users" in result.output 1abcdefghij
102def test_no_delete_all(mod: ModuleType): 1abcdefghij
103 result = runner.invoke(mod.app, ["delete-all"], input="n\n") 1abcdefghij
104 assert result.exit_code == 0 1abcdefghij
105 assert "Are you sure you want to delete ALL users? [y/n]:" in result.output 1abcdefghij
106 assert "Operation cancelled" in result.output 1abcdefghij
109def test_init(mod: ModuleType): 1abcdefghij
110 result = runner.invoke(mod.app, ["init"]) 1abcdefghij
111 assert result.exit_code == 0 1abcdefghij
112 assert "Initializing user database" in result.output 1abcdefghij
115def test_script(mod: ModuleType): 1abcdefghij
116 result = subprocess.run( 1abcdefghij
117 [sys.executable, "-m", "coverage", "run", mod.__file__, "--help"],
118 capture_output=True,
119 encoding="utf-8",
120 )
121 assert "Usage" in result.stdout 1abcdefghij