Skip to content

Commit 8d7e27c

Browse files
committed
fix tests for coverage
1 parent f81d200 commit 8d7e27c

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

django_typer/tests/apps/test_app/management/commands/completion.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,18 @@ def handle(
8181
),
8282
),
8383
] = [],
84+
command_first: Annotated[
85+
t.List[str],
86+
typer.Option(
87+
"--cmd-first",
88+
help=_("A list of commands by import path or name."),
89+
shell_complete=completers.chain(
90+
completers.complete_import_path,
91+
completers.commands(allow_duplicates=True),
92+
first_match=True,
93+
),
94+
),
95+
] = [],
8496
):
8597
assert self.__class__ is Command
8698
for app in django_apps:

django_typer/tests/test_parser_completers.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,21 @@ def test_app_label_parser_idempotency(self):
107107
def test_app_label_parser_completers(self):
108108
from django.apps import apps
109109

110+
result = StringIO()
111+
with contextlib.redirect_stdout(result):
112+
call_command("shellcompletion", "complete", "completion ")
113+
result = result.getvalue()
114+
self.assertTrue("test_app" in result)
115+
self.assertTrue("django_typer_tests_apps_util" in result)
116+
self.assertTrue("django_typer" in result)
117+
self.assertTrue("django_typer_tests_apps_examples_polls" in result)
118+
self.assertTrue("admin" in result)
119+
self.assertTrue("auth" in result)
120+
self.assertTrue("contenttypes" in result)
121+
self.assertTrue("sessions" in result)
122+
self.assertTrue("messages" in result)
123+
self.assertTrue("staticfiles" in result)
124+
110125
result = StringIO()
111126
with contextlib.redirect_stdout(result):
112127
call_command(
@@ -1353,3 +1368,15 @@ def test_chain_and_commands_completer(self):
13531368
self.assertTrue("dj_params2" in result)
13541369
self.assertTrue("dj_params3" in result)
13551370
self.assertTrue("dj_params4" in result)
1371+
1372+
result = run_command(
1373+
"shellcompletion", "complete", "completion --cmd-first dj"
1374+
)[0].strip()
1375+
1376+
self.assertTrue("django" in result)
1377+
self.assertTrue("django_typer" in result)
1378+
1379+
self.assertFalse("dj_params1" in result)
1380+
self.assertFalse("dj_params2" in result)
1381+
self.assertFalse("dj_params3" in result)
1382+
self.assertFalse("dj_params4" in result)

doc/source/architecture.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ following:
2727
commands they plugin to directly.
2828
* The group/command tree on instantiated commands must be walkable using attributes from the
2929
command instance itself to support subgroup name overloads.
30-
* Common django options should appear on a common initializer for compound commands with multiple
31-
groups or commands and should appear directly on the command for non-compound commands.
30+
* Common django options should appear on the initializer for compound commands and should be
31+
directly on the command for non-compound commands.
3232

3333
During all of this, the correct self must be passed if the function accepts it, but all of the
3434
registered functions are not registered as methods because they enter the Typer_ app tree as

0 commit comments

Comments
 (0)