diff options
| author | Claude Paroz <claude@2xlibre.net> | 2018-05-21 11:32:51 +0200 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2018-06-06 19:17:57 +0200 |
| commit | 33b5313d7c0869d6268fa8d550d20eaa172bdfb1 (patch) | |
| tree | 8a7e493e676dde8f5fc41c2332d3a250605db7a2 /tests | |
| parent | 38bdac4752cd8b27b786fc4aec5516d785f4b6ba (diff) | |
[2.1.x] Fixed #29301 -- Added custom help formatter to BaseCommand class
This partially reverts c3055242c81812278ebdc93dd109f30d2cbd1610.
Thanks Adam Johnson and Carlton Gibson for the reviews.
Backport of ce3351b9508896afdf87d11bd64fd6b5ad928228 from master.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/user_commands/management/commands/common_args.py | 16 | ||||
| -rw-r--r-- | tests/user_commands/tests.py | 5 |
2 files changed, 21 insertions, 0 deletions
diff --git a/tests/user_commands/management/commands/common_args.py b/tests/user_commands/management/commands/common_args.py new file mode 100644 index 0000000000..d7b288a267 --- /dev/null +++ b/tests/user_commands/management/commands/common_args.py @@ -0,0 +1,16 @@ +from argparse import ArgumentError + +from django.core.management.base import BaseCommand, CommandError + + +class Command(BaseCommand): + def add_arguments(self, parser): + try: + parser.add_argument('--version', action='version', version='A.B.C') + except ArgumentError: + pass + else: + raise CommandError('--version argument does no yet exist') + + def handle(self, *args, **options): + return 'Detected that --version already exists' diff --git a/tests/user_commands/tests.py b/tests/user_commands/tests.py index 92263f58d6..e90d29bb0f 100644 --- a/tests/user_commands/tests.py +++ b/tests/user_commands/tests.py @@ -205,6 +205,11 @@ class CommandTests(SimpleTestCase): self.assertIn('need_me', out.getvalue()) self.assertIn('needme2', out.getvalue()) + def test_command_add_arguments_after_common_arguments(self): + out = StringIO() + management.call_command('common_args', stdout=out) + self.assertIn('Detected that --version already exists', out.getvalue()) + def test_subparser(self): out = StringIO() management.call_command('subparser', 'foo', 12, stdout=out) |
