Ticket #14503: 14503-with-testcase-class.diff

File 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

  • django/test/__init__.py

    diff --git a/django/test/__init__.py b/django/test/__init__.py
    a b  
    33"""
    44
    55from django.test.client import Client, RequestFactory
    6 from django.test.testcases import TestCase, TransactionTestCase, skipIfDBFeature, skipUnlessDBFeature
     6from django.test.testcases import (TestCase, TransactionTestCase,
     7        skipIfDBFeature, skipUnlessDBFeature, SimpleTestCase)
    78from django.test.utils import Approximate
  • django/test/testcases.py

    diff --git a/django/test/testcases.py b/django/test/testcases.py
    a b  
    2121from django.utils.encoding import smart_str
    2222
    2323__all__ = ('DocTestRunner', 'OutputChecker', 'TestCase', 'TransactionTestCase',
    24            'skipIfDBFeature', 'skipUnlessDBFeature')
     24           'skipIfDBFeature', 'skipUnlessDBFeature', 'SimpleTestCase')
    2525
    2626normalize_long_ints = lambda s: re.sub(r'(?<![\w])(\d+)L(?![\w])', '\\1', s)
    2727normalize_decimals = lambda s: re.sub(r"Decimal\('(\d+(\.\d*)?)'\)", lambda m: "Decimal(\"%s\")" % m.groups()[0], s)
     
    235235            )
    236236        )
    237237
     238class SimpleTestCase(ut2.TestCase):
    238239
    239 class TransactionTestCase(ut2.TestCase):
     240    def assertRaisesMessage(self, expected_exception, expected_message,
     241                           callable_obj=None, *args, **kwargs):
     242        """Asserts that the message in a raised exception matches the passe value.
     243
     244        Args:
     245            expected_exception: Exception class expected to be raised.
     246            expected_message: expected error message string value.
     247            callable_obj: Function to be called.
     248            args: Extra args.
     249            kwargs: Extra kwargs.
     250        """
     251        return self.assertRaisesRegexp(expected_exception,
     252                re.escape(expected_message), callable_obj, *args, **kwargs)
     253
     254class TransactionTestCase(SimpleTestCase):
    240255    # The class we'll use for the test client self.client.
    241256    # Can be overridden in derived classes.
    242257    client_class = Client
  • tests/regressiontests/admin_validation/tests.py

    diff --git a/tests/regressiontests/admin_validation/tests.py b/tests/regressiontests/admin_validation/tests.py
    a b  
    1919    fields = ['spam']
    2020
    2121class ValidationTestCase(TestCase):
    22     def assertRaisesMessage(self, exc, msg, func, *args, **kwargs):
    23         try:
    24             func(*args, **kwargs)
    25         except Exception, e:
    26             self.assertEqual(msg, str(e))
    27             self.assertTrue(isinstance(e, exc), "Expected %s, got %s" % (exc, type(e)))
    2822
    2923    def test_readonly_and_editable(self):
    3024        class SongAdmin(admin.ModelAdmin):
  • tests/regressiontests/custom_columns_regress/tests.py

    diff --git a/tests/regressiontests/custom_columns_regress/tests.py b/tests/regressiontests/custom_columns_regress/tests.py
    a b  
    99
    1010class CustomColumnRegression(TestCase):
    1111
    12     def assertRaisesMessage(self, exc, msg, func, *args, **kwargs):
    13         try:
    14             func(*args, **kwargs)
    15         except Exception, e:
    16             self.assertEqual(msg, str(e))
    17             self.assertTrue(isinstance(e, exc), "Expected %s, got %s" % (exc, type(e)))
    18 
    1912    def setUp(self):
    2013        self.a1 = Author.objects.create(first_name='John', last_name='Smith')
    2114        self.a2 = Author.objects.create(first_name='Peter', last_name='Jones')
  • tests/regressiontests/file_storage/tests.py

    diff --git a/tests/regressiontests/file_storage/tests.py b/tests/regressiontests/file_storage/tests.py
    a b  
    2222from django.core.files.images import get_image_dimensions
    2323from django.core.files.storage import FileSystemStorage, get_storage_class
    2424from django.core.files.uploadedfile import UploadedFile
     25from django.test import SimpleTestCase
    2526from django.utils import unittest
    2627
    2728# Try to import PIL in either of the two ways it can end up installed.
     
    3637        Image = None
    3738
    3839
    39 class GetStorageClassTests(unittest.TestCase):
    40     def assertRaisesErrorWithMessage(self, error, message, callable,
    41         *args, **kwargs):
    42         self.assertRaises(error, callable, *args, **kwargs)
    43         try:
    44             callable(*args, **kwargs)
    45         except error, e:
    46             self.assertEqual(message, str(e))
     40class GetStorageClassTests(SimpleTestCase):
    4741
    4842    def test_get_filesystem_storage(self):
    4943        """
     
    5751        """
    5852        get_storage_class raises an error if the requested import don't exist.
    5953        """
    60         self.assertRaisesErrorWithMessage(
     54        self.assertRaisesMessage(
    6155            ImproperlyConfigured,
    6256            "NonExistingStorage isn't a storage module.",
    6357            get_storage_class,
     
    6761        """
    6862        get_storage_class raises an error if the requested class don't exist.
    6963        """
    70         self.assertRaisesErrorWithMessage(
     64        self.assertRaisesMessage(
    7165            ImproperlyConfigured,
    7266            'Storage module "django.core.files.storage" does not define a '\
    7367                '"NonExistingStorage" class.',
  • tests/regressiontests/fixtures_regress/tests.py

    diff --git a/tests/regressiontests/fixtures_regress/tests.py b/tests/regressiontests/fixtures_regress/tests.py
    a b  
    393393
    394394
    395395class NaturalKeyFixtureTests(TestCase):
    396     def assertRaisesMessage(self, exc, msg, func, *args, **kwargs):
    397         try:
    398             func(*args, **kwargs)
    399         except Exception, e:
    400             self.assertEqual(msg, str(e))
    401             self.assertTrue(isinstance(e, exc), "Expected %s, got %s" % (exc, type(e)))
    402396
    403397    def test_nk_deserialize(self):
    404398        """
  • tests/regressiontests/forms/tests/fields.py

    diff --git a/tests/regressiontests/forms/tests/fields.py b/tests/regressiontests/forms/tests/fields.py
    a b  
    3333
    3434from django.core.files.uploadedfile import SimpleUploadedFile
    3535from django.forms import *
    36 from django.utils.unittest import TestCase
     36from django.test import SimpleTestCase
    3737
    3838
    3939def fix_os_paths(x):
     
    6969    return decorator
    7070
    7171
    72 class FieldsTests(TestCase):
    73 
    74     def assertRaisesErrorWithMessage(self, error, message, callable, *args, **kwargs):
    75         self.assertRaises(error, callable, *args, **kwargs)
    76         try:
    77             callable(*args, **kwargs)
    78         except error, e:
    79             self.assertEqual(message, str(e))
     72class FieldsTests(SimpleTestCase):
    8073
    8174    def test_field_sets_widget_is_required(self):
    8275        self.assertTrue(Field(required=True).widget.is_required)
     
    8881        f = CharField()
    8982        self.assertEqual(u'1', f.clean(1))
    9083        self.assertEqual(u'hello', f.clean('hello'))
    91         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
    92         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
     84        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None)
     85        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '')
    9386        self.assertEqual(u'[1, 2, 3]', f.clean([1, 2, 3]))
    9487        self.assertEqual(f.max_length, None)
    9588        self.assertEqual(f.min_length, None)
     
    108101        f = CharField(max_length=10, required=False)
    109102        self.assertEqual(u'12345', f.clean('12345'))
    110103        self.assertEqual(u'1234567890', f.clean('1234567890'))
    111         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value has at most 10 characters (it has 11).']", f.clean, '1234567890a')
     104        self.assertRaisesMessage(ValidationError, "[u'Ensure this value has at most 10 characters (it has 11).']", f.clean, '1234567890a')
    112105        self.assertEqual(f.max_length, 10)
    113106        self.assertEqual(f.min_length, None)
    114107
    115108    def test_charfield_4(self):
    116109        f = CharField(min_length=10, required=False)
    117110        self.assertEqual(u'', f.clean(''))
    118         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value has at least 10 characters (it has 5).']", f.clean, '12345')
     111        self.assertRaisesMessage(ValidationError, "[u'Ensure this value has at least 10 characters (it has 5).']", f.clean, '12345')
    119112        self.assertEqual(u'1234567890', f.clean('1234567890'))
    120113        self.assertEqual(u'1234567890a', f.clean('1234567890a'))
    121114        self.assertEqual(f.max_length, None)
     
    123116
    124117    def test_charfield_5(self):
    125118        f = CharField(min_length=10, required=True)
    126         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
    127         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value has at least 10 characters (it has 5).']", f.clean, '12345')
     119        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '')
     120        self.assertRaisesMessage(ValidationError, "[u'Ensure this value has at least 10 characters (it has 5).']", f.clean, '12345')
    128121        self.assertEqual(u'1234567890', f.clean('1234567890'))
    129122        self.assertEqual(u'1234567890a', f.clean('1234567890a'))
    130123        self.assertEqual(f.max_length, None)
     
    134127
    135128    def test_integerfield_1(self):
    136129        f = IntegerField()
    137         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
    138         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
     130        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '')
     131        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None)
    139132        self.assertEqual(1, f.clean('1'))
    140133        self.assertEqual(True, isinstance(f.clean('1'), int))
    141134        self.assertEqual(23, f.clean('23'))
    142         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a whole number.']", f.clean, 'a')
     135        self.assertRaisesMessage(ValidationError, "[u'Enter a whole number.']", f.clean, 'a')
    143136        self.assertEqual(42, f.clean(42))
    144         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a whole number.']", f.clean, 3.14)
     137        self.assertRaisesMessage(ValidationError, "[u'Enter a whole number.']", f.clean, 3.14)
    145138        self.assertEqual(1, f.clean('1 '))
    146139        self.assertEqual(1, f.clean(' 1'))
    147140        self.assertEqual(1, f.clean(' 1 '))
    148         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a whole number.']", f.clean, '1a')
     141        self.assertRaisesMessage(ValidationError, "[u'Enter a whole number.']", f.clean, '1a')
    149142        self.assertEqual(f.max_value, None)
    150143        self.assertEqual(f.min_value, None)
    151144
     
    158151        self.assertEqual(1, f.clean('1'))
    159152        self.assertEqual(True, isinstance(f.clean('1'), int))
    160153        self.assertEqual(23, f.clean('23'))
    161         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a whole number.']", f.clean, 'a')
     154        self.assertRaisesMessage(ValidationError, "[u'Enter a whole number.']", f.clean, 'a')
    162155        self.assertEqual(1, f.clean('1 '))
    163156        self.assertEqual(1, f.clean(' 1'))
    164157        self.assertEqual(1, f.clean(' 1 '))
    165         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a whole number.']", f.clean, '1a')
     158        self.assertRaisesMessage(ValidationError, "[u'Enter a whole number.']", f.clean, '1a')
    166159        self.assertEqual(f.max_value, None)
    167160        self.assertEqual(f.min_value, None)
    168161
    169162    def test_integerfield_3(self):
    170163        f = IntegerField(max_value=10)
    171         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
     164        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None)
    172165        self.assertEqual(1, f.clean(1))
    173166        self.assertEqual(10, f.clean(10))
    174         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value is less than or equal to 10.']", f.clean, 11)
     167        self.assertRaisesMessage(ValidationError, "[u'Ensure this value is less than or equal to 10.']", f.clean, 11)
    175168        self.assertEqual(10, f.clean('10'))
    176         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value is less than or equal to 10.']", f.clean, '11')
     169        self.assertRaisesMessage(ValidationError, "[u'Ensure this value is less than or equal to 10.']", f.clean, '11')
    177170        self.assertEqual(f.max_value, 10)
    178171        self.assertEqual(f.min_value, None)
    179172
    180173    def test_integerfield_4(self):
    181174        f = IntegerField(min_value=10)
    182         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
    183         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value is greater than or equal to 10.']", f.clean, 1)
     175        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None)
     176        self.assertRaisesMessage(ValidationError, "[u'Ensure this value is greater than or equal to 10.']", f.clean, 1)
    184177        self.assertEqual(10, f.clean(10))
    185178        self.assertEqual(11, f.clean(11))
    186179        self.assertEqual(10, f.clean('10'))
     
    190183
    191184    def test_integerfield_5(self):
    192185        f = IntegerField(min_value=10, max_value=20)
    193         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
    194         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value is greater than or equal to 10.']", f.clean, 1)
     186        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None)
     187        self.assertRaisesMessage(ValidationError, "[u'Ensure this value is greater than or equal to 10.']", f.clean, 1)
    195188        self.assertEqual(10, f.clean(10))
    196189        self.assertEqual(11, f.clean(11))
    197190        self.assertEqual(10, f.clean('10'))
    198191        self.assertEqual(11, f.clean('11'))
    199192        self.assertEqual(20, f.clean(20))
    200         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value is less than or equal to 20.']", f.clean, 21)
     193        self.assertRaisesMessage(ValidationError, "[u'Ensure this value is less than or equal to 20.']", f.clean, 21)
    201194        self.assertEqual(f.max_value, 20)
    202195        self.assertEqual(f.min_value, 10)
    203196
     
    205198
    206199    def test_floatfield_1(self):
    207200        f = FloatField()
    208         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
    209         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
     201        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '')
     202        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None)
    210203        self.assertEqual(1.0, f.clean('1'))
    211204        self.assertEqual(True, isinstance(f.clean('1'), float))
    212205        self.assertEqual(23.0, f.clean('23'))
    213206        self.assertEqual(3.1400000000000001, f.clean('3.14'))
    214207        self.assertEqual(3.1400000000000001, f.clean(3.14))
    215208        self.assertEqual(42.0, f.clean(42))
    216         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a number.']", f.clean, 'a')
     209        self.assertRaisesMessage(ValidationError, "[u'Enter a number.']", f.clean, 'a')
    217210        self.assertEqual(1.0, f.clean('1.0 '))
    218211        self.assertEqual(1.0, f.clean(' 1.0'))
    219212        self.assertEqual(1.0, f.clean(' 1.0 '))
    220         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a number.']", f.clean, '1.0a')
     213        self.assertRaisesMessage(ValidationError, "[u'Enter a number.']", f.clean, '1.0a')
    221214        self.assertEqual(f.max_value, None)
    222215        self.assertEqual(f.min_value, None)
    223216
     
    231224
    232225    def test_floatfield_3(self):
    233226        f = FloatField(max_value=1.5, min_value=0.5)
    234         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value is less than or equal to 1.5.']", f.clean, '1.6')
    235         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value is greater than or equal to 0.5.']", f.clean, '0.4')
     227        self.assertRaisesMessage(ValidationError, "[u'Ensure this value is less than or equal to 1.5.']", f.clean, '1.6')
     228        self.assertRaisesMessage(ValidationError, "[u'Ensure this value is greater than or equal to 0.5.']", f.clean, '0.4')
    236229        self.assertEqual(1.5, f.clean('1.5'))
    237230        self.assertEqual(0.5, f.clean('0.5'))
    238231        self.assertEqual(f.max_value, 1.5)
     
    242235
    243236    def test_decimalfield_1(self):
    244237        f = DecimalField(max_digits=4, decimal_places=2)
    245         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
    246         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
     238        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '')
     239        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None)
    247240        self.assertEqual(f.clean('1'), Decimal("1"))
    248241        self.assertEqual(True, isinstance(f.clean('1'), Decimal))
    249242        self.assertEqual(f.clean('23'), Decimal("23"))
    250243        self.assertEqual(f.clean('3.14'), Decimal("3.14"))
    251244        self.assertEqual(f.clean(3.14), Decimal("3.14"))
    252245        self.assertEqual(f.clean(Decimal('3.14')), Decimal("3.14"))
    253         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a number.']", f.clean, 'NaN')
    254         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a number.']", f.clean, 'Inf')
    255         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a number.']", f.clean, '-Inf')
    256         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a number.']", f.clean, 'a')
    257         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a number.']", f.clean, u'łąść')
     246        self.assertRaisesMessage(ValidationError, "[u'Enter a number.']", f.clean, 'NaN')
     247        self.assertRaisesMessage(ValidationError, "[u'Enter a number.']", f.clean, 'Inf')
     248        self.assertRaisesMessage(ValidationError, "[u'Enter a number.']", f.clean, '-Inf')
     249        self.assertRaisesMessage(ValidationError, "[u'Enter a number.']", f.clean, 'a')
     250        self.assertRaisesMessage(ValidationError, "[u'Enter a number.']", f.clean, u'łąść')
    258251        self.assertEqual(f.clean('1.0 '), Decimal("1.0"))
    259252        self.assertEqual(f.clean(' 1.0'), Decimal("1.0"))
    260253        self.assertEqual(f.clean(' 1.0 '), Decimal("1.0"))
    261         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a number.']", f.clean, '1.0a')
    262         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure that there are no more than 4 digits in total.']", f.clean, '123.45')
    263         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure that there are no more than 2 decimal places.']", f.clean, '1.234')
    264         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure that there are no more than 2 digits before the decimal point.']", f.clean, '123.4')
     254        self.assertRaisesMessage(ValidationError, "[u'Enter a number.']", f.clean, '1.0a')
     255        self.assertRaisesMessage(ValidationError, "[u'Ensure that there are no more than 4 digits in total.']", f.clean, '123.45')
     256        self.assertRaisesMessage(ValidationError, "[u'Ensure that there are no more than 2 decimal places.']", f.clean, '1.234')
     257        self.assertRaisesMessage(ValidationError, "[u'Ensure that there are no more than 2 digits before the decimal point.']", f.clean, '123.4')
    265258        self.assertEqual(f.clean('-12.34'), Decimal("-12.34"))
    266         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure that there are no more than 4 digits in total.']", f.clean, '-123.45')
     259        self.assertRaisesMessage(ValidationError, "[u'Ensure that there are no more than 4 digits in total.']", f.clean, '-123.45')
    267260        self.assertEqual(f.clean('-.12'), Decimal("-0.12"))
    268261        self.assertEqual(f.clean('-00.12'), Decimal("-0.12"))
    269262        self.assertEqual(f.clean('-000.12'), Decimal("-0.12"))
    270         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure that there are no more than 2 decimal places.']", f.clean, '-000.123')
    271         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure that there are no more than 4 digits in total.']", f.clean, '-000.12345')
    272         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a number.']", f.clean, '--0.12')
     263        self.assertRaisesMessage(ValidationError, "[u'Ensure that there are no more than 2 decimal places.']", f.clean, '-000.123')
     264        self.assertRaisesMessage(ValidationError, "[u'Ensure that there are no more than 4 digits in total.']", f.clean, '-000.12345')
     265        self.assertRaisesMessage(ValidationError, "[u'Enter a number.']", f.clean, '--0.12')
    273266        self.assertEqual(f.max_digits, 4)
    274267        self.assertEqual(f.decimal_places, 2)
    275268        self.assertEqual(f.max_value, None)
     
    287280
    288281    def test_decimalfield_3(self):
    289282        f = DecimalField(max_digits=4, decimal_places=2, max_value=Decimal('1.5'), min_value=Decimal('0.5'))
    290         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value is less than or equal to 1.5.']", f.clean, '1.6')
    291         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value is greater than or equal to 0.5.']", f.clean, '0.4')
     283        self.assertRaisesMessage(ValidationError, "[u'Ensure this value is less than or equal to 1.5.']", f.clean, '1.6')
     284        self.assertRaisesMessage(ValidationError, "[u'Ensure this value is greater than or equal to 0.5.']", f.clean, '0.4')
    292285        self.assertEqual(f.clean('1.5'), Decimal("1.5"))
    293286        self.assertEqual(f.clean('0.5'), Decimal("0.5"))
    294287        self.assertEqual(f.clean('.5'), Decimal("0.5"))
     
    300293
    301294    def test_decimalfield_4(self):
    302295        f = DecimalField(decimal_places=2)
    303         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure that there are no more than 2 decimal places.']", f.clean, '0.00000001')
     296        self.assertRaisesMessage(ValidationError, "[u'Ensure that there are no more than 2 decimal places.']", f.clean, '0.00000001')
    304297
    305298    def test_decimalfield_5(self):
    306299        f = DecimalField(max_digits=3)
     
    310303        self.assertEqual(f.clean('0000000.100'), Decimal("0.100"))
    311304        # Only leading whole zeros "collapse" to one digit.
    312305        self.assertEqual(f.clean('000000.02'), Decimal('0.02'))
    313         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure that there are no more than 3 digits in total.']", f.clean, '000000.0002')
     306        self.assertRaisesMessage(ValidationError, "[u'Ensure that there are no more than 3 digits in total.']", f.clean, '000000.0002')
    314307        self.assertEqual(f.clean('.002'), Decimal("0.002"))
    315308
    316309    def test_decimalfield_6(self):
    317310        f = DecimalField(max_digits=2, decimal_places=2)
    318311        self.assertEqual(f.clean('.01'), Decimal(".01"))
    319         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure that there are no more than 0 digits before the decimal point.']", f.clean, '1.1')
     312        self.assertRaisesMessage(ValidationError, "[u'Ensure that there are no more than 0 digits before the decimal point.']", f.clean, '1.1')
    320313
    321314    # DateField ###################################################################
    322315
     
    334327        self.assertEqual(datetime.date(2006, 10, 25), f.clean('October 25, 2006'))
    335328        self.assertEqual(datetime.date(2006, 10, 25), f.clean('25 October 2006'))
    336329        self.assertEqual(datetime.date(2006, 10, 25), f.clean('25 October, 2006'))
    337         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid date.']", f.clean, '2006-4-31')
    338         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid date.']", f.clean, '200a-10-25')
    339         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid date.']", f.clean, '25/10/06')
    340         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
     330        self.assertRaisesMessage(ValidationError, "[u'Enter a valid date.']", f.clean, '2006-4-31')
     331        self.assertRaisesMessage(ValidationError, "[u'Enter a valid date.']", f.clean, '200a-10-25')
     332        self.assertRaisesMessage(ValidationError, "[u'Enter a valid date.']", f.clean, '25/10/06')
     333        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None)
    341334
    342335    def test_datefield_2(self):
    343336        f = DateField(required=False)
     
    351344        self.assertEqual(datetime.date(2006, 10, 25), f.clean(datetime.date(2006, 10, 25)))
    352345        self.assertEqual(datetime.date(2006, 10, 25), f.clean(datetime.datetime(2006, 10, 25, 14, 30)))
    353346        self.assertEqual(datetime.date(2006, 10, 25), f.clean('2006 10 25'))
    354         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid date.']", f.clean, '2006-10-25')
    355         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid date.']", f.clean, '10/25/2006')
    356         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid date.']", f.clean, '10/25/06')
     347        self.assertRaisesMessage(ValidationError, "[u'Enter a valid date.']", f.clean, '2006-10-25')
     348        self.assertRaisesMessage(ValidationError, "[u'Enter a valid date.']", f.clean, '10/25/2006')
     349        self.assertRaisesMessage(ValidationError, "[u'Enter a valid date.']", f.clean, '10/25/06')
    357350
    358351    def test_datefield_4(self):
    359352        # Test whitespace stripping behavior (#5714)
     
    364357        self.assertEqual(datetime.date(2006, 10, 25), f.clean(' October  25 2006 '))
    365358        self.assertEqual(datetime.date(2006, 10, 25), f.clean(' October 25, 2006 '))
    366359        self.assertEqual(datetime.date(2006, 10, 25), f.clean(' 25 October 2006 '))
    367         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid date.']", f.clean, '   ')
     360        self.assertRaisesMessage(ValidationError, "[u'Enter a valid date.']", f.clean, '   ')
    368361
    369362    # TimeField ###################################################################
    370363
     
    374367        self.assertEqual(datetime.time(14, 25, 59), f.clean(datetime.time(14, 25, 59)))
    375368        self.assertEqual(datetime.time(14, 25), f.clean('14:25'))
    376369        self.assertEqual(datetime.time(14, 25, 59), f.clean('14:25:59'))
    377         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid time.']", f.clean, 'hello')
    378         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid time.']", f.clean, '1:24 p.m.')
     370        self.assertRaisesMessage(ValidationError, "[u'Enter a valid time.']", f.clean, 'hello')
     371        self.assertRaisesMessage(ValidationError, "[u'Enter a valid time.']", f.clean, '1:24 p.m.')
    379372
    380373    def test_timefield_2(self):
    381374        f = TimeField(input_formats=['%I:%M %p'])
     
    383376        self.assertEqual(datetime.time(14, 25, 59), f.clean(datetime.time(14, 25, 59)))
    384377        self.assertEqual(datetime.time(4, 25), f.clean('4:25 AM'))
    385378        self.assertEqual(datetime.time(16, 25), f.clean('4:25 PM'))
    386         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid time.']", f.clean, '14:30:45')
     379        self.assertRaisesMessage(ValidationError, "[u'Enter a valid time.']", f.clean, '14:30:45')
    387380
    388381    def test_timefield_3(self):
    389382        f = TimeField()
    390383        # Test whitespace stripping behavior (#5714)
    391384        self.assertEqual(datetime.time(14, 25), f.clean(' 14:25 '))
    392385        self.assertEqual(datetime.time(14, 25, 59), f.clean(' 14:25:59 '))
    393         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid time.']", f.clean, '   ')
     386        self.assertRaisesMessage(ValidationError, "[u'Enter a valid time.']", f.clean, '   ')
    394387
    395388    # DateTimeField ###############################################################
    396389
     
    415408        self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30), f.clean('10/25/06 14:30:00'))
    416409        self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30), f.clean('10/25/06 14:30'))
    417410        self.assertEqual(datetime.datetime(2006, 10, 25, 0, 0), f.clean('10/25/06'))
    418         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid date/time.']", f.clean, 'hello')
    419         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid date/time.']", f.clean, '2006-10-25 4:30 p.m.')
     411        self.assertRaisesMessage(ValidationError, "[u'Enter a valid date/time.']", f.clean, 'hello')
     412        self.assertRaisesMessage(ValidationError, "[u'Enter a valid date/time.']", f.clean, '2006-10-25 4:30 p.m.')
    420413
    421414    def test_datetimefield_2(self):
    422415        f = DateTimeField(input_formats=['%Y %m %d %I:%M %p'])
     
    425418        self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30, 59), f.clean(datetime.datetime(2006, 10, 25, 14, 30, 59)))
    426419        self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30, 59, 200), f.clean(datetime.datetime(2006, 10, 25, 14, 30, 59, 200)))
    427420        self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30), f.clean('2006 10 25 2:30 PM'))
    428         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid date/time.']", f.clean, '2006-10-25 14:30:45')
     421        self.assertRaisesMessage(ValidationError, "[u'Enter a valid date/time.']", f.clean, '2006-10-25 14:30:45')
    429422
    430423    def test_datetimefield_3(self):
    431424        f = DateTimeField(required=False)
     
    444437        self.assertEqual(datetime.datetime(2006, 10, 25, 0, 0), f.clean(' 10/25/2006 '))
    445438        self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30, 45), f.clean(' 10/25/06 14:30:45 '))
    446439        self.assertEqual(datetime.datetime(2006, 10, 25, 0, 0), f.clean(' 10/25/06 '))
    447         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid date/time.']", f.clean, '   ')
     440        self.assertRaisesMessage(ValidationError, "[u'Enter a valid date/time.']", f.clean, '   ')
    448441
    449442    # RegexField ##################################################################
    450443
     
    452445        f = RegexField('^\d[A-F]\d$')
    453446        self.assertEqual(u'2A2', f.clean('2A2'))
    454447        self.assertEqual(u'3F3', f.clean('3F3'))
    455         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid value.']", f.clean, '3G3')
    456         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid value.']", f.clean, ' 2A2')
    457         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid value.']", f.clean, '2A2 ')
    458         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
     448        self.assertRaisesMessage(ValidationError, "[u'Enter a valid value.']", f.clean, '3G3')
     449        self.assertRaisesMessage(ValidationError, "[u'Enter a valid value.']", f.clean, ' 2A2')
     450        self.assertRaisesMessage(ValidationError, "[u'Enter a valid value.']", f.clean, '2A2 ')
     451        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '')
    459452
    460453    def test_regexfield_2(self):
    461454        f = RegexField('^\d[A-F]\d$', required=False)
    462455        self.assertEqual(u'2A2', f.clean('2A2'))
    463456        self.assertEqual(u'3F3', f.clean('3F3'))
    464         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid value.']", f.clean, '3G3')
     457        self.assertRaisesMessage(ValidationError, "[u'Enter a valid value.']", f.clean, '3G3')
    465458        self.assertEqual(u'', f.clean(''))
    466459
    467460    def test_regexfield_3(self):
    468461        f = RegexField(re.compile('^\d[A-F]\d$'))
    469462        self.assertEqual(u'2A2', f.clean('2A2'))
    470463        self.assertEqual(u'3F3', f.clean('3F3'))
    471         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid value.']", f.clean, '3G3')
    472         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid value.']", f.clean, ' 2A2')
    473         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid value.']", f.clean, '2A2 ')
     464        self.assertRaisesMessage(ValidationError, "[u'Enter a valid value.']", f.clean, '3G3')
     465        self.assertRaisesMessage(ValidationError, "[u'Enter a valid value.']", f.clean, ' 2A2')
     466        self.assertRaisesMessage(ValidationError, "[u'Enter a valid value.']", f.clean, '2A2 ')
    474467
    475468    def test_regexfield_4(self):
    476469        f = RegexField('^\d\d\d\d$', error_message='Enter a four-digit number.')
    477470        self.assertEqual(u'1234', f.clean('1234'))
    478         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a four-digit number.']", f.clean, '123')
    479         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a four-digit number.']", f.clean, 'abcd')
     471        self.assertRaisesMessage(ValidationError, "[u'Enter a four-digit number.']", f.clean, '123')
     472        self.assertRaisesMessage(ValidationError, "[u'Enter a four-digit number.']", f.clean, 'abcd')
    480473
    481474    def test_regexfield_5(self):
    482475        f = RegexField('^\d+$', min_length=5, max_length=10)
    483         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value has at least 5 characters (it has 3).']", f.clean, '123')
    484         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value has at least 5 characters (it has 3).', u'Enter a valid value.']", f.clean, 'abc')
     476        self.assertRaisesMessage(ValidationError, "[u'Ensure this value has at least 5 characters (it has 3).']", f.clean, '123')
     477        self.assertRaisesMessage(ValidationError, "[u'Ensure this value has at least 5 characters (it has 3).', u'Enter a valid value.']", f.clean, 'abc')
    485478        self.assertEqual(u'12345', f.clean('12345'))
    486479        self.assertEqual(u'1234567890', f.clean('1234567890'))
    487         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value has at most 10 characters (it has 11).']", f.clean, '12345678901')
    488         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid value.']", f.clean, '12345a')
     480        self.assertRaisesMessage(ValidationError, "[u'Ensure this value has at most 10 characters (it has 11).']", f.clean, '12345678901')
     481        self.assertRaisesMessage(ValidationError, "[u'Enter a valid value.']", f.clean, '12345a')
    489482
    490483    # EmailField ##################################################################
    491484
    492485    def test_emailfield_1(self):
    493486        f = EmailField()
    494         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
    495         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
     487        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '')
     488        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None)
    496489        self.assertEqual(u'person@example.com', f.clean('person@example.com'))
    497         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'foo')
    498         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'foo@')
    499         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'foo@bar')
    500         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'example@invalid-.com')
    501         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'example@-invalid.com')
    502         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'example@inv-.alid-.com')
    503         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'example@inv-.-alid.com')
     490        self.assertRaisesMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'foo')
     491        self.assertRaisesMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'foo@')
     492        self.assertRaisesMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'foo@bar')
     493        self.assertRaisesMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'example@invalid-.com')
     494        self.assertRaisesMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'example@-invalid.com')
     495        self.assertRaisesMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'example@inv-.alid-.com')
     496        self.assertRaisesMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'example@inv-.-alid.com')
    504497        self.assertEqual(u'example@valid-----hyphens.com', f.clean('example@valid-----hyphens.com'))
    505498        self.assertEqual(u'example@valid-with-hyphens.com', f.clean('example@valid-with-hyphens.com'))
    506         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'example@.com')
     499        self.assertRaisesMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'example@.com')
    507500        self.assertEqual(u'local@domain.with.idn.xyz\xe4\xf6\xfc\xdfabc.part.com', f.clean('local@domain.with.idn.xyzäöüßabc.part.com'))
    508501
    509502    def test_email_regexp_for_performance(self):
    510503        f = EmailField()
    511504        # Check for runaway regex security problem. This will take for-freeking-ever
    512505        # if the security fix isn't in place.
    513         self.assertRaisesErrorWithMessage(
     506        self.assertRaisesMessage(
    514507                ValidationError,
    515508                "[u'Enter a valid e-mail address.']",
    516509                f.clean,
     
    523516        self.assertEqual(u'', f.clean(None))
    524517        self.assertEqual(u'person@example.com', f.clean('person@example.com'))
    525518        self.assertEqual(u'example@example.com', f.clean('      example@example.com  \t   \t '))
    526         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'foo')
    527         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'foo@')
    528         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'foo@bar')
     519        self.assertRaisesMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'foo')
     520        self.assertRaisesMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'foo@')
     521        self.assertRaisesMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'foo@bar')
    529522
    530523    def test_emailfield_3(self):
    531524        f = EmailField(min_length=10, max_length=15)
    532         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value has at least 10 characters (it has 9).']", f.clean, 'a@foo.com')
     525        self.assertRaisesMessage(ValidationError, "[u'Ensure this value has at least 10 characters (it has 9).']", f.clean, 'a@foo.com')
    533526        self.assertEqual(u'alf@foo.com', f.clean('alf@foo.com'))
    534         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value has at most 15 characters (it has 20).']", f.clean, 'alf123456788@foo.com')
     527        self.assertRaisesMessage(ValidationError, "[u'Ensure this value has at most 15 characters (it has 20).']", f.clean, 'alf123456788@foo.com')
    535528
    536529    # FileField ##################################################################
    537530
    538531    def test_filefield_1(self):
    539532        f = FileField()
    540         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
    541         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '', '')
     533        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '')
     534        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '', '')
    542535        self.assertEqual('files/test1.pdf', f.clean('', 'files/test1.pdf'))
    543         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
    544         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None, '')
     536        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None)
     537        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None, '')
    545538        self.assertEqual('files/test2.pdf', f.clean(None, 'files/test2.pdf'))
    546         self.assertRaisesErrorWithMessage(ValidationError, "[u'No file was submitted. Check the encoding type on the form.']", f.clean, SimpleUploadedFile('', ''))
    547         self.assertRaisesErrorWithMessage(ValidationError, "[u'No file was submitted. Check the encoding type on the form.']", f.clean, SimpleUploadedFile('', ''), '')
     539        self.assertRaisesMessage(ValidationError, "[u'No file was submitted. Check the encoding type on the form.']", f.clean, SimpleUploadedFile('', ''))
     540        self.assertRaisesMessage(ValidationError, "[u'No file was submitted. Check the encoding type on the form.']", f.clean, SimpleUploadedFile('', ''), '')
    548541        self.assertEqual('files/test3.pdf', f.clean(None, 'files/test3.pdf'))
    549         self.assertRaisesErrorWithMessage(ValidationError, "[u'No file was submitted. Check the encoding type on the form.']", f.clean, 'some content that is not a file')
    550         self.assertRaisesErrorWithMessage(ValidationError, "[u'The submitted file is empty.']", f.clean, SimpleUploadedFile('name', None))
    551         self.assertRaisesErrorWithMessage(ValidationError, "[u'The submitted file is empty.']", f.clean, SimpleUploadedFile('name', ''))
     542        self.assertRaisesMessage(ValidationError, "[u'No file was submitted. Check the encoding type on the form.']", f.clean, 'some content that is not a file')
     543        self.assertRaisesMessage(ValidationError, "[u'The submitted file is empty.']", f.clean, SimpleUploadedFile('name', None))
     544        self.assertRaisesMessage(ValidationError, "[u'The submitted file is empty.']", f.clean, SimpleUploadedFile('name', ''))
    552545        self.assertEqual(SimpleUploadedFile, type(f.clean(SimpleUploadedFile('name', 'Some File Content'))))
    553546        self.assertEqual(SimpleUploadedFile, type(f.clean(SimpleUploadedFile('我隻氣墊船裝滿晒鱔.txt', 'मेरी मँडराने वाली नाव सर्पमीनों से भरी ह'))))
    554547        self.assertEqual(SimpleUploadedFile, type(f.clean(SimpleUploadedFile('name', 'Some File Content'), 'files/test4.pdf')))
    555548
    556549    def test_filefield_2(self):
    557550        f = FileField(max_length = 5)
    558         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this filename has at most 5 characters (it has 18).']", f.clean, SimpleUploadedFile('test_maxlength.txt', 'hello world'))
     551        self.assertRaisesMessage(ValidationError, "[u'Ensure this filename has at most 5 characters (it has 18).']", f.clean, SimpleUploadedFile('test_maxlength.txt', 'hello world'))
    559552        self.assertEqual('files/test1.pdf', f.clean('', 'files/test1.pdf'))
    560553        self.assertEqual('files/test2.pdf', f.clean(None, 'files/test2.pdf'))
    561554        self.assertEqual(SimpleUploadedFile, type(f.clean(SimpleUploadedFile('name', 'Some File Content'))))
     
    569562
    570563    def test_urlfield_1(self):
    571564        f = URLField()
    572         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
    573         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
     565        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '')
     566        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None)
    574567        self.assertEqual(u'http://localhost/', f.clean('http://localhost'))
    575568        self.assertEqual(u'http://example.com/', f.clean('http://example.com'))
    576569        self.assertEqual(u'http://example.com./', f.clean('http://example.com.'))
     
    580573        self.assertEqual(u'http://subdomain.domain.com/', f.clean('subdomain.domain.com'))
    581574        self.assertEqual(u'http://200.8.9.10/', f.clean('http://200.8.9.10'))
    582575        self.assertEqual(u'http://200.8.9.10:8000/test', f.clean('http://200.8.9.10:8000/test'))
    583         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'foo')
    584         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://')
    585         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://example')
    586         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://example.')
    587         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'com.')
    588         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, '.')
    589         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://.com')
    590         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://invalid-.com')
    591         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://-invalid.com')
    592         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://inv-.alid-.com')
    593         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://inv-.-alid.com')
     576        self.assertRaisesMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'foo')
     577        self.assertRaisesMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://')
     578        self.assertRaisesMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://example')
     579        self.assertRaisesMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://example.')
     580        self.assertRaisesMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'com.')
     581        self.assertRaisesMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, '.')
     582        self.assertRaisesMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://.com')
     583        self.assertRaisesMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://invalid-.com')
     584        self.assertRaisesMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://-invalid.com')
     585        self.assertRaisesMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://inv-.alid-.com')
     586        self.assertRaisesMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://inv-.-alid.com')
    594587        self.assertEqual(u'http://valid-----hyphens.com/', f.clean('http://valid-----hyphens.com'))
    595588        self.assertEqual(u'http://some.idn.xyz\xe4\xf6\xfc\xdfabc.domain.com:123/blah', f.clean('http://some.idn.xyzäöüßabc.domain.com:123/blah'))
    596589        self.assertEqual(u'http://www.example.com/s/http://code.djangoproject.com/ticket/13804', f.clean('www.example.com/s/http://code.djangoproject.com/ticket/13804'))
     
    598591    def test_url_regex_ticket11198(self):
    599592        f = URLField()
    600593        # hangs "forever" if catastrophic backtracking in ticket:#11198 not fixed
    601         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://%s' % ("X"*200,))
     594        self.assertRaisesMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://%s' % ("X"*200,))
    602595
    603596        # a second test, to make sure the problem is really addressed, even on
    604597        # domains that don't fail the domain label length check in the regex
    605         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://%s' % ("X"*60,))
     598        self.assertRaisesMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://%s' % ("X"*60,))
    606599
    607600    def test_urlfield_2(self):
    608601        f = URLField(required=False)
     
    610603        self.assertEqual(u'', f.clean(None))
    611604        self.assertEqual(u'http://example.com/', f.clean('http://example.com'))
    612605        self.assertEqual(u'http://www.example.com/', f.clean('http://www.example.com'))
    613         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'foo')
    614         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://')
    615         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://example')
    616         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://example.')
    617         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://.com')
     606        self.assertRaisesMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'foo')
     607        self.assertRaisesMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://')
     608        self.assertRaisesMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://example')
     609        self.assertRaisesMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://example.')
     610        self.assertRaisesMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://.com')
    618611
    619612    @verify_exists_urls(('http://www.google.com/',))
    620613    def test_urlfield_3(self):
    621614        f = URLField(verify_exists=True)
    622615        self.assertEqual(u'http://www.google.com/', f.clean('http://www.google.com'))
    623         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://example')
     616        self.assertRaisesMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://example')
    624617        self.assertRaises(ValidationError, f.clean, 'http://www.broken.djangoproject.com') # bad domain
    625618        self.assertRaises(ValidationError, f.clean, 'http://qa-dev.w3.org/link-testsuite/http.php?code=405') # Method not allowed
    626619        try:
     
    641634
    642635    def test_urlfield_5(self):
    643636        f = URLField(min_length=15, max_length=20)
    644         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value has at least 15 characters (it has 13).']", f.clean, 'http://f.com')
     637        self.assertRaisesMessage(ValidationError, "[u'Ensure this value has at least 15 characters (it has 13).']", f.clean, 'http://f.com')
    645638        self.assertEqual(u'http://example.com/', f.clean('http://example.com'))
    646         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value has at most 20 characters (it has 38).']", f.clean, 'http://abcdefghijklmnopqrstuvwxyz.com')
     639        self.assertRaisesMessage(ValidationError, "[u'Ensure this value has at most 20 characters (it has 38).']", f.clean, 'http://abcdefghijklmnopqrstuvwxyz.com')
    647640
    648641    def test_urlfield_6(self):
    649642        f = URLField(required=False)
     
    697690
    698691    def test_booleanfield_1(self):
    699692        f = BooleanField()
    700         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
    701         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
     693        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '')
     694        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None)
    702695        self.assertEqual(True, f.clean(True))
    703         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, False)
     696        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, False)
    704697        self.assertEqual(True, f.clean(1))
    705         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, 0)
     698        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, 0)
    706699        self.assertEqual(True, f.clean('Django rocks'))
    707700        self.assertEqual(True, f.clean('True'))
    708         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, 'False')
     701        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, 'False')
    709702
    710703    def test_booleanfield_2(self):
    711704        f = BooleanField(required=False)
     
    726719
    727720    def test_choicefield_1(self):
    728721        f = ChoiceField(choices=[('1', 'One'), ('2', 'Two')])
    729         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
    730         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
     722        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '')
     723        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None)
    731724        self.assertEqual(u'1', f.clean(1))
    732725        self.assertEqual(u'1', f.clean('1'))
    733         self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. 3 is not one of the available choices.']", f.clean, '3')
     726        self.assertRaisesMessage(ValidationError, "[u'Select a valid choice. 3 is not one of the available choices.']", f.clean, '3')
    734727
    735728    def test_choicefield_2(self):
    736729        f = ChoiceField(choices=[('1', 'One'), ('2', 'Two')], required=False)
     
    738731        self.assertEqual(u'', f.clean(None))
    739732        self.assertEqual(u'1', f.clean(1))
    740733        self.assertEqual(u'1', f.clean('1'))
    741         self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. 3 is not one of the available choices.']", f.clean, '3')
     734        self.assertRaisesMessage(ValidationError, "[u'Select a valid choice. 3 is not one of the available choices.']", f.clean, '3')
    742735
    743736    def test_choicefield_3(self):
    744737        f = ChoiceField(choices=[('J', 'John'), ('P', 'Paul')])
    745738        self.assertEqual(u'J', f.clean('J'))
    746         self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. John is not one of the available choices.']", f.clean, 'John')
     739        self.assertRaisesMessage(ValidationError, "[u'Select a valid choice. John is not one of the available choices.']", f.clean, 'John')
    747740
    748741    def test_choicefield_4(self):
    749742        f = ChoiceField(choices=[('Numbers', (('1', 'One'), ('2', 'Two'))), ('Letters', (('3','A'),('4','B'))), ('5','Other')])
     
    753746        self.assertEqual(u'3', f.clean('3'))
    754747        self.assertEqual(u'5', f.clean(5))
    755748        self.assertEqual(u'5', f.clean('5'))
    756         self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. 6 is not one of the available choices.']", f.clean, '6')
     749        self.assertRaisesMessage(ValidationError, "[u'Select a valid choice. 6 is not one of the available choices.']", f.clean, '6')
    757750
    758751    # TypedChoiceField ############################################################
    759752    # TypedChoiceField is just like ChoiceField, except that coerced types will
     
    762755    def test_typedchoicefield_1(self):
    763756        f = TypedChoiceField(choices=[(1, "+1"), (-1, "-1")], coerce=int)
    764757        self.assertEqual(1, f.clean('1'))
    765         self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. 2 is not one of the available choices.']", f.clean, '2')
     758        self.assertRaisesMessage(ValidationError, "[u'Select a valid choice. 2 is not one of the available choices.']", f.clean, '2')
    766759
    767760    def test_typedchoicefield_2(self):
    768761        # Different coercion, same validation.
     
    778771        # Even more weirdness: if you have a valid choice but your coercion function
    779772        # can't coerce, you'll still get a validation error. Don't do this!
    780773        f = TypedChoiceField(choices=[('A', 'A'), ('B', 'B')], coerce=int)
    781         self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. B is not one of the available choices.']", f.clean, 'B')
     774        self.assertRaisesMessage(ValidationError, "[u'Select a valid choice. B is not one of the available choices.']", f.clean, 'B')
    782775        # Required fields require values
    783         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
     776        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '')
    784777
    785778    def test_typedchoicefield_5(self):
    786779        # Non-required fields aren't required
     
    842835
    843836    def test_multiplechoicefield_1(self):
    844837        f = MultipleChoiceField(choices=[('1', 'One'), ('2', 'Two')])
    845         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
    846         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
     838        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '')
     839        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None)
    847840        self.assertEqual([u'1'], f.clean([1]))
    848841        self.assertEqual([u'1'], f.clean(['1']))
    849842        self.assertEqual([u'1', u'2'], f.clean(['1', '2']))
    850843        self.assertEqual([u'1', u'2'], f.clean([1, '2']))
    851844        self.assertEqual([u'1', u'2'], f.clean((1, '2')))
    852         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a list of values.']", f.clean, 'hello')
    853         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, [])
    854         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, ())
    855         self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. 3 is not one of the available choices.']", f.clean, ['3'])
     845        self.assertRaisesMessage(ValidationError, "[u'Enter a list of values.']", f.clean, 'hello')
     846        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, [])
     847        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, ())
     848        self.assertRaisesMessage(ValidationError, "[u'Select a valid choice. 3 is not one of the available choices.']", f.clean, ['3'])
    856849
    857850    def test_multiplechoicefield_2(self):
    858851        f = MultipleChoiceField(choices=[('1', 'One'), ('2', 'Two')], required=False)
     
    863856        self.assertEqual([u'1', u'2'], f.clean(['1', '2']))
    864857        self.assertEqual([u'1', u'2'], f.clean([1, '2']))
    865858        self.assertEqual([u'1', u'2'], f.clean((1, '2')))
    866         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a list of values.']", f.clean, 'hello')
     859        self.assertRaisesMessage(ValidationError, "[u'Enter a list of values.']", f.clean, 'hello')
    867860        self.assertEqual([], f.clean([]))
    868861        self.assertEqual([], f.clean(()))
    869         self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. 3 is not one of the available choices.']", f.clean, ['3'])
     862        self.assertRaisesMessage(ValidationError, "[u'Select a valid choice. 3 is not one of the available choices.']", f.clean, ['3'])
    870863
    871864    def test_multiplechoicefield_3(self):
    872865        f = MultipleChoiceField(choices=[('Numbers', (('1', 'One'), ('2', 'Two'))), ('Letters', (('3','A'),('4','B'))), ('5','Other')])
     
    876869        self.assertEqual([u'1', u'5'], f.clean([1, '5']))
    877870        self.assertEqual([u'1', u'5'], f.clean(['1', 5]))
    878871        self.assertEqual([u'1', u'5'], f.clean(['1', '5']))
    879         self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. 6 is not one of the available choices.']", f.clean, ['6'])
    880         self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. 6 is not one of the available choices.']", f.clean, ['1','6'])
     872        self.assertRaisesMessage(ValidationError, "[u'Select a valid choice. 6 is not one of the available choices.']", f.clean, ['6'])
     873        self.assertRaisesMessage(ValidationError, "[u'Select a valid choice. 6 is not one of the available choices.']", f.clean, ['1','6'])
    881874
    882875    # TypedMultipleChoiceField ############################################################
    883876    # TypedMultipleChoiceField is just like MultipleChoiceField, except that coerced types
     
    886879    def test_typedmultiplechoicefield_1(self):
    887880        f = TypedMultipleChoiceField(choices=[(1, "+1"), (-1, "-1")], coerce=int)
    888881        self.assertEqual([1], f.clean(['1']))
    889         self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. 2 is not one of the available choices.']", f.clean, ['2'])
     882        self.assertRaisesMessage(ValidationError, "[u'Select a valid choice. 2 is not one of the available choices.']", f.clean, ['2'])
    890883
    891884    def test_typedmultiplechoicefield_2(self):
    892885        # Different coercion, same validation.
     
    901894    def test_typedmultiplechoicefield_4(self):
    902895        f = TypedMultipleChoiceField(choices=[(1, "+1"), (-1, "-1")], coerce=int)
    903896        self.assertEqual([1, -1], f.clean(['1','-1']))
    904         self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. 2 is not one of the available choices.']", f.clean, ['1','2'])
     897        self.assertRaisesMessage(ValidationError, "[u'Select a valid choice. 2 is not one of the available choices.']", f.clean, ['1','2'])
    905898
    906899    def test_typedmultiplechoicefield_5(self):
    907900        # Even more weirdness: if you have a valid choice but your coercion function
    908901        # can't coerce, you'll still get a validation error. Don't do this!
    909902        f = TypedMultipleChoiceField(choices=[('A', 'A'), ('B', 'B')], coerce=int)
    910         self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. B is not one of the available choices.']", f.clean, ['B'])
     903        self.assertRaisesMessage(ValidationError, "[u'Select a valid choice. B is not one of the available choices.']", f.clean, ['B'])
    911904        # Required fields require values
    912         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, [])
     905        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, [])
    913906
    914907    def test_typedmultiplechoicefield_6(self):
    915908        # Non-required fields aren't required
     
    926919    def test_combofield_1(self):
    927920        f = ComboField(fields=[CharField(max_length=20), EmailField()])
    928921        self.assertEqual(u'test@example.com', f.clean('test@example.com'))
    929         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value has at most 20 characters (it has 28).']", f.clean, 'longemailaddress@example.com')
    930         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'not an e-mail')
    931         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
    932         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
     922        self.assertRaisesMessage(ValidationError, "[u'Ensure this value has at most 20 characters (it has 28).']", f.clean, 'longemailaddress@example.com')
     923        self.assertRaisesMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'not an e-mail')
     924        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '')
     925        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None)
    933926
    934927    def test_combofield_2(self):
    935928        f = ComboField(fields=[CharField(max_length=20), EmailField()], required=False)
    936929        self.assertEqual(u'test@example.com', f.clean('test@example.com'))
    937         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value has at most 20 characters (it has 28).']", f.clean, 'longemailaddress@example.com')
    938         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'not an e-mail')
     930        self.assertRaisesMessage(ValidationError, "[u'Ensure this value has at most 20 characters (it has 28).']", f.clean, 'longemailaddress@example.com')
     931        self.assertRaisesMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'not an e-mail')
    939932        self.assertEqual(u'', f.clean(''))
    940933        self.assertEqual(u'', f.clean(None))
    941934
     
    964957        for exp, got in zip(expected, fix_os_paths(f.choices)):
    965958            self.assertEqual(exp[1], got[1])
    966959            self.assertTrue(got[0].endswith(exp[0]))
    967         self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. fields.py is not one of the available choices.']", f.clean, 'fields.py')
     960        self.assertRaisesMessage(ValidationError, "[u'Select a valid choice. fields.py is not one of the available choices.']", f.clean, 'fields.py')
    968961        assert fix_os_paths(f.clean(path + 'fields.py')).endswith('/django/forms/fields.py')
    969962
    970963    def test_filepathfield_3(self):
     
    10121005        f = SplitDateTimeField()
    10131006        assert isinstance(f.widget, SplitDateTimeWidget)
    10141007        self.assertEqual(datetime.datetime(2006, 1, 10, 7, 30), f.clean([datetime.date(2006, 1, 10), datetime.time(7, 30)]))
    1015         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
    1016         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
    1017         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a list of values.']", f.clean, 'hello')
    1018         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid date.', u'Enter a valid time.']", f.clean, ['hello', 'there'])
    1019         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid time.']", f.clean, ['2006-01-10', 'there'])
    1020         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid date.']", f.clean, ['hello', '07:30'])
     1008        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None)
     1009        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '')
     1010        self.assertRaisesMessage(ValidationError, "[u'Enter a list of values.']", f.clean, 'hello')
     1011        self.assertRaisesMessage(ValidationError, "[u'Enter a valid date.', u'Enter a valid time.']", f.clean, ['hello', 'there'])
     1012        self.assertRaisesMessage(ValidationError, "[u'Enter a valid time.']", f.clean, ['2006-01-10', 'there'])
     1013        self.assertRaisesMessage(ValidationError, "[u'Enter a valid date.']", f.clean, ['hello', '07:30'])
    10211014
    10221015    def test_splitdatetimefield_2(self):
    10231016        f = SplitDateTimeField(required=False)
     
    10271020        self.assertEqual(None, f.clean(''))
    10281021        self.assertEqual(None, f.clean(['']))
    10291022        self.assertEqual(None, f.clean(['', '']))
    1030         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a list of values.']", f.clean, 'hello')
    1031         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid date.', u'Enter a valid time.']", f.clean, ['hello', 'there'])
    1032         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid time.']", f.clean, ['2006-01-10', 'there'])
    1033         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid date.']", f.clean, ['hello', '07:30'])
    1034         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid time.']", f.clean, ['2006-01-10', ''])
    1035         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid time.']", f.clean, ['2006-01-10'])
    1036         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid date.']", f.clean, ['', '07:30'])
     1023        self.assertRaisesMessage(ValidationError, "[u'Enter a list of values.']", f.clean, 'hello')
     1024        self.assertRaisesMessage(ValidationError, "[u'Enter a valid date.', u'Enter a valid time.']", f.clean, ['hello', 'there'])
     1025        self.assertRaisesMessage(ValidationError, "[u'Enter a valid time.']", f.clean, ['2006-01-10', 'there'])
     1026        self.assertRaisesMessage(ValidationError, "[u'Enter a valid date.']", f.clean, ['hello', '07:30'])
     1027        self.assertRaisesMessage(ValidationError, "[u'Enter a valid time.']", f.clean, ['2006-01-10', ''])
     1028        self.assertRaisesMessage(ValidationError, "[u'Enter a valid time.']", f.clean, ['2006-01-10'])
     1029        self.assertRaisesMessage(ValidationError, "[u'Enter a valid date.']", f.clean, ['', '07:30'])
  • tests/regressiontests/queries/tests.py

    diff --git a/tests/regressiontests/queries/tests.py b/tests/regressiontests/queries/tests.py
    a b  
    2222    def assertValueQuerysetEqual(self, qs, values):
    2323        return self.assertQuerysetEqual(qs, values, transform=lambda x: x)
    2424
    25     def assertRaisesMessage(self, exc, msg, func, *args, **kwargs):
    26         try:
    27             func(*args, **kwargs)
    28         except Exception, e:
    29             self.assertEqual(msg, str(e))
    30             self.assertTrue(isinstance(e, exc), "Expected %s, got %s" % (exc, type(e)))
    31         else:
    32             if hasattr(exc, '__name__'):
    33                 excName = exc.__name__
    34             else:
    35                 excName = str(exc)
    36             raise AssertionError("%s not raised" % excName)
    37 
    3825
    3926class Queries1Tests(BaseQuerysetTest):
    4027    def setUp(self):
  • tests/regressiontests/urlpatterns_reverse/tests.py

    diff --git a/tests/regressiontests/urlpatterns_reverse/tests.py b/tests/regressiontests/urlpatterns_reverse/tests.py
    a b  
    138138class NoURLPatternsTests(TestCase):
    139139    urls = 'regressiontests.urlpatterns_reverse.no_urls'
    140140
    141     def assertRaisesErrorWithMessage(self, error, message, callable,
    142         *args, **kwargs):
    143         self.assertRaises(error, callable, *args, **kwargs)
    144         try:
    145             callable(*args, **kwargs)
    146         except error, e:
    147             self.assertEqual(message, str(e))
    148 
    149141    def test_no_urls_exception(self):
    150142        """
    151143        RegexURLResolver should raise an exception when no urlpatterns exist.
    152144        """
    153145        resolver = RegexURLResolver(r'^$', self.urls)
    154146
    155         self.assertRaisesErrorWithMessage(ImproperlyConfigured,
     147        self.assertRaisesMessage(ImproperlyConfigured,
    156148            "The included urlconf regressiontests.urlpatterns_reverse.no_urls "\
    157149            "doesn't have any patterns in it", getattr, resolver, 'url_patterns')
    158150
  • tests/regressiontests/utils/datastructures.py

    diff --git a/tests/regressiontests/utils/datastructures.py b/tests/regressiontests/utils/datastructures.py
    a b  
    44
    55import copy
    66import pickle
    7 import unittest
    87
     8from django.test import SimpleTestCase
    99from django.utils.datastructures import *
    1010
    1111
    12 class DatastructuresTestCase(unittest.TestCase):
    13     def assertRaisesErrorWithMessage(self, error, message, callable,
    14         *args, **kwargs):
    15         self.assertRaises(error, callable, *args, **kwargs)
    16         try:
    17             callable(*args, **kwargs)
    18         except error, e:
    19             self.assertEqual(message, str(e))
     12class DatastructuresTestCase(SimpleTestCase):
     13    pass
    2014
    2115
    2216class SortedDictTests(DatastructuresTestCase):
     
    198192        # MultiValueDictKeyError: "Key 'lastname' not found in
    199193        # <MultiValueDict: {'position': ['Developer'],
    200194        #                   'name': ['Adrian', 'Simon']}>"
    201         self.assertRaisesErrorWithMessage(MultiValueDictKeyError,
     195        self.assertRaisesMessage(MultiValueDictKeyError,
    202196            '"Key \'lastname\' not found in <MultiValueDict: {\'position\':'\
    203197            ' [\'Developer\'], \'name\': [\'Adrian\', \'Simon\']}>"',
    204198            d.__getitem__, 'lastname')
     
    268262        d = ImmutableList(range(10))
    269263
    270264        # AttributeError: ImmutableList object is immutable.
    271         self.assertRaisesErrorWithMessage(AttributeError,
     265        self.assertRaisesMessage(AttributeError,
    272266            'ImmutableList object is immutable.', d.sort)
    273267
    274268        self.assertEqual(repr(d), '(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)')
     
    279273        self.assertEqual(d[1], 1)
    280274
    281275        # AttributeError: Object is immutable!
    282         self.assertRaisesErrorWithMessage(AttributeError,
     276        self.assertRaisesMessage(AttributeError,
    283277            'Object is immutable!', d.__setitem__, 1, 'test')
    284278
    285279
Back to Top