Coverage for tests/test_tutorial/test_commands/test_help/test_tutorial004_an.py: 100%
40 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 tutorial004_an as mod 1abcdefghi
9app = mod.app 1abcdefghi
11runner = CliRunner() 1abcdefghi
14def test_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 shinny user. ✨" in result.output 1abcdefghi
19 assert "delete" in result.output 1abcdefghi
20 assert "Delete a user with USERNAME." in result.output 1abcdefghi
21 assert "Some internal utility function to create." not in result.output 1abcdefghi
22 assert "Some internal utility function to delete." not in result.output 1abcdefghi
25def test_help_create(): 1abcdefghi
26 result = runner.invoke(app, ["create", "--help"]) 1abcdefghi
27 assert result.exit_code == 0 1abcdefghi
28 assert "Create a new shinny user. ✨" in result.output 1abcdefghi
29 assert "The username to be created" in result.output 1abcdefghi
30 assert "Some internal utility function to create." not in result.output 1abcdefghi
33def test_help_delete(): 1abcdefghi
34 result = runner.invoke(app, ["delete", "--help"]) 1abcdefghi
35 assert result.exit_code == 0 1abcdefghi
36 assert "Delete a user with USERNAME." in result.output 1abcdefghi
37 assert "The username to be deleted" in result.output 1abcdefghi
38 assert "Force the deletion 💥" in result.output 1abcdefghi
39 assert "Some internal utility function to delete." not in result.output 1abcdefghi
42def test_create(): 1abcdefghi
43 result = runner.invoke(app, ["create", "Camila"]) 1abcdefghi
44 assert result.exit_code == 0 1abcdefghi
45 assert "Creating user: Camila" in result.output 1abcdefghi
48def test_delete(): 1abcdefghi
49 result = runner.invoke(app, ["delete", "Camila"]) 1abcdefghi
50 assert result.exit_code == 0 1abcdefghi
51 assert "Deleting user: Camila" in result.output 1abcdefghi
54def test_script(): 1abcdefghi
55 result = subprocess.run( 1abcdefghi
56 [sys.executable, "-m", "coverage", "run", mod.__file__, "--help"],
57 capture_output=True,
58 encoding="utf-8",
59 env={**os.environ, "PYTHONIOENCODING": "utf-8"},
60 )
61 assert "Usage" in result.stdout 1abcdefghi