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 2024-09-09 18:26 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-09-09 18:26 +0000
1import os 1abcdefgh
2import subprocess 1abcdefgh
3import sys 1abcdefgh
5from typer.testing import CliRunner 1abcdefgh
7from docs_src.commands.help import tutorial007_an as mod 1abcdefgh
9app = mod.app 1abcdefgh
11runner = CliRunner() 1abcdefgh
14def test_main_help(): 1abcdefgh
15 result = runner.invoke(app, ["--help"]) 1abcdefgh
16 assert result.exit_code == 0 1abcdefgh
17 assert "create" in result.output 1abcdefgh
18 assert "Create a new user. ✨" in result.output 1abcdefgh
19 assert "Utils and Configs" in result.output 1abcdefgh
20 assert "config" in result.output 1abcdefgh
21 assert "Configure the system. 🔧" in result.output 1abcdefgh
24def test_create_help(): 1abcdefgh
25 result = runner.invoke(app, ["create", "--help"]) 1abcdefgh
26 assert result.exit_code == 0 1abcdefgh
27 assert "username" in result.output 1abcdefgh
28 assert "The username to create" in result.output 1abcdefgh
29 assert "Secondary Arguments" in result.output 1abcdefgh
30 assert "lastname" in result.output 1abcdefgh
31 assert "The last name of the new user" in result.output 1abcdefgh
32 assert "--force" in result.output 1abcdefgh
33 assert "--no-force" in result.output 1abcdefgh
34 assert "Force the creation of the user" in result.output 1abcdefgh
35 assert "Additional Data" in result.output 1abcdefgh
36 assert "--age" in result.output 1abcdefgh
37 assert "The age of the new user" in result.output 1abcdefgh
38 assert "--favorite-color" in result.output 1abcdefgh
39 assert "The favorite color of the new user" in result.output 1abcdefgh
42def test_call(): 1abcdefgh
43 # Mainly for coverage
44 result = runner.invoke(app, ["create", "Morty"]) 1abcdefgh
45 assert result.exit_code == 0 1abcdefgh
46 result = runner.invoke(app, ["config", "Morty"]) 1abcdefgh
47 assert result.exit_code == 0 1abcdefgh
50def test_script(): 1abcdefgh
51 result = subprocess.run( 1abcdefgh
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 1abcdefgh