Skip to content

Commit

Permalink
Handle missing COMP_WORDS and COMP_CWORD in completion script
Browse files Browse the repository at this point in the history
  • Loading branch information
orf committed Nov 14, 2023
1 parent 03118f7 commit 323a64b
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions tests/functional/test_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# dropping support for Python 3.7.
Protocol = object


COMPLETION_FOR_SUPPORTED_SHELLS_TESTS = (
(
"bash",
Expand Down Expand Up @@ -133,6 +132,7 @@ def __call__(
cword: str,
cwd: Union[Path, str, None] = None,
include_env: bool = True,
expect_error: bool = True,
) -> Tuple[TestPipResult, PipTestEnvironment]:
...

Expand All @@ -149,6 +149,7 @@ def do_autocomplete(
cword: str,
cwd: Union[Path, str, None] = None,
include_env: bool = True,
expect_error: bool = True,
) -> Tuple[TestPipResult, PipTestEnvironment]:
if include_env:
autocomplete_script.environ["COMP_WORDS"] = words
Expand All @@ -158,7 +159,7 @@ def do_autocomplete(
"-c",
"from pip._internal.cli.autocompletion import autocomplete;"
"autocomplete()",
expect_error=True,
expect_error=expect_error,
cwd=cwd,
)

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


def test_completion_without_env_vars(autocomplete: DoAutocomplete) -> None:
"""
Test getting completion <path> after options in command
given absolute path
"""
res, env = autocomplete(
words="pip install ", cword="", include_env=False, expect_error=False
)
assert res.stdout == "", "autocomplete function did not complete"


def test_completion_alone(autocomplete_script: PipTestEnvironment) -> None:
"""
Test getting completion for none shell, just pip completion
Expand Down Expand Up @@ -417,16 +429,3 @@ def test_completion_uses_same_executable_name(
expect_stderr=deprecated_python,
)
assert executable_name in result.stdout


def test_completion_without_env_vars(autocomplete: DoAutocomplete) -> None:
"""
Test getting completion <path> after options in command
given absolute path
"""
res, env = autocomplete(
words="pip install ",
cword="",
include_env=False,
)
assert res.stdout == ""

0 comments on commit 323a64b

Please sign in to comment.