Coverage for tests / test_tutorial / test_subcommands / test_tutorial002.py: 100%

52 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-11-18 11:12 +0000

1import subprocess 1abcdefghij

2import sys 1abcdefghij

3 

4from typer.testing import CliRunner 1abcdefghij

5 

6from docs_src.subcommands.tutorial002 import main as mod 1abcdefghij

7 

8app = mod.app 1abcdefghij

9runner = CliRunner() 1abcdefghij

10 

11 

12def test_help(): 1abcdefghij

13 result = runner.invoke(app, ["--help"]) 1abcdefghij

14 assert result.exit_code == 0 1abcdefghij

15 assert "[OPTIONS] COMMAND [ARGS]..." in result.output 1abcdefghij

16 assert "Commands" in result.output 1abcdefghij

17 assert "items" in result.output 1abcdefghij

18 assert "users" in result.output 1abcdefghij

19 

20 

21def test_help_items(): 1abcdefghij

22 result = runner.invoke(app, ["items", "--help"]) 1abcdefghij

23 assert result.exit_code == 0 1abcdefghij

24 assert "[OPTIONS] COMMAND [ARGS]..." in result.output 1abcdefghij

25 assert "Commands" in result.output 1abcdefghij

26 assert "create" in result.output 1abcdefghij

27 assert "delete" in result.output 1abcdefghij

28 assert "sell" in result.output 1abcdefghij

29 

30 

31def test_items_create(): 1abcdefghij

32 result = runner.invoke(app, ["items", "create", "Wand"]) 1abcdefghij

33 assert result.exit_code == 0 1abcdefghij

34 assert "Creating item: Wand" in result.output 1abcdefghij

35 

36 

37def test_items_sell(): 1abcdefghij

38 result = runner.invoke(app, ["items", "sell", "Vase"]) 1abcdefghij

39 assert result.exit_code == 0 1abcdefghij

40 assert "Selling item: Vase" in result.output 1abcdefghij

41 

42 

43def test_items_delete(): 1abcdefghij

44 result = runner.invoke(app, ["items", "delete", "Vase"]) 1abcdefghij

45 assert result.exit_code == 0 1abcdefghij

46 assert "Deleting item: Vase" in result.output 1abcdefghij

47 

48 

49def test_help_users(): 1abcdefghij

50 result = runner.invoke(app, ["users", "--help"]) 1abcdefghij

51 assert result.exit_code == 0 1abcdefghij

52 assert "[OPTIONS] COMMAND [ARGS]..." in result.output 1abcdefghij

53 assert "Commands" in result.output 1abcdefghij

54 assert "create" in result.output 1abcdefghij

55 assert "delete" in result.output 1abcdefghij

56 assert "sell" not in result.output 1abcdefghij

57 

58 

59def test_users_create(): 1abcdefghij

60 result = runner.invoke(app, ["users", "create", "Camila"]) 1abcdefghij

61 assert result.exit_code == 0 1abcdefghij

62 assert "Creating user: Camila" in result.output 1abcdefghij

63 

64 

65def test_users_delete(): 1abcdefghij

66 result = runner.invoke(app, ["users", "delete", "Camila"]) 1abcdefghij

67 assert result.exit_code == 0 1abcdefghij

68 assert "Deleting user: Camila" in result.output 1abcdefghij

69 

70 

71def test_script(): 1abcdefghij

72 result = subprocess.run( 1abcdefghij

73 [sys.executable, "-m", "coverage", "run", mod.__file__, "--help"], 

74 capture_output=True, 

75 encoding="utf-8", 

76 ) 

77 assert "Usage" in result.stdout 1abcdefghij