summaryrefslogtreecommitdiff
path: root/tests/user_commands
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2018-05-21 11:32:51 +0200
committerClaude Paroz <claude@2xlibre.net>2018-06-06 19:16:10 +0200
commitce3351b9508896afdf87d11bd64fd6b5ad928228 (patch)
tree2a29a1e01b4df1765c101be40ca76bb5b840d3b0 /tests/user_commands
parente9bd1a3e12df132527a8d8bea95858e856ac7be4 (diff)
Fixed #29301 -- Added custom help formatter to BaseCommand class
This partially reverts c3055242c81812278ebdc93dd109f30d2cbd1610. Thanks Adam Johnson and Carlton Gibson for the reviews.
Diffstat (limited to 'tests/user_commands')
-rw-r--r--tests/user_commands/management/commands/common_args.py16
-rw-r--r--tests/user_commands/tests.py5
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)