Ticket #14503: 14503-with-mixin.diff

File 14503-with-mixin.diff, 70.1 KB (added by Ramiro Morales, 13 years ago)

Uupdated patch

  • 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, SimpleTestMixin)
    78from django.test.utils import Approximate
  • django/test/testcases.py

    diff --git a/django/test/testcases.py b/django/test/testcases.py
    a b  
    235235            )
    236236        )
    237237
     238class SimpleTestMixin(object):
    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(SimpleTestMixin, ut2.TestCase):
    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 SimpleTestMixin
    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(SimpleTestMixin, unittest.TestCase):
    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  
    364364
    365365
    366366class NaturalKeyFixtureTests(TestCase):
    367     def assertRaisesMessage(self, exc, msg, func, *args, **kwargs):
    368         try:
    369             func(*args, **kwargs)
    370         except Exception, e:
    371             self.assertEqual(msg, str(e))
    372             self.assertTrue(isinstance(e, exc), "Expected %s, got %s" % (exc, type(e)))
    373367
    374368    def test_nk_deserialize(self):
    375369        """
  • tests/regressiontests/forms/tests/fields.py

    diff --git a/tests/regressiontests/forms/tests/fields.py b/tests/regressiontests/forms/tests/fields.py
    a b  
    3434from django.core.files.uploadedfile import SimpleUploadedFile
    3535from django.forms import *
    3636from django.utils.unittest import TestCase
     37from django.test import SimpleTestMixin
    3738
    3839
    3940def fix_os_paths(x):
     
    6970    return decorator
    7071
    7172
    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))
     73class FieldsTests(SimpleTestMixin, TestCase):
    8074
    8175    def test_field_sets_widget_is_required(self):
    8276        self.assertTrue(Field(required=True).widget.is_required)
     
    8882        f = CharField()
    8983        self.assertEqual(u'1', f.clean(1))
    9084        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, '')
     85        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None)
     86        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '')
    9387        self.assertEqual(u'[1, 2, 3]', f.clean([1, 2, 3]))
    9488        self.assertEqual(f.max_length, None)
    9589        self.assertEqual(f.min_length, None)
     
    108102        f = CharField(max_length=10, required=False)
    109103        self.assertEqual(u'12345', f.clean('12345'))
    110104        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')
     105        self.assertRaisesMessage(ValidationError, "[u'Ensure this value has at most 10 characters (it has 11).']", f.clean, '1234567890a')
    112106        self.assertEqual(f.max_length, 10)
    113107        self.assertEqual(f.min_length, None)
    114108
    115109    def test_charfield_4(self):
    116110        f = CharField(min_length=10, required=False)
    117111        self.assertEqual(u'', f.clean(''))
    118         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value has at least 10 characters (it has 5).']", f.clean, '12345')
     112        self.assertRaisesMessage(ValidationError, "[u'Ensure this value has at least 10 characters (it has 5).']", f.clean, '12345')
    119113        self.assertEqual(u'1234567890', f.clean('1234567890'))
    120114        self.assertEqual(u'1234567890a', f.clean('1234567890a'))
    121115        self.assertEqual(f.max_length, None)
     
    123117
    124118    def test_charfield_5(self):
    125119        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')
     120        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '')
     121        self.assertRaisesMessage(ValidationError, "[u'Ensure this value has at least 10 characters (it has 5).']", f.clean, '12345')
    128122        self.assertEqual(u'1234567890', f.clean('1234567890'))
    129123        self.assertEqual(u'1234567890a', f.clean('1234567890a'))
    130124        self.assertEqual(f.max_length, None)
     
    134128
    135129    def test_integerfield_1(self):
    136130        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)
     131        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '')
     132        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None)
    139133        self.assertEqual(1, f.clean('1'))
    140134        self.assertEqual(True, isinstance(f.clean('1'), int))
    141135        self.assertEqual(23, f.clean('23'))
    142         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a whole number.']", f.clean, 'a')
     136        self.assertRaisesMessage(ValidationError, "[u'Enter a whole number.']", f.clean, 'a')
    143137        self.assertEqual(42, f.clean(42))
    144         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a whole number.']", f.clean, 3.14)
     138        self.assertRaisesMessage(ValidationError, "[u'Enter a whole number.']", f.clean, 3.14)
    145139        self.assertEqual(1, f.clean('1 '))
    146140        self.assertEqual(1, f.clean(' 1'))
    147141        self.assertEqual(1, f.clean(' 1 '))
    148         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a whole number.']", f.clean, '1a')
     142        self.assertRaisesMessage(ValidationError, "[u'Enter a whole number.']", f.clean, '1a')
    149143        self.assertEqual(f.max_value, None)
    150144        self.assertEqual(f.min_value, None)
    151145
     
    158152        self.assertEqual(1, f.clean('1'))
    159153        self.assertEqual(True, isinstance(f.clean('1'), int))
    160154        self.assertEqual(23, f.clean('23'))
    161         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a whole number.']", f.clean, 'a')
     155        self.assertRaisesMessage(ValidationError, "[u'Enter a whole number.']", f.clean, 'a')
    162156        self.assertEqual(1, f.clean('1 '))
    163157        self.assertEqual(1, f.clean(' 1'))
    164158        self.assertEqual(1, f.clean(' 1 '))
    165         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a whole number.']", f.clean, '1a')
     159        self.assertRaisesMessage(ValidationError, "[u'Enter a whole number.']", f.clean, '1a')
    166160        self.assertEqual(f.max_value, None)
    167161        self.assertEqual(f.min_value, None)
    168162
    169163    def test_integerfield_3(self):
    170164        f = IntegerField(max_value=10)
    171         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
     165        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None)
    172166        self.assertEqual(1, f.clean(1))
    173167        self.assertEqual(10, f.clean(10))
    174         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value is less than or equal to 10.']", f.clean, 11)
     168        self.assertRaisesMessage(ValidationError, "[u'Ensure this value is less than or equal to 10.']", f.clean, 11)
    175169        self.assertEqual(10, f.clean('10'))
    176         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value is less than or equal to 10.']", f.clean, '11')
     170        self.assertRaisesMessage(ValidationError, "[u'Ensure this value is less than or equal to 10.']", f.clean, '11')
    177171        self.assertEqual(f.max_value, 10)
    178172        self.assertEqual(f.min_value, None)
    179173
    180174    def test_integerfield_4(self):
    181175        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)
     176        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None)
     177        self.assertRaisesMessage(ValidationError, "[u'Ensure this value is greater than or equal to 10.']", f.clean, 1)
    184178        self.assertEqual(10, f.clean(10))
    185179        self.assertEqual(11, f.clean(11))
    186180        self.assertEqual(10, f.clean('10'))
     
    190184
    191185    def test_integerfield_5(self):
    192186        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)
     187        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None)
     188        self.assertRaisesMessage(ValidationError, "[u'Ensure this value is greater than or equal to 10.']", f.clean, 1)
    195189        self.assertEqual(10, f.clean(10))
    196190        self.assertEqual(11, f.clean(11))
    197191        self.assertEqual(10, f.clean('10'))
    198192        self.assertEqual(11, f.clean('11'))
    199193        self.assertEqual(20, f.clean(20))
    200         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value is less than or equal to 20.']", f.clean, 21)
     194        self.assertRaisesMessage(ValidationError, "[u'Ensure this value is less than or equal to 20.']", f.clean, 21)
    201195        self.assertEqual(f.max_value, 20)
    202196        self.assertEqual(f.min_value, 10)
    203197
     
    205199
    206200    def test_floatfield_1(self):
    207201        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)
     202        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '')
     203        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None)
    210204        self.assertEqual(1.0, f.clean('1'))
    211205        self.assertEqual(True, isinstance(f.clean('1'), float))
    212206        self.assertEqual(23.0, f.clean('23'))
    213207        self.assertEqual(3.1400000000000001, f.clean('3.14'))
    214208        self.assertEqual(3.1400000000000001, f.clean(3.14))
    215209        self.assertEqual(42.0, f.clean(42))
    216         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a number.']", f.clean, 'a')
     210        self.assertRaisesMessage(ValidationError, "[u'Enter a number.']", f.clean, 'a')
    217211        self.assertEqual(1.0, f.clean('1.0 '))
    218212        self.assertEqual(1.0, f.clean(' 1.0'))
    219213        self.assertEqual(1.0, f.clean(' 1.0 '))
    220         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a number.']", f.clean, '1.0a')
     214        self.assertRaisesMessage(ValidationError, "[u'Enter a number.']", f.clean, '1.0a')
    221215        self.assertEqual(f.max_value, None)
    222216        self.assertEqual(f.min_value, None)
    223217
     
    231225
    232226    def test_floatfield_3(self):
    233227        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')
     228        self.assertRaisesMessage(ValidationError, "[u'Ensure this value is less than or equal to 1.5.']", f.clean, '1.6')
     229        self.assertRaisesMessage(ValidationError, "[u'Ensure this value is greater than or equal to 0.5.']", f.clean, '0.4')
    236230        self.assertEqual(1.5, f.clean('1.5'))
    237231        self.assertEqual(0.5, f.clean('0.5'))
    238232        self.assertEqual(f.max_value, 1.5)
     
    242236
    243237    def test_decimalfield_1(self):
    244238        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)
     239        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '')
     240        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None)
    247241        self.assertEqual(f.clean('1'), Decimal("1"))
    248242        self.assertEqual(True, isinstance(f.clean('1'), Decimal))
    249243        self.assertEqual(f.clean('23'), Decimal("23"))
    250244        self.assertEqual(f.clean('3.14'), Decimal("3.14"))
    251245        self.assertEqual(f.clean(3.14), Decimal("3.14"))
    252246        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'łąść')
     247        self.assertRaisesMessage(ValidationError, "[u'Enter a number.']", f.clean, 'NaN')
     248        self.assertRaisesMessage(ValidationError, "[u'Enter a number.']", f.clean, 'Inf')
     249        self.assertRaisesMessage(ValidationError, "[u'Enter a number.']", f.clean, '-Inf')
     250        self.assertRaisesMessage(ValidationError, "[u'Enter a number.']", f.clean, 'a')
     251        self.assertRaisesMessage(ValidationError, "[u'Enter a number.']", f.clean, u'łąść')
    258252        self.assertEqual(f.clean('1.0 '), Decimal("1.0"))
    259253        self.assertEqual(f.clean(' 1.0'), Decimal("1.0"))
    260254        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')
     255        self.assertRaisesMessage(ValidationError, "[u'Enter a number.']", f.clean, '1.0a')
     256        self.assertRaisesMessage(ValidationError, "[u'Ensure that there are no more than 4 digits in total.']", f.clean, '123.45')
     257        self.assertRaisesMessage(ValidationError, "[u'Ensure that there are no more than 2 decimal places.']", f.clean, '1.234')
     258        self.assertRaisesMessage(ValidationError, "[u'Ensure that there are no more than 2 digits before the decimal point.']", f.clean, '123.4')
    265259        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')
     260        self.assertRaisesMessage(ValidationError, "[u'Ensure that there are no more than 4 digits in total.']", f.clean, '-123.45')
    267261        self.assertEqual(f.clean('-.12'), Decimal("-0.12"))
    268262        self.assertEqual(f.clean('-00.12'), Decimal("-0.12"))
    269263        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')
     264        self.assertRaisesMessage(ValidationError, "[u'Ensure that there are no more than 2 decimal places.']", f.clean, '-000.123')
     265        self.assertRaisesMessage(ValidationError, "[u'Ensure that there are no more than 4 digits in total.']", f.clean, '-000.12345')
     266        self.assertRaisesMessage(ValidationError, "[u'Enter a number.']", f.clean, '--0.12')
    273267        self.assertEqual(f.max_digits, 4)
    274268        self.assertEqual(f.decimal_places, 2)
    275269        self.assertEqual(f.max_value, None)
     
    287281
    288282    def test_decimalfield_3(self):
    289283        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')
     284        self.assertRaisesMessage(ValidationError, "[u'Ensure this value is less than or equal to 1.5.']", f.clean, '1.6')
     285        self.assertRaisesMessage(ValidationError, "[u'Ensure this value is greater than or equal to 0.5.']", f.clean, '0.4')
    292286        self.assertEqual(f.clean('1.5'), Decimal("1.5"))
    293287        self.assertEqual(f.clean('0.5'), Decimal("0.5"))
    294288        self.assertEqual(f.clean('.5'), Decimal("0.5"))
     
    300294
    301295    def test_decimalfield_4(self):
    302296        f = DecimalField(decimal_places=2)
    303         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure that there are no more than 2 decimal places.']", f.clean, '0.00000001')
     297        self.assertRaisesMessage(ValidationError, "[u'Ensure that there are no more than 2 decimal places.']", f.clean, '0.00000001')
    304298
    305299    def test_decimalfield_5(self):
    306300        f = DecimalField(max_digits=3)
     
    310304        self.assertEqual(f.clean('0000000.100'), Decimal("0.100"))
    311305        # Only leading whole zeros "collapse" to one digit.
    312306        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')
     307        self.assertRaisesMessage(ValidationError, "[u'Ensure that there are no more than 3 digits in total.']", f.clean, '000000.0002')
    314308        self.assertEqual(f.clean('.002'), Decimal("0.002"))
    315309
    316310    def test_decimalfield_6(self):
    317311        f = DecimalField(max_digits=2, decimal_places=2)
    318312        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')
     313        self.assertRaisesMessage(ValidationError, "[u'Ensure that there are no more than 0 digits before the decimal point.']", f.clean, '1.1')
    320314
    321315    # DateField ###################################################################
    322316
     
    334328        self.assertEqual(datetime.date(2006, 10, 25), f.clean('October 25, 2006'))
    335329        self.assertEqual(datetime.date(2006, 10, 25), f.clean('25 October 2006'))
    336330        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)
     331        self.assertRaisesMessage(ValidationError, "[u'Enter a valid date.']", f.clean, '2006-4-31')
     332        self.assertRaisesMessage(ValidationError, "[u'Enter a valid date.']", f.clean, '200a-10-25')
     333        self.assertRaisesMessage(ValidationError, "[u'Enter a valid date.']", f.clean, '25/10/06')
     334        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None)
    341335
    342336    def test_datefield_2(self):
    343337        f = DateField(required=False)
     
    351345        self.assertEqual(datetime.date(2006, 10, 25), f.clean(datetime.date(2006, 10, 25)))
    352346        self.assertEqual(datetime.date(2006, 10, 25), f.clean(datetime.datetime(2006, 10, 25, 14, 30)))
    353347        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')
     348        self.assertRaisesMessage(ValidationError, "[u'Enter a valid date.']", f.clean, '2006-10-25')
     349        self.assertRaisesMessage(ValidationError, "[u'Enter a valid date.']", f.clean, '10/25/2006')
     350        self.assertRaisesMessage(ValidationError, "[u'Enter a valid date.']", f.clean, '10/25/06')
    357351
    358352    def test_datefield_4(self):
    359353        # Test whitespace stripping behavior (#5714)
     
    364358        self.assertEqual(datetime.date(2006, 10, 25), f.clean(' October  25 2006 '))
    365359        self.assertEqual(datetime.date(2006, 10, 25), f.clean(' October 25, 2006 '))
    366360        self.assertEqual(datetime.date(2006, 10, 25), f.clean(' 25 October 2006 '))
    367         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid date.']", f.clean, '   ')
     361        self.assertRaisesMessage(ValidationError, "[u'Enter a valid date.']", f.clean, '   ')
    368362
    369363    # TimeField ###################################################################
    370364
     
    374368        self.assertEqual(datetime.time(14, 25, 59), f.clean(datetime.time(14, 25, 59)))
    375369        self.assertEqual(datetime.time(14, 25), f.clean('14:25'))
    376370        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.')
     371        self.assertRaisesMessage(ValidationError, "[u'Enter a valid time.']", f.clean, 'hello')
     372        self.assertRaisesMessage(ValidationError, "[u'Enter a valid time.']", f.clean, '1:24 p.m.')
    379373
    380374    def test_timefield_2(self):
    381375        f = TimeField(input_formats=['%I:%M %p'])
     
    383377        self.assertEqual(datetime.time(14, 25, 59), f.clean(datetime.time(14, 25, 59)))
    384378        self.assertEqual(datetime.time(4, 25), f.clean('4:25 AM'))
    385379        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')
     380        self.assertRaisesMessage(ValidationError, "[u'Enter a valid time.']", f.clean, '14:30:45')
    387381
    388382    def test_timefield_3(self):
    389383        f = TimeField()
    390384        # Test whitespace stripping behavior (#5714)
    391385        self.assertEqual(datetime.time(14, 25), f.clean(' 14:25 '))
    392386        self.assertEqual(datetime.time(14, 25, 59), f.clean(' 14:25:59 '))
    393         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid time.']", f.clean, '   ')
     387        self.assertRaisesMessage(ValidationError, "[u'Enter a valid time.']", f.clean, '   ')
    394388
    395389    # DateTimeField ###############################################################
    396390
     
    415409        self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30), f.clean('10/25/06 14:30:00'))
    416410        self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30), f.clean('10/25/06 14:30'))
    417411        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.')
     412        self.assertRaisesMessage(ValidationError, "[u'Enter a valid date/time.']", f.clean, 'hello')
     413        self.assertRaisesMessage(ValidationError, "[u'Enter a valid date/time.']", f.clean, '2006-10-25 4:30 p.m.')
    420414
    421415    def test_datetimefield_2(self):
    422416        f = DateTimeField(input_formats=['%Y %m %d %I:%M %p'])
     
    425419        self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30, 59), f.clean(datetime.datetime(2006, 10, 25, 14, 30, 59)))
    426420        self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30, 59, 200), f.clean(datetime.datetime(2006, 10, 25, 14, 30, 59, 200)))
    427421        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')
     422        self.assertRaisesMessage(ValidationError, "[u'Enter a valid date/time.']", f.clean, '2006-10-25 14:30:45')
    429423
    430424    def test_datetimefield_3(self):
    431425        f = DateTimeField(required=False)
     
    444438        self.assertEqual(datetime.datetime(2006, 10, 25, 0, 0), f.clean(' 10/25/2006 '))
    445439        self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30, 45), f.clean(' 10/25/06 14:30:45 '))
    446440        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, '   ')
     441        self.assertRaisesMessage(ValidationError, "[u'Enter a valid date/time.']", f.clean, '   ')
    448442
    449443    # RegexField ##################################################################
    450444
     
    452446        f = RegexField('^\d[A-F]\d$')
    453447        self.assertEqual(u'2A2', f.clean('2A2'))
    454448        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, '')
     449        self.assertRaisesMessage(ValidationError, "[u'Enter a valid value.']", f.clean, '3G3')
     450        self.assertRaisesMessage(ValidationError, "[u'Enter a valid value.']", f.clean, ' 2A2')
     451        self.assertRaisesMessage(ValidationError, "[u'Enter a valid value.']", f.clean, '2A2 ')
     452        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '')
    459453
    460454    def test_regexfield_2(self):
    461455        f = RegexField('^\d[A-F]\d$', required=False)
    462456        self.assertEqual(u'2A2', f.clean('2A2'))
    463457        self.assertEqual(u'3F3', f.clean('3F3'))
    464         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid value.']", f.clean, '3G3')
     458        self.assertRaisesMessage(ValidationError, "[u'Enter a valid value.']", f.clean, '3G3')
    465459        self.assertEqual(u'', f.clean(''))
    466460
    467461    def test_regexfield_3(self):
    468462        f = RegexField(re.compile('^\d[A-F]\d$'))
    469463        self.assertEqual(u'2A2', f.clean('2A2'))
    470464        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 ')
     465        self.assertRaisesMessage(ValidationError, "[u'Enter a valid value.']", f.clean, '3G3')
     466        self.assertRaisesMessage(ValidationError, "[u'Enter a valid value.']", f.clean, ' 2A2')
     467        self.assertRaisesMessage(ValidationError, "[u'Enter a valid value.']", f.clean, '2A2 ')
    474468
    475469    def test_regexfield_4(self):
    476470        f = RegexField('^\d\d\d\d$', error_message='Enter a four-digit number.')
    477471        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')
     472        self.assertRaisesMessage(ValidationError, "[u'Enter a four-digit number.']", f.clean, '123')
     473        self.assertRaisesMessage(ValidationError, "[u'Enter a four-digit number.']", f.clean, 'abcd')
    480474
    481475    def test_regexfield_5(self):
    482476        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')
     477        self.assertRaisesMessage(ValidationError, "[u'Ensure this value has at least 5 characters (it has 3).']", f.clean, '123')
     478        self.assertRaisesMessage(ValidationError, "[u'Ensure this value has at least 5 characters (it has 3).', u'Enter a valid value.']", f.clean, 'abc')
    485479        self.assertEqual(u'12345', f.clean('12345'))
    486480        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')
     481        self.assertRaisesMessage(ValidationError, "[u'Ensure this value has at most 10 characters (it has 11).']", f.clean, '12345678901')
     482        self.assertRaisesMessage(ValidationError, "[u'Enter a valid value.']", f.clean, '12345a')
    489483
    490484    # EmailField ##################################################################
    491485
    492486    def test_emailfield_1(self):
    493487        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)
     488        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '')
     489        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None)
    496490        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')
     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@')
     493        self.assertRaisesMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'foo@bar')
     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@-invalid.com')
     496        self.assertRaisesMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'example@inv-.alid-.com')
     497        self.assertRaisesMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'example@inv-.-alid.com')
    504498        self.assertEqual(u'example@valid-----hyphens.com', f.clean('example@valid-----hyphens.com'))
    505499        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')
     500        self.assertRaisesMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'example@.com')
    507501        self.assertEqual(u'local@domain.with.idn.xyz\xe4\xf6\xfc\xdfabc.part.com', f.clean('local@domain.with.idn.xyzäöüßabc.part.com'))
    508502
    509503    def test_email_regexp_for_performance(self):
    510504        f = EmailField()
    511505        # Check for runaway regex security problem. This will take for-freeking-ever
    512506        # if the security fix isn't in place.
    513         self.assertRaisesErrorWithMessage(
     507        self.assertRaisesMessage(
    514508                ValidationError,
    515509                "[u'Enter a valid e-mail address.']",
    516510                f.clean,
     
    523517        self.assertEqual(u'', f.clean(None))
    524518        self.assertEqual(u'person@example.com', f.clean('person@example.com'))
    525519        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')
     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@')
     522        self.assertRaisesMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'foo@bar')
    529523
    530524    def test_emailfield_3(self):
    531525        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')
     526        self.assertRaisesMessage(ValidationError, "[u'Ensure this value has at least 10 characters (it has 9).']", f.clean, 'a@foo.com')
    533527        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')
     528        self.assertRaisesMessage(ValidationError, "[u'Ensure this value has at most 15 characters (it has 20).']", f.clean, 'alf123456788@foo.com')
    535529
    536530    # FileField ##################################################################
    537531
    538532    def test_filefield_1(self):
    539533        f = FileField()
    540         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
    541         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '', '')
     534        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '')
     535        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '', '')
    542536        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, '')
     537        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None)
     538        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None, '')
    545539        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('', ''), '')
     540        self.assertRaisesMessage(ValidationError, "[u'No file was submitted. Check the encoding type on the form.']", f.clean, SimpleUploadedFile('', ''))
     541        self.assertRaisesMessage(ValidationError, "[u'No file was submitted. Check the encoding type on the form.']", f.clean, SimpleUploadedFile('', ''), '')
    548542        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', ''))
     543        self.assertRaisesMessage(ValidationError, "[u'No file was submitted. Check the encoding type on the form.']", f.clean, 'some content that is not a file')
     544        self.assertRaisesMessage(ValidationError, "[u'The submitted file is empty.']", f.clean, SimpleUploadedFile('name', None))
     545        self.assertRaisesMessage(ValidationError, "[u'The submitted file is empty.']", f.clean, SimpleUploadedFile('name', ''))
    552546        self.assertEqual(SimpleUploadedFile, type(f.clean(SimpleUploadedFile('name', 'Some File Content'))))
    553547        self.assertEqual(SimpleUploadedFile, type(f.clean(SimpleUploadedFile('我隻氣墊船裝滿晒鱔.txt', 'मेरी मँडराने वाली नाव सर्पमीनों से भरी ह'))))
    554548        self.assertEqual(SimpleUploadedFile, type(f.clean(SimpleUploadedFile('name', 'Some File Content'), 'files/test4.pdf')))
    555549
    556550    def test_filefield_2(self):
    557551        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'))
     552        self.assertRaisesMessage(ValidationError, "[u'Ensure this filename has at most 5 characters (it has 18).']", f.clean, SimpleUploadedFile('test_maxlength.txt', 'hello world'))
    559553        self.assertEqual('files/test1.pdf', f.clean('', 'files/test1.pdf'))
    560554        self.assertEqual('files/test2.pdf', f.clean(None, 'files/test2.pdf'))
    561555        self.assertEqual(SimpleUploadedFile, type(f.clean(SimpleUploadedFile('name', 'Some File Content'))))
     
    569563
    570564    def test_urlfield_1(self):
    571565        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)
     566        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '')
     567        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None)
    574568        self.assertEqual(u'http://localhost/', f.clean('http://localhost'))
    575569        self.assertEqual(u'http://example.com/', f.clean('http://example.com'))
    576570        self.assertEqual(u'http://example.com./', f.clean('http://example.com.'))
     
    580574        self.assertEqual(u'http://subdomain.domain.com/', f.clean('subdomain.domain.com'))
    581575        self.assertEqual(u'http://200.8.9.10/', f.clean('http://200.8.9.10'))
    582576        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')
     577        self.assertRaisesMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'foo')
     578        self.assertRaisesMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://')
     579        self.assertRaisesMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://example')
     580        self.assertRaisesMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://example.')
     581        self.assertRaisesMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'com.')
     582        self.assertRaisesMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, '.')
     583        self.assertRaisesMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://.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://-invalid.com')
     586        self.assertRaisesMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://inv-.alid-.com')
     587        self.assertRaisesMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://inv-.-alid.com')
    594588        self.assertEqual(u'http://valid-----hyphens.com/', f.clean('http://valid-----hyphens.com'))
    595589        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'))
    596590        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'))
     
    598592    def test_url_regex_ticket11198(self):
    599593        f = URLField()
    600594        # 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,))
     595        self.assertRaisesMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://%s' % ("X"*200,))
    602596
    603597        # a second test, to make sure the problem is really addressed, even on
    604598        # 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,))
     599        self.assertRaisesMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://%s' % ("X"*60,))
    606600
    607601    def test_urlfield_2(self):
    608602        f = URLField(required=False)
     
    610604        self.assertEqual(u'', f.clean(None))
    611605        self.assertEqual(u'http://example.com/', f.clean('http://example.com'))
    612606        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')
     607        self.assertRaisesMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'foo')
     608        self.assertRaisesMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://')
     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://example.')
     611        self.assertRaisesMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://.com')
    618612
    619613    @verify_exists_urls(('http://www.google.com/',))
    620614    def test_urlfield_3(self):
    621615        f = URLField(verify_exists=True)
    622616        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')
     617        self.assertRaisesMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://example')
    624618        self.assertRaises(ValidationError, f.clean, 'http://www.broken.djangoproject.com') # bad domain
    625619        self.assertRaises(ValidationError, f.clean, 'http://qa-dev.w3.org/link-testsuite/http.php?code=405') # Method not allowed
    626620        try:
     
    641635
    642636    def test_urlfield_5(self):
    643637        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')
     638        self.assertRaisesMessage(ValidationError, "[u'Ensure this value has at least 15 characters (it has 13).']", f.clean, 'http://f.com')
    645639        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')
     640        self.assertRaisesMessage(ValidationError, "[u'Ensure this value has at most 20 characters (it has 38).']", f.clean, 'http://abcdefghijklmnopqrstuvwxyz.com')
    647641
    648642    def test_urlfield_6(self):
    649643        f = URLField(required=False)
     
    697691
    698692    def test_booleanfield_1(self):
    699693        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)
     694        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '')
     695        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None)
    702696        self.assertEqual(True, f.clean(True))
    703         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, False)
     697        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, False)
    704698        self.assertEqual(True, f.clean(1))
    705         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, 0)
     699        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, 0)
    706700        self.assertEqual(True, f.clean('Django rocks'))
    707701        self.assertEqual(True, f.clean('True'))
    708         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, 'False')
     702        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, 'False')
    709703
    710704    def test_booleanfield_2(self):
    711705        f = BooleanField(required=False)
     
    726720
    727721    def test_choicefield_1(self):
    728722        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)
     723        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '')
     724        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None)
    731725        self.assertEqual(u'1', f.clean(1))
    732726        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')
     727        self.assertRaisesMessage(ValidationError, "[u'Select a valid choice. 3 is not one of the available choices.']", f.clean, '3')
    734728
    735729    def test_choicefield_2(self):
    736730        f = ChoiceField(choices=[('1', 'One'), ('2', 'Two')], required=False)
     
    738732        self.assertEqual(u'', f.clean(None))
    739733        self.assertEqual(u'1', f.clean(1))
    740734        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')
     735        self.assertRaisesMessage(ValidationError, "[u'Select a valid choice. 3 is not one of the available choices.']", f.clean, '3')
    742736
    743737    def test_choicefield_3(self):
    744738        f = ChoiceField(choices=[('J', 'John'), ('P', 'Paul')])
    745739        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')
     740        self.assertRaisesMessage(ValidationError, "[u'Select a valid choice. John is not one of the available choices.']", f.clean, 'John')
    747741
    748742    def test_choicefield_4(self):
    749743        f = ChoiceField(choices=[('Numbers', (('1', 'One'), ('2', 'Two'))), ('Letters', (('3','A'),('4','B'))), ('5','Other')])
     
    753747        self.assertEqual(u'3', f.clean('3'))
    754748        self.assertEqual(u'5', f.clean(5))
    755749        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')
     750        self.assertRaisesMessage(ValidationError, "[u'Select a valid choice. 6 is not one of the available choices.']", f.clean, '6')
    757751
    758752    # TypedChoiceField ############################################################
    759753    # TypedChoiceField is just like ChoiceField, except that coerced types will
     
    762756    def test_typedchoicefield_1(self):
    763757        f = TypedChoiceField(choices=[(1, "+1"), (-1, "-1")], coerce=int)
    764758        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')
     759        self.assertRaisesMessage(ValidationError, "[u'Select a valid choice. 2 is not one of the available choices.']", f.clean, '2')
    766760
    767761    def test_typedchoicefield_2(self):
    768762        # Different coercion, same validation.
     
    778772        # Even more weirdness: if you have a valid choice but your coercion function
    779773        # can't coerce, you'll still get a validation error. Don't do this!
    780774        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')
     775        self.assertRaisesMessage(ValidationError, "[u'Select a valid choice. B is not one of the available choices.']", f.clean, 'B')
    782776        # Required fields require values
    783         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
     777        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '')
    784778
    785779    def test_typedchoicefield_5(self):
    786780        # Non-required fields aren't required
     
    842836
    843837    def test_multiplechoicefield_1(self):
    844838        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)
     839        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '')
     840        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None)
    847841        self.assertEqual([u'1'], f.clean([1]))
    848842        self.assertEqual([u'1'], f.clean(['1']))
    849843        self.assertEqual([u'1', u'2'], f.clean(['1', '2']))
    850844        self.assertEqual([u'1', u'2'], f.clean([1, '2']))
    851845        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'])
     846        self.assertRaisesMessage(ValidationError, "[u'Enter a list of values.']", f.clean, 'hello')
     847        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, [])
     848        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, ())
     849        self.assertRaisesMessage(ValidationError, "[u'Select a valid choice. 3 is not one of the available choices.']", f.clean, ['3'])
    856850
    857851    def test_multiplechoicefield_2(self):
    858852        f = MultipleChoiceField(choices=[('1', 'One'), ('2', 'Two')], required=False)
     
    863857        self.assertEqual([u'1', u'2'], f.clean(['1', '2']))
    864858        self.assertEqual([u'1', u'2'], f.clean([1, '2']))
    865859        self.assertEqual([u'1', u'2'], f.clean((1, '2')))
    866         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a list of values.']", f.clean, 'hello')
     860        self.assertRaisesMessage(ValidationError, "[u'Enter a list of values.']", f.clean, 'hello')
    867861        self.assertEqual([], f.clean([]))
    868862        self.assertEqual([], f.clean(()))
    869         self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. 3 is not one of the available choices.']", f.clean, ['3'])
     863        self.assertRaisesMessage(ValidationError, "[u'Select a valid choice. 3 is not one of the available choices.']", f.clean, ['3'])
    870864
    871865    def test_multiplechoicefield_3(self):
    872866        f = MultipleChoiceField(choices=[('Numbers', (('1', 'One'), ('2', 'Two'))), ('Letters', (('3','A'),('4','B'))), ('5','Other')])
     
    876870        self.assertEqual([u'1', u'5'], f.clean([1, '5']))
    877871        self.assertEqual([u'1', u'5'], f.clean(['1', 5]))
    878872        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'])
     873        self.assertRaisesMessage(ValidationError, "[u'Select a valid choice. 6 is not one of the available choices.']", f.clean, ['6'])
     874        self.assertRaisesMessage(ValidationError, "[u'Select a valid choice. 6 is not one of the available choices.']", f.clean, ['1','6'])
    881875
    882876    # TypedMultipleChoiceField ############################################################
    883877    # TypedMultipleChoiceField is just like MultipleChoiceField, except that coerced types
     
    886880    def test_typedmultiplechoicefield_1(self):
    887881        f = TypedMultipleChoiceField(choices=[(1, "+1"), (-1, "-1")], coerce=int)
    888882        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'])
     883        self.assertRaisesMessage(ValidationError, "[u'Select a valid choice. 2 is not one of the available choices.']", f.clean, ['2'])
    890884
    891885    def test_typedmultiplechoicefield_2(self):
    892886        # Different coercion, same validation.
     
    901895    def test_typedmultiplechoicefield_4(self):
    902896        f = TypedMultipleChoiceField(choices=[(1, "+1"), (-1, "-1")], coerce=int)
    903897        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'])
     898        self.assertRaisesMessage(ValidationError, "[u'Select a valid choice. 2 is not one of the available choices.']", f.clean, ['1','2'])
    905899
    906900    def test_typedmultiplechoicefield_5(self):
    907901        # Even more weirdness: if you have a valid choice but your coercion function
    908902        # can't coerce, you'll still get a validation error. Don't do this!
    909903        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'])
     904        self.assertRaisesMessage(ValidationError, "[u'Select a valid choice. B is not one of the available choices.']", f.clean, ['B'])
    911905        # Required fields require values
    912         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, [])
     906        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, [])
    913907
    914908    def test_typedmultiplechoicefield_6(self):
    915909        # Non-required fields aren't required
     
    926920    def test_combofield_1(self):
    927921        f = ComboField(fields=[CharField(max_length=20), EmailField()])
    928922        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)
     923        self.assertRaisesMessage(ValidationError, "[u'Ensure this value has at most 20 characters (it has 28).']", f.clean, 'longemailaddress@example.com')
     924        self.assertRaisesMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'not an e-mail')
     925        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '')
     926        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None)
    933927
    934928    def test_combofield_2(self):
    935929        f = ComboField(fields=[CharField(max_length=20), EmailField()], required=False)
    936930        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')
     931        self.assertRaisesMessage(ValidationError, "[u'Ensure this value has at most 20 characters (it has 28).']", f.clean, 'longemailaddress@example.com')
     932        self.assertRaisesMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'not an e-mail')
    939933        self.assertEqual(u'', f.clean(''))
    940934        self.assertEqual(u'', f.clean(None))
    941935
     
    964958        for exp, got in zip(expected, fix_os_paths(f.choices)):
    965959            self.assertEqual(exp[1], got[1])
    966960            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')
     961        self.assertRaisesMessage(ValidationError, "[u'Select a valid choice. fields.py is not one of the available choices.']", f.clean, 'fields.py')
    968962        assert fix_os_paths(f.clean(path + 'fields.py')).endswith('/django/forms/fields.py')
    969963
    970964    def test_filepathfield_3(self):
     
    10121006        f = SplitDateTimeField()
    10131007        assert isinstance(f.widget, SplitDateTimeWidget)
    10141008        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'])
     1009        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None)
     1010        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '')
     1011        self.assertRaisesMessage(ValidationError, "[u'Enter a list of values.']", f.clean, 'hello')
     1012        self.assertRaisesMessage(ValidationError, "[u'Enter a valid date.', u'Enter a valid time.']", f.clean, ['hello', 'there'])
     1013        self.assertRaisesMessage(ValidationError, "[u'Enter a valid time.']", f.clean, ['2006-01-10', 'there'])
     1014        self.assertRaisesMessage(ValidationError, "[u'Enter a valid date.']", f.clean, ['hello', '07:30'])
    10211015
    10221016    def test_splitdatetimefield_2(self):
    10231017        f = SplitDateTimeField(required=False)
     
    10271021        self.assertEqual(None, f.clean(''))
    10281022        self.assertEqual(None, f.clean(['']))
    10291023        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'])
     1024        self.assertRaisesMessage(ValidationError, "[u'Enter a list of values.']", f.clean, 'hello')
     1025        self.assertRaisesMessage(ValidationError, "[u'Enter a valid date.', u'Enter a valid time.']", f.clean, ['hello', 'there'])
     1026        self.assertRaisesMessage(ValidationError, "[u'Enter a valid time.']", f.clean, ['2006-01-10', 'there'])
     1027        self.assertRaisesMessage(ValidationError, "[u'Enter a valid date.']", f.clean, ['hello', '07:30'])
     1028        self.assertRaisesMessage(ValidationError, "[u'Enter a valid time.']", f.clean, ['2006-01-10', ''])
     1029        self.assertRaisesMessage(ValidationError, "[u'Enter a valid time.']", f.clean, ['2006-01-10'])
     1030        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.utils import unittest
     9from django.test import SimpleTestMixin
    910from django.utils.datastructures import *
    1011
    1112
    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))
     13class DatastructuresTestCase(SimpleTestMixin, unittest.TestCase):
     14    pass
    2015
    2116
    2217class SortedDictTests(DatastructuresTestCase):
     
    198193        # MultiValueDictKeyError: "Key 'lastname' not found in
    199194        # <MultiValueDict: {'position': ['Developer'],
    200195        #                   'name': ['Adrian', 'Simon']}>"
    201         self.assertRaisesErrorWithMessage(MultiValueDictKeyError,
     196        self.assertRaisesMessage(MultiValueDictKeyError,
    202197            '"Key \'lastname\' not found in <MultiValueDict: {\'position\':'\
    203198            ' [\'Developer\'], \'name\': [\'Adrian\', \'Simon\']}>"',
    204199            d.__getitem__, 'lastname')
     
    268263        d = ImmutableList(range(10))
    269264
    270265        # AttributeError: ImmutableList object is immutable.
    271         self.assertRaisesErrorWithMessage(AttributeError,
     266        self.assertRaisesMessage(AttributeError,
    272267            'ImmutableList object is immutable.', d.sort)
    273268
    274269        self.assertEqual(repr(d), '(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)')
     
    279274        self.assertEqual(d[1], 1)
    280275
    281276        # AttributeError: Object is immutable!
    282         self.assertRaisesErrorWithMessage(AttributeError,
     277        self.assertRaisesMessage(AttributeError,
    283278            'Object is immutable!', d.__setitem__, 1, 'test')
    284279
    285280
Back to Top