Skip to content

Commit 323a64b

Browse files
committed
Handle missing COMP_WORDS and COMP_CWORD in completion script
1 parent 03118f7 commit 323a64b

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

tests/functional/test_completion.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
# dropping support for Python 3.7.
1515
Protocol = object
1616

17-
1817
COMPLETION_FOR_SUPPORTED_SHELLS_TESTS = (
1918
(
2019
"bash",
@@ -133,6 +132,7 @@ def __call__(
133132
cword: str,
134133
cwd: Union[Path, str, None] = None,
135134
include_env: bool = True,
135+
expect_error: bool = True,
136136
) -> Tuple[TestPipResult, PipTestEnvironment]:
137137
...
138138

@@ -149,6 +149,7 @@ def do_autocomplete(
149149
cword: str,
150150
cwd: Union[Path, str, None] = None,
151151
include_env: bool = True,
152+
expect_error: bool = True,
152153
) -> Tuple[TestPipResult, PipTestEnvironment]:
153154
if include_env:
154155
autocomplete_script.environ["COMP_WORDS"] = words
@@ -158,7 +159,7 @@ def do_autocomplete(
158159
"-c",
159160
"from pip._internal.cli.autocompletion import autocomplete;"
160161
"autocomplete()",
161-
expect_error=True,
162+
expect_error=expect_error,
162163
cwd=cwd,
163164
)
164165

@@ -176,6 +177,17 @@ def test_completion_for_unknown_shell(autocomplete_script: PipTestEnvironment) -
176177
assert error_msg in result.stderr, "tests for an unknown shell failed"
177178

178179

180+
def test_completion_without_env_vars(autocomplete: DoAutocomplete) -> None:
181+
"""
182+
Test getting completion <path> after options in command
183+
given absolute path
184+
"""
185+
res, env = autocomplete(
186+
words="pip install ", cword="", include_env=False, expect_error=False
187+
)
188+
assert res.stdout == "", "autocomplete function did not complete"
189+
190+
179191
def test_completion_alone(autocomplete_script: PipTestEnvironment) -> None:
180192
"""
181193
Test getting completion for none shell, just pip completion
@@ -417,16 +429,3 @@ def test_completion_uses_same_executable_name(
417429
expect_stderr=deprecated_python,
418430
)
419431
assert executable_name in result.stdout
420-
421-
422-
def test_completion_without_env_vars(autocomplete: DoAutocomplete) -> None:
423-
"""
424-
Test getting completion <path> after options in command
425-
given absolute path
426-
"""
427-
res, env = autocomplete(
428-
words="pip install ",
429-
cword="",
430-
include_env=False,
431-
)
432-
assert res.stdout == ""

0 commit comments

Comments
 (0)