Coverage for tests/test_app/management/commands/completion.py: 63%

25 statements  

« prev     ^ index     » next       coverage.py v7.3.4, created at 2024-01-20 18:02 +0000

1import json 

2import typing as t 

3from functools import partial 

4 

5import typer 

6from django.apps import AppConfig, apps 

7from django.utils.translation import gettext_lazy as _ 

8 

9from django_typer import TyperCommand 

10 

11 

12def parse_app_label(label: t.Union[str, AppConfig]): 

13 if label == "django_apps": 13 ↛ 14line 13 didn't jump to line 14, because the condition on line 13 was never true

14 import ipdb 

15 

16 ipdb.set_trace() 

17 if isinstance(label, AppConfig): 17 ↛ 18line 17 didn't jump to line 18, because the condition on line 17 was never true

18 return label 

19 return apps.get_app_config(label) 

20 

21 

22def complete_app_label(ctx: typer.Context, incomplete: str): 

23 names = ctx.params.get("django_apps") or [] 

24 for name in [app.label for app in apps.get_app_configs()]: 

25 if name.startswith(incomplete) and name not in names: 

26 yield name 

27 

28 

29class Command(TyperCommand): 

30 def handle( 

31 self, 

32 django_apps: t.Annotated[ 

33 t.List[AppConfig], 

34 typer.Argument( 

35 parser=parse_app_label, 

36 help=_("One or more application labels."), 

37 autocompletion=complete_app_label, 

38 ), 

39 ], 

40 ): 

41 assert self.__class__ == Command 

42 for app in django_apps: 

43 assert isinstance(app, AppConfig) 

44 return json.dumps([app.label for app in django_apps])