Coverage for tests/test_app2/management/commands/groups.py: 83%
34 statements
« prev ^ index » next coverage.py v7.3.4, created at 2024-01-20 18:02 +0000
« prev ^ index » next coverage.py v7.3.4, created at 2024-01-20 18:02 +0000
1import typing as t
3from django.conf import settings
4from django.utils.translation import gettext_lazy as _
5from typer import Argument, Option
7from django_typer import command, group, initialize, types
8from django_typer.tests.test_app.management.commands.groups import (
9 Command as GroupsCommand,
10)
13class Command(GroupsCommand, epilog="Overridden from test_app."):
14 help = "Test groups command inheritance."
16 precision = 2
17 verbosity = 1
19 @initialize()
20 def init(self, verbosity: types.Verbosity = verbosity):
21 """
22 Initialize the command.
23 """
24 assert self.__class__ is Command
25 self.verbosity = verbosity
27 @command()
28 def echo(
29 self,
30 message: str,
31 echoes: t.Annotated[
32 int, Argument(help="Number of times to echo the message.")
33 ] = 1,
34 ):
35 """
36 Echo the given message the given number of times.
37 """
38 assert self.__class__ is Command
39 return " ".join([message] * echoes)
41 # test override base class command and remove arguments
42 @GroupsCommand.case.command()
43 def upper(self):
44 return super().upper(0, None)
46 @GroupsCommand.string.command()
47 def strip(self):
48 """Strip white space off the ends of the string"""
49 return self.op_string.strip()
51 @group()
52 def setting(
53 self, setting: t.Annotated[str, Argument(help=_("The setting variable name."))]
54 ):
55 """
56 Get or set Django settings.
57 """
58 assert self.__class__ is Command
59 self.setting = setting
61 @setting.command()
62 def print(
63 self,
64 safe: t.Annotated[bool, Option(help=_("Do not assume the setting exists."))],
65 ):
66 """
67 Print the setting value.
68 """
69 assert self.__class__ is Command
70 if safe:
71 return getattr(settings, self.setting, None)
72 return getattr(settings, self.setting)