From b667ac24ead73300c49e265201b6c0b913ee36a3 Mon Sep 17 00:00:00 2001 From: Jan Szoja Date: Sun, 25 Jul 2021 00:16:00 +0100 Subject: Fixed #25264 -- Allowed suppressing base command options in --help output. This also suppresses -verbosity and --trackback options in the runserver's help. --- .../commands/suppress_base_options_command.py | 24 ++++++++++++++ tests/admin_scripts/tests.py | 37 ++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 tests/admin_scripts/management/commands/suppress_base_options_command.py (limited to 'tests/admin_scripts') diff --git a/tests/admin_scripts/management/commands/suppress_base_options_command.py b/tests/admin_scripts/management/commands/suppress_base_options_command.py new file mode 100644 index 0000000000..769ef3178c --- /dev/null +++ b/tests/admin_scripts/management/commands/suppress_base_options_command.py @@ -0,0 +1,24 @@ +from django.core.management import BaseCommand + + +class Command(BaseCommand): + + help = 'Test suppress base options command.' + requires_system_checks = [] + suppressed_base_arguments = { + '-v', + '--traceback', + '--settings', + '--pythonpath', + '--no-color', + '--force-color', + '--version', + 'file', + } + + def add_arguments(self, parser): + super().add_arguments(parser) + self.add_base_argument(parser, 'file', nargs='?', help='input file') + + def handle(self, *labels, **options): + print('EXECUTE:SuppressBaseOptionsCommand options=%s' % sorted(options.items())) diff --git a/tests/admin_scripts/tests.py b/tests/admin_scripts/tests.py index e5216e93e9..a3ceb8ad75 100644 --- a/tests/admin_scripts/tests.py +++ b/tests/admin_scripts/tests.py @@ -1381,6 +1381,15 @@ class ManageRunserverEmptyAllowedHosts(AdminScriptTestCase): self.assertOutput(err, 'CommandError: You must set settings.ALLOWED_HOSTS if DEBUG is False.') +class ManageRunserverHelpOutput(AdminScriptTestCase): + def test_suppressed_options(self): + """runserver doesn't support --verbosity and --trackback options.""" + out, err = self.run_manage(['runserver', '--help']) + self.assertNotInOutput(out, '--verbosity') + self.assertNotInOutput(out, '--trackback') + self.assertOutput(out, '--settings') + + class ManageTestserver(SimpleTestCase): @mock.patch.object(TestserverCommand, 'handle', return_value='') @@ -1847,6 +1856,34 @@ class CommandTypes(AdminScriptTestCase): "('settings', None), ('traceback', False), ('verbosity', 1)]" ) + def test_suppress_base_options_command_help(self): + args = ['suppress_base_options_command', '--help'] + out, err = self.run_manage(args) + self.assertNoOutput(err) + self.assertOutput(out, 'Test suppress base options command.') + self.assertNotInOutput(out, 'input file') + self.assertOutput(out, '-h, --help') + self.assertNotInOutput(out, '--version') + self.assertNotInOutput(out, '--verbosity') + self.assertNotInOutput(out, '-v {0,1,2,3}') + self.assertNotInOutput(out, '--settings') + self.assertNotInOutput(out, '--pythonpath') + self.assertNotInOutput(out, '--traceback') + self.assertNotInOutput(out, '--no-color') + self.assertNotInOutput(out, '--force-color') + + def test_suppress_base_options_command_defaults(self): + args = ['suppress_base_options_command'] + out, err = self.run_manage(args) + self.assertNoOutput(err) + self.assertOutput( + out, + "EXECUTE:SuppressBaseOptionsCommand options=[('file', None), " + "('force_color', False), ('no_color', False), " + "('pythonpath', None), ('settings', None), " + "('traceback', False), ('verbosity', 1)]" + ) + class Discovery(SimpleTestCase): -- cgit v1.3