Coverage for tests/test_tutorial/test_commands/test_callback/test_tutorial001.py: 100%

51 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-09-09 18:26 +0000

1import subprocess 1abcdefgh

2import sys 1abcdefgh

3 

4import typer.core 1abcdefgh

5from typer.testing import CliRunner 1abcdefgh

6 

7from docs_src.commands.callback import tutorial001 as mod 1abcdefgh

8 

9app = mod.app 1abcdefgh

10 

11runner = CliRunner() 1abcdefgh

12 

13 

14def test_help(): 1abcdefgh

15 result = runner.invoke(app, ["--help"]) 1abcdefgh

16 assert result.exit_code == 0 1abcdefgh

17 assert "Manage users in the awesome CLI app." in result.output 1abcdefgh

18 assert "--verbose" in result.output 1abcdefgh

19 assert "--no-verbose" in result.output 1abcdefgh

20 

21 

22def test_help_no_rich(): 1abcdefgh

23 rich = typer.core.rich 1abcdefgh

24 typer.core.rich = None 1abcdefgh

25 result = runner.invoke(app, ["--help"]) 1abcdefgh

26 assert result.exit_code == 0 1abcdefgh

27 assert "Manage users in the awesome CLI app." in result.output 1abcdefgh

28 assert "--verbose" in result.output 1abcdefgh

29 assert "--no-verbose" in result.output 1abcdefgh

30 typer.core.rich = rich 1abcdefgh

31 

32 

33def test_create(): 1abcdefgh

34 result = runner.invoke(app, ["create", "Camila"]) 1abcdefgh

35 assert result.exit_code == 0 1abcdefgh

36 assert "Creating user: Camila" in result.output 1abcdefgh

37 

38 

39def test_create_verbose(): 1abcdefgh

40 result = runner.invoke(app, ["--verbose", "create", "Camila"]) 1abcdefgh

41 assert result.exit_code == 0 1abcdefgh

42 assert "Will write verbose output" in result.output 1abcdefgh

43 assert "About to create a user" in result.output 1abcdefgh

44 assert "Creating user: Camila" in result.output 1abcdefgh

45 assert "Just created a user" in result.output 1abcdefgh

46 

47 

48def test_delete(): 1abcdefgh

49 result = runner.invoke(app, ["delete", "Camila"]) 1abcdefgh

50 assert result.exit_code == 0 1abcdefgh

51 assert "Deleting user: Camila" in result.output 1abcdefgh

52 

53 

54def test_delete_verbose(): 1abcdefgh

55 result = runner.invoke(app, ["--verbose", "delete", "Camila"]) 1abcdefgh

56 assert result.exit_code == 0 1abcdefgh

57 assert "Will write verbose output" in result.output 1abcdefgh

58 assert "About to delete a user" in result.output 1abcdefgh

59 assert "Deleting user: Camila" in result.output 1abcdefgh

60 assert "Just deleted a user" in result.output 1abcdefgh

61 

62 

63def test_wrong_verbose(): 1abcdefgh

64 result = runner.invoke(app, ["delete", "--verbose", "Camila"]) 1abcdefgh

65 assert result.exit_code != 0 1abcdefgh

66 assert "No such option: --verbose" in result.output 1abcdefgh

67 

68 

69def test_script(): 1abcdefgh

70 result = subprocess.run( 1abcdefgh

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

72 capture_output=True, 

73 encoding="utf-8", 

74 ) 

75 assert "Usage" in result.stdout 1abcdefgh