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

23 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_hello(): 1abcdefgh

6 result = subprocess.run( 1abcdefgh

7 [ 

8 sys.executable, 

9 "-m", 

10 "coverage", 

11 "run", 

12 "-m", 

13 "typer", 

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

15 "run", 

16 "hello", 

17 ], 

18 capture_output=True, 

19 encoding="utf-8", 

20 ) 

21 assert "Hello World!" in result.stdout 1abcdefgh

22 

23 

24def test_script_hello_name(): 1abcdefgh

25 result = subprocess.run( 1abcdefgh

26 [ 

27 sys.executable, 

28 "-m", 

29 "coverage", 

30 "run", 

31 "-m", 

32 "typer", 

33 "tests/assets/cli/sample.py", 

34 "run", 

35 "hello", 

36 "--name", 

37 "Camila", 

38 ], 

39 capture_output=True, 

40 encoding="utf-8", 

41 ) 

42 assert "Hello Camila!" in result.stdout 1abcdefgh

43 

44 

45def test_script_hello_name_formal(): 1abcdefgh

46 result = subprocess.run( 1abcdefgh

47 [ 

48 sys.executable, 

49 "-m", 

50 "coverage", 

51 "run", 

52 "-m", 

53 "typer", 

54 "tests/assets/cli/sample.py", 

55 "run", 

56 "hello", 

57 "--name", 

58 "Camila", 

59 "--formal", 

60 ], 

61 capture_output=True, 

62 encoding="utf-8", 

63 ) 

64 assert "Good morning Ms. Camila" in result.stdout 1abcdefgh

65 

66 

67def test_script_bye(): 1abcdefgh

68 result = subprocess.run( 1abcdefgh

69 [ 

70 sys.executable, 

71 "-m", 

72 "coverage", 

73 "run", 

74 "-m", 

75 "typer", 

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

77 "run", 

78 "bye", 

79 ], 

80 capture_output=True, 

81 encoding="utf-8", 

82 ) 

83 assert "Goodbye" in result.stdout 1abcdefgh

84 

85 

86def test_script_bye_friend(): 1abcdefgh

87 result = subprocess.run( 1abcdefgh

88 [ 

89 sys.executable, 

90 "-m", 

91 "coverage", 

92 "run", 

93 "-m", 

94 "typer", 

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

96 "run", 

97 "bye", 

98 "--friend", 

99 ], 

100 capture_output=True, 

101 encoding="utf-8", 

102 ) 

103 assert "Goodbye my friend" in result.stdout 1abcdefgh

104 

105 

106def test_script_help(): 1abcdefgh

107 result = subprocess.run( 1abcdefgh

108 [ 

109 sys.executable, 

110 "-m", 

111 "coverage", 

112 "run", 

113 "-m", 

114 "typer", 

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

116 "--help", 

117 ], 

118 capture_output=True, 

119 encoding="utf-8", 

120 ) 

121 assert "run" in result.stdout 1abcdefgh

122 

123 

124def test_not_python(): 1abcdefgh

125 result = subprocess.run( 1abcdefgh

126 [ 

127 sys.executable, 

128 "-m", 

129 "coverage", 

130 "run", 

131 "-m", 

132 "typer", 

133 "tests/assets/cli/not_python.txt", 

134 "run", 

135 ], 

136 capture_output=True, 

137 encoding="utf-8", 

138 ) 

139 assert "Could not import as Python file" in result.stderr 1abcdefgh