Coverage for tests/test_completion/test_completion_complete.py: 100%

34 statements  

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

1import os 1abcdefgh

2import subprocess 1abcdefgh

3import sys 1abcdefgh

4 

5from docs_src.commands.help import tutorial001 as mod 1abcdefgh

6 

7 

8def test_completion_complete_subcommand_bash(): 1abcdefgh

9 result = subprocess.run( 1abcdefgh

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

11 capture_output=True, 

12 encoding="utf-8", 

13 env={ 

14 **os.environ, 

15 "_TUTORIAL001.PY_COMPLETE": "complete_bash", 

16 "COMP_WORDS": "tutorial001.py del", 

17 "COMP_CWORD": "1", 

18 }, 

19 ) 

20 assert "delete\ndelete-all" in result.stdout 1abcdefgh

21 

22 

23def test_completion_complete_subcommand_bash_invalid(): 1abcdefgh

24 result = subprocess.run( 1abcdefgh

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

26 capture_output=True, 

27 encoding="utf-8", 

28 env={ 

29 **os.environ, 

30 "_TUTORIAL001.PY_COMPLETE": "complete_bash", 

31 "COMP_WORDS": "tutorial001.py del", 

32 "COMP_CWORD": "42", 

33 }, 

34 ) 

35 assert "create\ndelete\ndelete-all\ninit" in result.stdout 1abcdefgh

36 

37 

38def test_completion_complete_subcommand_zsh(): 1abcdefgh

39 result = subprocess.run( 1abcdefgh

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

41 capture_output=True, 

42 encoding="utf-8", 

43 env={ 

44 **os.environ, 

45 "_TUTORIAL001.PY_COMPLETE": "complete_zsh", 

46 "_TYPER_COMPLETE_ARGS": "tutorial001.py del", 

47 }, 

48 ) 

49 assert ( 1abcdefgh

50 """_arguments '*: :(("delete":"Delete a user with USERNAME."\n""" 

51 """\"delete-all":"Delete ALL users in the database."))'""" 

52 ) in result.stdout 

53 

54 

55def test_completion_complete_subcommand_zsh_files(): 1abcdefgh

56 result = subprocess.run( 1abcdefgh

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

58 capture_output=True, 

59 encoding="utf-8", 

60 env={ 

61 **os.environ, 

62 "_TUTORIAL001.PY_COMPLETE": "complete_zsh", 

63 "_TYPER_COMPLETE_ARGS": "tutorial001.py delete ", 

64 }, 

65 ) 

66 assert ("_files") in result.stdout 1abcdefgh

67 

68 

69def test_completion_complete_subcommand_fish(): 1abcdefgh

70 result = subprocess.run( 1abcdefgh

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

72 capture_output=True, 

73 encoding="utf-8", 

74 env={ 

75 **os.environ, 

76 "_TUTORIAL001.PY_COMPLETE": "complete_fish", 

77 "_TYPER_COMPLETE_ARGS": "tutorial001.py del", 

78 "_TYPER_COMPLETE_FISH_ACTION": "get-args", 

79 }, 

80 ) 

81 assert ( 1abcdefgh

82 "delete\tDelete a user with USERNAME.\ndelete-all\tDelete ALL users in the database." 

83 in result.stdout 

84 ) 

85 

86 

87def test_completion_complete_subcommand_fish_should_complete(): 1abcdefgh

88 result = subprocess.run( 1abcdefgh

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

90 capture_output=True, 

91 encoding="utf-8", 

92 env={ 

93 **os.environ, 

94 "_TUTORIAL001.PY_COMPLETE": "complete_fish", 

95 "_TYPER_COMPLETE_ARGS": "tutorial001.py del", 

96 "_TYPER_COMPLETE_FISH_ACTION": "is-args", 

97 }, 

98 ) 

99 assert result.returncode == 0 1abcdefgh

100 

101 

102def test_completion_complete_subcommand_fish_should_complete_no(): 1abcdefgh

103 result = subprocess.run( 1abcdefgh

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

105 capture_output=True, 

106 encoding="utf-8", 

107 env={ 

108 **os.environ, 

109 "_TUTORIAL001.PY_COMPLETE": "complete_fish", 

110 "_TYPER_COMPLETE_ARGS": "tutorial001.py delete ", 

111 "_TYPER_COMPLETE_FISH_ACTION": "is-args", 

112 }, 

113 ) 

114 assert result.returncode != 0 1abcdefgh

115 

116 

117def test_completion_complete_subcommand_powershell(): 1abcdefgh

118 result = subprocess.run( 1abcdefgh

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

120 capture_output=True, 

121 encoding="utf-8", 

122 env={ 

123 **os.environ, 

124 "_TUTORIAL001.PY_COMPLETE": "complete_powershell", 

125 "_TYPER_COMPLETE_ARGS": "tutorial001.py del", 

126 }, 

127 ) 

128 assert ( 1abcdefgh

129 "delete:::Delete a user with USERNAME.\ndelete-all:::Delete ALL users in the database." 

130 ) in result.stdout 

131 

132 

133def test_completion_complete_subcommand_pwsh(): 1abcdefgh

134 result = subprocess.run( 1abcdefgh

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

136 capture_output=True, 

137 encoding="utf-8", 

138 env={ 

139 **os.environ, 

140 "_TUTORIAL001.PY_COMPLETE": "complete_pwsh", 

141 "_TYPER_COMPLETE_ARGS": "tutorial001.py del", 

142 }, 

143 ) 

144 assert ( 1abcdefgh

145 "delete:::Delete a user with USERNAME.\ndelete-all:::Delete ALL users in the database." 

146 ) in result.stdout 

147 

148 

149def test_completion_complete_subcommand_noshell(): 1abcdefgh

150 result = subprocess.run( 1abcdefgh

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

152 capture_output=True, 

153 encoding="utf-8", 

154 env={ 

155 **os.environ, 

156 "_TUTORIAL001.PY_COMPLETE": "complete_noshell", 

157 "_TYPER_COMPLETE_ARGS": "tutorial001.py del", 

158 }, 

159 ) 

160 assert ("") in result.stdout 1abcdefgh