Coverage for tests/test_cli/test_multi_app.py: 100%

22 statements  

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

1import subprocess 1abcdefgh

2import sys 1abcdefgh

3 

4 

5def test_script_help(): 1abcdefgh

6 result = subprocess.run( 1abcdefgh

7 [ 

8 sys.executable, 

9 "-m", 

10 "coverage", 

11 "run", 

12 "-m", 

13 "typer", 

14 "tests/assets/cli/multi_app.py", 

15 "run", 

16 "--help", 

17 ], 

18 capture_output=True, 

19 encoding="utf-8", 

20 ) 

21 assert "sub" in result.stdout 1abcdefgh

22 assert "top" in result.stdout 1abcdefgh

23 

24 

25def test_script_app_non_existent(): 1abcdefgh

26 result = subprocess.run( 1abcdefgh

27 [ 

28 sys.executable, 

29 "-m", 

30 "coverage", 

31 "run", 

32 "-m", 

33 "typer", 

34 "--app", 

35 "non_existent", 

36 "tests/assets/cli/multi_app.py", 

37 "run", 

38 "--help", 

39 ], 

40 capture_output=True, 

41 encoding="utf-8", 

42 ) 

43 assert "Not a Typer object:" in result.stderr 1abcdefgh

44 

45 

46def test_script_sub(): 1abcdefgh

47 result = subprocess.run( 1abcdefgh

48 [ 

49 sys.executable, 

50 "-m", 

51 "coverage", 

52 "run", 

53 "-m", 

54 "typer", 

55 "tests/assets/cli/multi_app.py", 

56 "run", 

57 "sub", 

58 "--help", 

59 ], 

60 capture_output=True, 

61 encoding="utf-8", 

62 ) 

63 assert "bye" in result.stdout 1abcdefgh

64 assert "hello" in result.stdout 1abcdefgh

65 

66 

67def test_script_top(): 1abcdefgh

68 result = subprocess.run( 1abcdefgh

69 [ 

70 sys.executable, 

71 "-m", 

72 "coverage", 

73 "run", 

74 "-m", 

75 "typer", 

76 "tests/assets/cli/multi_app.py", 

77 "run", 

78 "top", 

79 ], 

80 capture_output=True, 

81 encoding="utf-8", 

82 ) 

83 assert "top" in result.stdout 1abcdefgh

84 

85 

86def test_script_sub_hello(): 1abcdefgh

87 result = subprocess.run( 1abcdefgh

88 [ 

89 sys.executable, 

90 "-m", 

91 "coverage", 

92 "run", 

93 "-m", 

94 "typer", 

95 "tests/assets/cli/multi_app.py", 

96 "run", 

97 "sub", 

98 "hello", 

99 ], 

100 capture_output=True, 

101 encoding="utf-8", 

102 ) 

103 assert "Hello World" in result.stdout 1abcdefgh

104 

105 

106def test_script_sub_bye(): 1abcdefgh

107 result = subprocess.run( 1abcdefgh

108 [ 

109 sys.executable, 

110 "-m", 

111 "coverage", 

112 "run", 

113 "-m", 

114 "typer", 

115 "tests/assets/cli/multi_app.py", 

116 "run", 

117 "sub", 

118 "bye", 

119 ], 

120 capture_output=True, 

121 encoding="utf-8", 

122 ) 

123 assert "sub bye" in result.stdout 1abcdefgh