Opened 14 years ago

Closed 13 years ago

#14503 closed Cleanup/optimization (fixed)

Unify test for exception+message value assertion method

Reported by: Ramiro Morales Owned by: nobody
Component: Testing framework Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Currently we have a few copies of methods with similar tasks:

$ ack def\ assertRaises --python
[...]
tests/regressiontests/forms/fields.py
52:    def assertRaisesErrorWithMessage(self, error, message, callable, *args, **kwargs):

tests/regressiontests/forms/localflavor/be.py
11:    def assertRaisesErrorWithMessage(self, error, message, callable, *args, **kwargs):

tests/regressiontests/utils/datastructures.py
11:    def assertRaisesErrorWithMessage(self, error, message, callable,

tests/regressiontests/queries/tests.py
24:    def assertRaisesMessage(self, exc, msg, func, *args, **kwargs):

tests/regressiontests/fixtures_regress/tests.py
340:    def assertRaisesMessage(self, exc, msg, func, *args, **kwargs):

tests/regressiontests/urlpatterns_reverse/tests.py
136:    def assertRaisesErrorWithMessage(self, error, message, callable,

tests/regressiontests/custom_columns_regress/tests.py
12:    def assertRaisesMessage(self, exc, msg, func, *args, **kwargs):

tests/regressiontests/admin_validation/tests.py
21:    def assertRaisesMessage(self, exc, msg, func, *args, **kwargs):

tests/regressiontests/file_storage/tests.py
35:    def assertRaisesErrorWithMessage(self, error, message, callable,

And some of them even run the callable twice:

    def assertRaisesErrorWithMessage(self, error, message, callable, *args, **kwargs):
        self.assertRaises(error, callable, *args, **kwargs)
        try:
            callable(*args, **kwargs)
        except error, e:
            self.assertEqual(message, str(e))

Attachments (6)

14503-assertraisesmessage-unification-simple.diff (73.4 KB ) - added by Ramiro Morales 14 years ago.
Simple unification using a new django.test.{Transaction,}TestCase() method
14503-replacement-with-assertraisesregexp.diff (82.7 KB ) - added by Ramiro Morales 14 years ago.
Different strategy as sugested by Alex: Migrate to use assertRaisesRegexp() unittest2.TestCase method
14503-replacement-with-assertraisesregexp.2.diff (82.4 KB ) - added by Ramiro Morales 14 years ago.
Same as previous one, moving inheritance of some non-DB tests from django.test.TestCase back to django.utils.unittest.TestCase
14503-assertraisesregex-r14981.diff (79.7 KB ) - added by Ramiro Morales 14 years ago.
Updated patch for trunk as of now
14503-with-mixin.diff (70.1 KB ) - added by Ramiro Morales 13 years ago.
Uupdated patch
14503-with-testcase-class.diff (70.4 KB ) - added by Ramiro Morales 13 years ago.
Similar patch but using a thin subclass of django.utuls.unitest.TestCase

Download all attachments as: .zip

Change History (9)

by Ramiro Morales, 14 years ago

Simple unification using a new django.test.{Transaction,}TestCase() method

by Ramiro Morales, 14 years ago

Different strategy as sugested by Alex: Migrate to use assertRaisesRegexp() unittest2.TestCase method

by Ramiro Morales, 14 years ago

Same as previous one, moving inheritance of some non-DB tests from django.test.TestCase back to django.utils.unittest.TestCase

by Ramiro Morales, 14 years ago

Updated patch for trunk as of now

comment:1 by Ramiro Morales, 14 years ago

Triage Stage: UnreviewedAccepted

comment:2 by Julien Phalip, 13 years ago

Severity: Normal
Type: Cleanup/optimization

by Ramiro Morales, 13 years ago

Attachment: 14503-with-mixin.diff added

Uupdated patch

by Ramiro Morales, 13 years ago

Similar patch but using a thin subclass of django.utuls.unitest.TestCase

comment:3 by Ramiro Morales, 13 years ago

Resolution: fixed
Status: newclosed

In [16610]:

Fixed #14503 -- Unified multiple implementations of test cases assert* methods that verify a given exception is raised by a callable throughout the Django test suite.

Replaced them with a new assertRaisesMessage method of a new SimpleTestCase, a lightweight subclass of unittest.TestCase. Both are also available for usage in user tests.

Note: See TracTickets for help on using tickets.
Back to Top