Ticket #15675: ticket15675-4.patch

File ticket15675-4.patch, 6.2 KB (added by msiedlarek, 14 years ago)

Fourth version of patch - merged with r16022 trunk and added AUTHORS entry

  • AUTHORS

    diff --git a/AUTHORS b/AUTHORS
    index a19e49b..62c4aea 100644
    a b answer newbie questions, and generally made Django that much better:  
    528528    Gasper Zejn <zejn@kiberpipa.org>
    529529    Jarek Zgoda <jarek.zgoda@gmail.com>
    530530    Cheng Zhang
     531    Mikołaj Siedlarek <mikolaj.siedlarek@gmail.com>
    531532
    532533A big THANK YOU goes to:
    533534
  • django/core/management/commands/test.py

    diff --git a/django/core/management/commands/test.py b/django/core/management/commands/test.py
    index 1be1e1e..0e265ca 100644
    a b  
    11from django.core.management.base import BaseCommand
     2from django.test.utils import get_runner
     3from django.conf import settings
    24from optparse import make_option
    35import sys
    46
     7TestRunner = get_runner(settings)
     8
    59class Command(BaseCommand):
    610    option_list = BaseCommand.option_list + (
    711        make_option('--noinput', action='store_false', dest='interactive', default=True,
    812            help='Tells Django to NOT prompt the user for input of any kind.'),
    913        make_option('--failfast', action='store_true', dest='failfast', default=False,
    1014            help='Tells Django to stop running the test suite after first failed test.')
    11     )
     15    ) + getattr(TestRunner, 'option_list', ())
    1216    help = 'Runs the test suite for the specified applications, or the entire site if no apps are specified.'
    1317    args = '[appname ...]'
    1418
    1519    requires_model_validation = False
    1620
    1721    def handle(self, *test_labels, **options):
    18         from django.conf import settings
    19         from django.test.utils import get_runner
    20 
    21         verbosity = int(options.get('verbosity', 1))
    22         interactive = options.get('interactive', True)
    23         failfast = options.get('failfast', False)
    24         TestRunner = get_runner(settings)
     22        options['verbosity'] = int(options.get('verbosity', 1))
     23        options.setdefault('interactive', True)
     24        options.setdefault('failfast', False)
    2525
    26         test_runner = TestRunner(verbosity=verbosity, interactive=interactive, failfast=failfast)
     26        test_runner = TestRunner(**options)
    2727        failures = test_runner.run_tests(test_labels)
    2828
    2929        if failures:
  • docs/topics/testing.txt

    diff --git a/docs/topics/testing.txt b/docs/topics/testing.txt
    index 64e4707..d408d00 100644
    a b set up, execute and tear down the test suite.  
    16451645    write your own test runner, ensure accept and handle the ``**kwargs``
    16461646    parameter.
    16471647
     1648    .. versionadded:: development
     1649
     1650    Your test runner may define some command-line options which will be fed
     1651    into ``test`` management command's ``OptionParser``. If you need such
     1652    functionality, see the ``option_list`` attribute. Options you declare
     1653    will be provided to your test runner's constructor as additional keyword
     1654    arguments.
     1655
     1656Attributes
     1657~~~~~~~~~~
     1658
     1659.. versionadded:: development
     1660
     1661.. attribute:: DjangoTestSuiteRunner.option_list
     1662
     1663    This is the tuple of ``optparse`` options which will be fed into the management
     1664    command's ``OptionParser`` for parsing arguments.
     1665
     1666Methods
     1667~~~~~~~
     1668
    16481669.. method:: DjangoTestSuiteRunner.run_tests(test_labels, extra_tests=None, **kwargs)
    16491670
    16501671    Run the test suite.
  • tests/regressiontests/test_runner/tests.py

    diff --git a/tests/regressiontests/test_runner/tests.py b/tests/regressiontests/test_runner/tests.py
    index b3d6475..6ec2deb 100644
    a b Tests for django test runner  
    33"""
    44import StringIO
    55import warnings
     6from optparse import make_option
    67
    78from django.core.exceptions import ImproperlyConfigured
    89from django.test import simple
    910from django.test.utils import get_warnings_state, restore_warnings_state
    1011from django.utils import unittest
    1112
     13from regressiontests.admin_scripts.tests import AdminScriptTestCase
    1214
    1315class DjangoTestRunnerTests(unittest.TestCase):
    1416    def setUp(self):
    class DependencyOrderingTests(unittest.TestCase):  
    128130
    129131        self.assertRaises(ImproperlyConfigured, simple.dependency_ordered, raw, dependencies=dependencies)
    130132
     133class CustomOptionsTestRunner(simple.DjangoTestSuiteRunner):
     134    option_list = (
     135        make_option('--option_a','-a', action='store', dest='option_a', default='1'),
     136        make_option('--option_b','-b', action='store', dest='option_b', default='2'),
     137        make_option('--option_c','-c', action='store', dest='option_c', default='3'),
     138    )
     139
     140    def __init__(self, verbosity=1, interactive=True, failfast=True, option_a=None, option_b=None, option_c=None, **kwargs):
     141        super(CustomOptionsTestRunner, self).__init__(verbosity=verbosity, interactive=interactive,
     142                                                      failfast=failfast)
     143        self.option_a = option_a
     144        self.option_b = option_b
     145        self.option_c = option_c
     146
     147    def run_tests(self, test_labels, extra_tests=None, **kwargs):
     148        print "%s:%s:%s" % (self.option_a, self.option_b, self.option_c)
     149
     150class CustomTestRunnerOptionsTests(AdminScriptTestCase):
     151
     152    def setUp(self):
     153        settings = {
     154            'TEST_RUNNER': '\'regressiontests.test_runner.tests.CustomOptionsTestRunner\'',
     155        }
     156        self.write_settings('settings.py', sdict=settings)
     157
     158    def tearDown(self):
     159        self.remove_settings('settings.py')
     160
     161    def test_default_options(self): 
     162        args = ['test', '--settings=settings']
     163        out, err = self.run_django_admin(args)
     164        self.assertNoOutput(err)
     165        self.assertOutput(out, '1:2:3')
     166
     167    def test_default_and_given_options(self): 
     168        args = ['test', '--settings=settings', '--option_b=foo']
     169        out, err = self.run_django_admin(args)
     170        self.assertNoOutput(err)
     171        self.assertOutput(out, '1:foo:3')
     172
     173    def test_option_name_and_value_separated(self): 
     174        args = ['test', '--settings=settings', '--option_b', 'foo']
     175        out, err = self.run_django_admin(args)
     176        self.assertNoOutput(err)
     177        self.assertOutput(out, '1:foo:3')
     178
     179    def test_all_options_given(self): 
     180        args = ['test', '--settings=settings', '--option_a=bar', '--option_b=foo', '--option_c=31337']
     181        out, err = self.run_django_admin(args)
     182        self.assertNoOutput(err)
     183        self.assertOutput(out, 'bar:foo:31337')
     184
Back to Top