diff options
Diffstat (limited to 'tests/admin_scripts')
4 files changed, 19 insertions, 26 deletions
diff --git a/tests/admin_scripts/management/commands/base_command.py b/tests/admin_scripts/management/commands/base_command.py index c313235ead..14e9152d9d 100644 --- a/tests/admin_scripts/management/commands/base_command.py +++ b/tests/admin_scripts/management/commands/base_command.py @@ -1,17 +1,15 @@ -from optparse import make_option - from django.core.management.base import BaseCommand class Command(BaseCommand): - option_list = BaseCommand.option_list + ( - make_option('--option_a', '-a', action='store', dest='option_a', default='1'), - make_option('--option_b', '-b', action='store', dest='option_b', default='2'), - make_option('--option_c', '-c', action='store', dest='option_c', default='3'), - ) help = 'Test basic commands' requires_system_checks = False - args = '[labels ...]' + + def add_arguments(self, parser): + parser.add_argument('args', nargs='*') + parser.add_argument('--option_a', '-a', default='1') + parser.add_argument('--option_b', '-b', default='2') + parser.add_argument('--option_c', '-c', default='3') def handle(self, *labels, **options): print('EXECUTE:BaseCommand labels=%s, options=%s' % (labels, sorted(options.items()))) diff --git a/tests/admin_scripts/management/commands/custom_startproject.py b/tests/admin_scripts/management/commands/custom_startproject.py index 8144b5b69c..0d9c7d339e 100644 --- a/tests/admin_scripts/management/commands/custom_startproject.py +++ b/tests/admin_scripts/management/commands/custom_startproject.py @@ -1,11 +1,8 @@ -from optparse import make_option - from django.core.management.commands.startproject import Command as BaseCommand class Command(BaseCommand): - option_list = BaseCommand.option_list + ( - make_option('--extra', - action='store', dest='extra', - help='An arbitrary extra value passed to the context'), - ) + def add_arguments(self, parser): + super(Command, self).add_arguments(parser) + parser.add_argument('--extra', + help='An arbitrary extra value passed to the context') diff --git a/tests/admin_scripts/management/commands/label_command.py b/tests/admin_scripts/management/commands/label_command.py index 9bba413ff3..5bffeb3ae2 100644 --- a/tests/admin_scripts/management/commands/label_command.py +++ b/tests/admin_scripts/management/commands/label_command.py @@ -4,7 +4,6 @@ from django.core.management.base import LabelCommand class Command(LabelCommand): help = "Test Label-based commands" requires_system_checks = False - args = '<label>' def handle_label(self, label, **options): print('EXECUTE:LabelCommand label=%s, options=%s' % (label, sorted(options.items()))) diff --git a/tests/admin_scripts/tests.py b/tests/admin_scripts/tests.py index 75c272cf71..48414272ac 100644 --- a/tests/admin_scripts/tests.py +++ b/tests/admin_scripts/tests.py @@ -28,7 +28,6 @@ from django.utils._os import npath, upath from django.utils.six import StringIO from django.test import LiveServerTestCase, TestCase, override_settings from django.test.runner import DiscoverRunner -from django.test.utils import str_prefix test_dir = os.path.realpath(os.path.join(os.environ['DJANGO_TEST_TEMP_DIR'], 'test_project')) @@ -1378,7 +1377,8 @@ class CommandTypes(AdminScriptTestCase): args = ['sqlall', '--help'] out, err = self.run_manage(args) self.assertNoOutput(err) - self.assertOutput(out, "Prints the CREATE TABLE, custom SQL and CREATE INDEX SQL statements for the given model module name(s).") + self.assertOutput(out, "Prints the CREATE TABLE, custom SQL and CREATE INDEX SQL statements for the\ngiven model module name(s).") + self.assertEqual(out.count('optional arguments'), 1) def test_no_color(self): "--no-color prevent colorization of the output" @@ -1420,12 +1420,11 @@ class CommandTypes(AdminScriptTestCase): def _test_base_command(self, args, labels, option_a="'1'", option_b="'2'"): out, err = self.run_manage(args) - expected_out = str_prefix( - ("EXECUTE:BaseCommand labels=%%s, " - "options=[('no_color', False), ('option_a', %%s), ('option_b', %%s), " - "('option_c', '3'), ('pythonpath', None), ('settings', None), " - "('traceback', None), ('verbosity', %(_)s'1')]") - ) % (labels, option_a, option_b) + expected_out = ( + "EXECUTE:BaseCommand labels=%s, " + "options=[('no_color', False), ('option_a', %s), ('option_b', %s), " + "('option_c', '3'), ('pythonpath', None), ('settings', None), " + "('traceback', False), ('verbosity', 1)]") % (labels, option_a, option_b) self.assertNoOutput(err) self.assertOutput(out, expected_out) @@ -1629,7 +1628,7 @@ class ArgumentOrder(AdminScriptTestCase): def _test(self, args, option_b="'2'"): out, err = self.run_manage(args) self.assertNoOutput(err) - self.assertOutput(out, str_prefix("EXECUTE:BaseCommand labels=('testlabel',), options=[('no_color', False), ('option_a', 'x'), ('option_b', %%s), ('option_c', '3'), ('pythonpath', None), ('settings', 'alternate_settings'), ('traceback', None), ('verbosity', %(_)s'1')]") % option_b) + self.assertOutput(out, "EXECUTE:BaseCommand labels=('testlabel',), options=[('no_color', False), ('option_a', 'x'), ('option_b', %s), ('option_c', '3'), ('pythonpath', None), ('settings', 'alternate_settings'), ('traceback', False), ('verbosity', 1)]" % option_b) @override_settings(ROOT_URLCONF='admin_scripts.urls') @@ -1646,7 +1645,7 @@ class StartProject(LiveServerTestCase, AdminScriptTestCase): "Make sure passing the wrong kinds of arguments raises a CommandError" out, err = self.run_django_admin(['startproject']) self.assertNoOutput(out) - self.assertOutput(err, "you must provide a project name") + self.assertOutput(err, "You must provide a project name.") def test_simple_project(self): "Make sure the startproject management command creates a project" |
