@@ -120,7 +120,12 @@ def autocomplete_script(
120
120
121
121
class DoAutocomplete (Protocol ):
122
122
def __call__ (
123
- self , words : str , cword : str , cwd : Union [Path , str , None ] = None
123
+ self ,
124
+ words : str ,
125
+ cword : str ,
126
+ cwd : Union [Path , str , None ] = None ,
127
+ include_env : bool = True ,
128
+ expect_error : bool = True ,
124
129
) -> Tuple [TestPipResult , PipTestEnvironment ]:
125
130
...
126
131
@@ -133,16 +138,21 @@ def autocomplete(
133
138
autocomplete_script .environ ["PIP_AUTO_COMPLETE" ] = "1"
134
139
135
140
def do_autocomplete (
136
- words : str , cword : str , cwd : Union [Path , str , None ] = None
141
+ words : str ,
142
+ cword : str ,
143
+ cwd : Union [Path , str , None ] = None ,
144
+ include_env : bool = True ,
145
+ expect_error : bool = True ,
137
146
) -> Tuple [TestPipResult , PipTestEnvironment ]:
138
- autocomplete_script .environ ["COMP_WORDS" ] = words
139
- autocomplete_script .environ ["COMP_CWORD" ] = cword
147
+ if include_env :
148
+ autocomplete_script .environ ["COMP_WORDS" ] = words
149
+ autocomplete_script .environ ["COMP_CWORD" ] = cword
140
150
result = autocomplete_script .run (
141
151
"python" ,
142
152
"-c" ,
143
153
"from pip._internal.cli.autocompletion import autocomplete;"
144
154
"autocomplete()" ,
145
- expect_error = True ,
155
+ expect_error = expect_error ,
146
156
cwd = cwd ,
147
157
)
148
158
@@ -160,6 +170,17 @@ def test_completion_for_unknown_shell(autocomplete_script: PipTestEnvironment) -
160
170
assert error_msg in result .stderr , "tests for an unknown shell failed"
161
171
162
172
173
+ def test_completion_without_env_vars (autocomplete : DoAutocomplete ) -> None :
174
+ """
175
+ Test getting completion <path> after options in command
176
+ given absolute path
177
+ """
178
+ res , env = autocomplete (
179
+ words = "pip install " , cword = "" , include_env = False , expect_error = False
180
+ )
181
+ assert res .stdout == "" , "autocomplete function did not complete"
182
+
183
+
163
184
def test_completion_alone (autocomplete_script : PipTestEnvironment ) -> None :
164
185
"""
165
186
Test getting completion for none shell, just pip completion
0 commit comments