Coverage for tests/test_tutorial/test_commands/test_help/test_tutorial005_an.py: 100%
41 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 tutorial005_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 "Learn more at the Typer docs website" in result.output 1abcdefghi
31 assert "Some internal utility function to create." not in result.output 1abcdefghi
34def test_help_delete(): 1abcdefghi
35 result = runner.invoke(app, ["delete", "--help"]) 1abcdefghi
36 assert result.exit_code == 0 1abcdefghi
37 assert "Delete a user with USERNAME." in result.output 1abcdefghi
38 assert "The username to be deleted" in result.output 1abcdefghi
39 assert "Force the deletion 💥" in result.output 1abcdefghi
40 assert "Some internal utility function to delete." not in result.output 1abcdefghi
43def test_create(): 1abcdefghi
44 result = runner.invoke(app, ["create", "Camila"]) 1abcdefghi
45 assert result.exit_code == 0 1abcdefghi
46 assert "Creating user: Camila" in result.output 1abcdefghi
49def test_delete(): 1abcdefghi
50 result = runner.invoke(app, ["delete", "Camila"]) 1abcdefghi
51 assert result.exit_code == 0 1abcdefghi
52 assert "Deleting user: Camila" in result.output 1abcdefghi
55def test_script(): 1abcdefghi
56 result = subprocess.run( 1abcdefghi
57 [sys.executable, "-m", "coverage", "run", mod.__file__, "--help"],
58 capture_output=True,
59 encoding="utf-8",
60 env={**os.environ, "PYTHONIOENCODING": "utf-8"},
61 )
62 assert "Usage" in result.stdout 1abcdefghi