Skip to content

Commit

Permalink
add fallback import path completer and fallback test to completion in…
Browse files Browse the repository at this point in the history
…tegration tests
  • Loading branch information
bckohan committed Jan 7, 2025
1 parent 69ee3fa commit 14c2a33
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
8 changes: 5 additions & 3 deletions django_typer/management/commands/shellcompletion.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
from typer import Argument, Option
from typer.main import get_command as get_typer_command

from django_typer.completers import these_strings
from django_typer.completers import complete_import_path, these_strings
from django_typer.management import TyperCommand, command, get_command, initialize
from django_typer.types import COMMON_PANEL
from django_typer.utils import get_usage_script, get_win_shell
Expand Down Expand Up @@ -538,7 +538,8 @@ def install(
"The python import path to a fallback complete function to use when "
"the completion command is not a TyperCommand."
),
)
),
shell_complete=complete_import_path,
),
] = None,
template: t.Annotated[
Expand Down Expand Up @@ -676,7 +677,8 @@ def complete(
"the completion command is not a TyperCommand. By default, the builtin "
"django autocomplete function is used."
),
)
),
shell_complete=complete_import_path,
),
] = None,
):
Expand Down
10 changes: 9 additions & 1 deletion tests/shellcompletion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def verify_install(self, script=None):
def verify_remove(self, script=None):
pass

def install(self, script=None, force_color=False, no_color=None):
def install(self, script=None, force_color=False, no_color=None, fallback=None):
if not script:
script = self.manage_script
init_kwargs = {"force_color": force_color, "no_color": no_color}
Expand All @@ -107,6 +107,8 @@ def install(self, script=None, force_color=False, no_color=None):
kwargs["manage_script"] = script
if self.shell:
init_kwargs["shell"] = self.shell
if fallback:
kwargs["fallback"] = fallback
self.command.init(**init_kwargs)
self.command.install(**kwargs)
self.verify_install(script=script)
Expand Down Expand Up @@ -296,6 +298,12 @@ def test_shell_complete(self):
self.run_app_completion()
self.install()

def test_fallback(self):
self.remove()
self.install(fallback="tests.fallback.custom_fallback")
completions = self.get_completions(self.launch_script, " ")
self.assertIn("custom_fallback", completions)

@pytest.mark.rich
@pytest.mark.no_rich
def test_rich_output(self):
Expand Down

0 comments on commit 14c2a33

Please sign in to comment.