Coverage for tests / test_tutorial / test_subcommands / test_tutorial001.py: 100%
66 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 os 1abcdefghij
2import subprocess 1abcdefghij
3import sys 1abcdefghij
5import pytest 1abcdefghij
6from typer.testing import CliRunner 1abcdefghij
8from docs_src.subcommands import tutorial001 1abcdefghij
10runner = CliRunner() 1abcdefghij
13@pytest.fixture() 1abcdefghij
14def mod(monkeypatch): 1abcdefghij
15 with monkeypatch.context(): 1abcdefghij
16 monkeypatch.syspath_prepend(list(tutorial001.__path__)[0]) 1abcdefghij
17 from docs_src.subcommands.tutorial001 import main 1abcdefghij
19 return main 1abcdefghij
22@pytest.fixture() 1abcdefghij
23def app(mod): 1abcdefghij
24 return mod.app 1abcdefghij
27def test_help(app): 1abcdefghij
28 result = runner.invoke(app, ["--help"]) 1abcdefghij
29 assert result.exit_code == 0 1abcdefghij
30 assert "[OPTIONS] COMMAND [ARGS]..." in result.output 1abcdefghij
31 assert "Commands" in result.output 1abcdefghij
32 assert "items" in result.output 1abcdefghij
33 assert "users" in result.output 1abcdefghij
36def test_help_items(app): 1abcdefghij
37 result = runner.invoke(app, ["items", "--help"]) 1abcdefghij
38 assert result.exit_code == 0 1abcdefghij
39 assert "[OPTIONS] COMMAND [ARGS]..." in result.output 1abcdefghij
40 assert "Commands" in result.output 1abcdefghij
41 assert "create" in result.output 1abcdefghij
42 assert "delete" in result.output 1abcdefghij
43 assert "sell" in result.output 1abcdefghij
46def test_items_create(app): 1abcdefghij
47 result = runner.invoke(app, ["items", "create", "Wand"]) 1abcdefghij
48 assert result.exit_code == 0 1abcdefghij
49 assert "Creating item: Wand" in result.output 1abcdefghij
52def test_items_sell(app): 1abcdefghij
53 result = runner.invoke(app, ["items", "sell", "Vase"]) 1abcdefghij
54 assert result.exit_code == 0 1abcdefghij
55 assert "Selling item: Vase" in result.output 1abcdefghij
58def test_items_delete(app): 1abcdefghij
59 result = runner.invoke(app, ["items", "delete", "Vase"]) 1abcdefghij
60 assert result.exit_code == 0 1abcdefghij
61 assert "Deleting item: Vase" in result.output 1abcdefghij
64def test_help_users(app): 1abcdefghij
65 result = runner.invoke(app, ["users", "--help"]) 1abcdefghij
66 assert result.exit_code == 0 1abcdefghij
67 assert "[OPTIONS] COMMAND [ARGS]..." in result.output 1abcdefghij
68 assert "Commands" in result.output 1abcdefghij
69 assert "create" in result.output 1abcdefghij
70 assert "delete" in result.output 1abcdefghij
71 assert "sell" not in result.output 1abcdefghij
74def test_users_create(app): 1abcdefghij
75 result = runner.invoke(app, ["users", "create", "Camila"]) 1abcdefghij
76 assert result.exit_code == 0 1abcdefghij
77 assert "Creating user: Camila" in result.output 1abcdefghij
80def test_users_delete(app): 1abcdefghij
81 result = runner.invoke(app, ["users", "delete", "Camila"]) 1abcdefghij
82 assert result.exit_code == 0 1abcdefghij
83 assert "Deleting user: Camila" in result.output 1abcdefghij
86def test_scripts(mod): 1abcdefghij
87 from docs_src.subcommands.tutorial001 import items, users 1abcdefghij
89 env = os.environ.copy() 1abcdefghij
90 env["PYTHONPATH"] = ":".join(list(tutorial001.__path__)) 1abcdefghij
92 for module in [mod, items, users]: 1abcdefghij
93 result = subprocess.run( 1abcdefghij
94 [sys.executable, "-m", "coverage", "run", module.__file__, "--help"],
95 capture_output=True,
96 encoding="utf-8",
97 env=env,
98 )
99 assert "Usage" in result.stdout 1abcdefghij