Coverage for tests/test_tutorial/test_commands/test_help/test_tutorial007_an.py: 100%
39 statements
« prev ^ index » next coverage.py v7.6.1, created at 2025-04-14 00:18 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2025-04-14 00:18 +0000
1import os 1abcdefghi
2import subprocess 1abcdefghi
3import sys 1abcdefghi
5from typer.testing import CliRunner 1abcdefghi
7from docs_src.commands.help import tutorial007_an as mod 1abcdefghi
9app = mod.app 1abcdefghi
11runner = CliRunner() 1abcdefghi
14def test_main_help(): 1abcdefghi
15 result = runner.invoke(app, ["--help"]) 1abcdefghi
16 assert result.exit_code == 0 1abcdefghi
17 assert "create" in result.output 1abcdefghi
18 assert "Create a new user. ✨" in result.output 1abcdefghi
19 assert "Utils and Configs" in result.output 1abcdefghi
20 assert "config" in result.output 1abcdefghi
21 assert "Configure the system. 🔧" in result.output 1abcdefghi
24def test_create_help(): 1abcdefghi
25 result = runner.invoke(app, ["create", "--help"]) 1abcdefghi
26 assert result.exit_code == 0 1abcdefghi
27 assert "username" in result.output 1abcdefghi
28 assert "The username to create" in result.output 1abcdefghi
29 assert "Secondary Arguments" in result.output 1abcdefghi
30 assert "lastname" in result.output 1abcdefghi
31 assert "The last name of the new user" in result.output 1abcdefghi
32 assert "--force" in result.output 1abcdefghi
33 assert "--no-force" in result.output 1abcdefghi
34 assert "Force the creation of the user" in result.output 1abcdefghi
35 assert "Additional Data" in result.output 1abcdefghi
36 assert "--age" in result.output 1abcdefghi
37 assert "The age of the new user" in result.output 1abcdefghi
38 assert "--favorite-color" in result.output 1abcdefghi
39 assert "The favorite color of the new user" in result.output 1abcdefghi
42def test_call(): 1abcdefghi
43 # Mainly for coverage
44 result = runner.invoke(app, ["create", "Morty"]) 1abcdefghi
45 assert result.exit_code == 0 1abcdefghi
46 result = runner.invoke(app, ["config", "Morty"]) 1abcdefghi
47 assert result.exit_code == 0 1abcdefghi
50def test_script(): 1abcdefghi
51 result = subprocess.run( 1abcdefghi
52 [sys.executable, "-m", "coverage", "run", mod.__file__, "--help"],
53 capture_output=True,
54 encoding="utf-8",
55 env={**os.environ, "PYTHONIOENCODING": "utf-8"},
56 )
57 assert "Usage" in result.stdout 1abcdefghi