Skip to content

Commit

Permalink
more tests for coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
bckohan committed Jan 7, 2025
1 parent 26a36e2 commit d9c2057
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
6 changes: 2 additions & 4 deletions django_typer/management/commands/shellcompletion.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,7 @@ def source_vars(self) -> t.Dict[str, t.Any]:
else "--no-color"
if self.command.force_color
else "",
"fallback": (
f" --fallback {self.command.fallback.__module__}."
f"{self.command.fallback.__name__}"
)
"fallback": f" --fallback {self.command.fallback_import}"
if self.command.fallback
else "",
"is_installed": not isinstance(self.command.manage_script, Path),
Expand Down Expand Up @@ -555,6 +552,7 @@ def install(
"The name of the template to use for the shell completion script."
),
)
# todo - add template name completer - see django-render-static
),
] = None,
):
Expand Down
14 changes: 12 additions & 2 deletions tests/shellcompletion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@

from django.test import TestCase
from django_typer.management import get_command
from django_typer.management.commands.shellcompletion import Command as ShellCompletion
from django_typer.management.commands.shellcompletion import (
Command as ShellCompletion,
DjangoTyperShellCompleter,
)
from ..utils import rich_installed

default_shell = None
Expand Down Expand Up @@ -72,7 +75,14 @@ class _CompleteTestCase:

@cached_property
def command(self) -> ShellCompletion:
return get_command("shellcompletion", ShellCompletion)
cmd = get_command("shellcompletion", ShellCompletion)
cmd.init(shell=self.shell)
return cmd

def get_completer(self, **kwargs) -> DjangoTyperShellCompleter:
return self.command.shell_class(
**{"prog_name": self.manage_script, "command": self.command, **kwargs}
)

def setUp(self):
self.remove()
Expand Down
17 changes: 17 additions & 0 deletions tests/shellcompletion/test_bash.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,20 @@ def test_no_bashrc_file(self):
finally:
if bashrc:
(Path.home() / ".bashrc").write_text(bashrc)

def test_source_template(self):
self.assertEqual(
(
Path(__file__).parent.parent.parent
/ "django_typer/templates/shell_complete/bash.sh"
).read_text(),
self.get_completer().source_template,
)

self.assertEqual(
(
Path(__file__).parent.parent.parent
/ "django_typer/templates/shell_complete/zsh.sh"
).read_text(),
self.get_completer(template="shell_complete/zsh.sh").source_template,
)

0 comments on commit d9c2057

Please sign in to comment.