Ticket #14503: 14503-replacement-with-assertraisesregexp.2.diff

File 14503-replacement-with-assertraisesregexp.2.diff, 82.4 KB (added by Ramiro Morales, 14 years ago)

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

  • tests/regressiontests/admin_validation/tests.py

    diff --git a/tests/regressiontests/admin_validation/tests.py b/tests/regressiontests/admin_validation/tests.py
    a b  
    1818    fields = ['spam']
    1919
    2020class ValidationTestCase(TestCase):
    21     def assertRaisesMessage(self, exc, msg, func, *args, **kwargs):
    22         try:
    23             func(*args, **kwargs)
    24         except Exception, e:
    25             self.assertEqual(msg, str(e))
    26             self.assertTrue(isinstance(e, exc), "Expected %s, got %s" % (exc, type(e)))
    27 
    2821    def test_readonly_and_editable(self):
    2922        class SongAdmin(admin.ModelAdmin):
    3023            readonly_fields = ["original_release"]
     
    4033        # Regression test for #8027: custom ModelForms with fields/fieldsets
    4134        """
    4235        validate(ValidFields, Song)
    43         self.assertRaisesMessage(ImproperlyConfigured,
     36        self.assertRaisesRegexp(ImproperlyConfigured,
    4437            "'InvalidFields.fields' refers to field 'spam' that is missing from the form.",
    4538            validate,
    4639            InvalidFields, Song)
     
    5144        """
    5245        class ExcludedFields1(admin.ModelAdmin):
    5346            exclude = ('foo')
    54         self.assertRaisesMessage(ImproperlyConfigured,
     47        self.assertRaisesRegexp(ImproperlyConfigured,
    5548            "'ExcludedFields1.exclude' must be a list or tuple.",
    5649            validate,
    5750            ExcludedFields1, Book)
     
    5952    def test_exclude_duplicate_values(self):
    6053        class ExcludedFields2(admin.ModelAdmin):
    6154            exclude = ('name', 'name')
    62         self.assertRaisesMessage(ImproperlyConfigured,
    63             "There are duplicate field(s) in ExcludedFields2.exclude",
     55        self.assertRaisesRegexp(ImproperlyConfigured,
     56            "There are duplicate field\(s\) in ExcludedFields2.exclude",
    6457            validate,
    6558            ExcludedFields2, Book)
    6659
     
    7366            model = Album
    7467            inlines = [ExcludedFieldsInline]
    7568
    76         self.assertRaisesMessage(ImproperlyConfigured,
     69        self.assertRaisesRegexp(ImproperlyConfigured,
    7770            "'ExcludedFieldsInline.exclude' must be a list or tuple.",
    7871            validate,
    7972            ExcludedFieldsAlbumAdmin, Album)
     
    9184            model = Album
    9285            inlines = [SongInline]
    9386
    94         self.assertRaisesMessage(ImproperlyConfigured,
     87        self.assertRaisesRegexp(ImproperlyConfigured,
    9588            "SongInline cannot exclude the field 'album' - this is the foreign key to the parent model Album.",
    9689            validate,
    9790            AlbumAdmin, Album)
     
    112105        class TwoAlbumFKAndAnEInline(admin.TabularInline):
    113106            model = TwoAlbumFKAndAnE
    114107
    115         self.assertRaisesMessage(Exception,
     108        self.assertRaisesRegexp(Exception,
    116109            "<class 'regressiontests.admin_validation.models.TwoAlbumFKAndAnE'> has more than 1 ForeignKey to <class 'regressiontests.admin_validation.models.Album'>",
    117110            validate_inline,
    118111            TwoAlbumFKAndAnEInline, None, Album)
     
    157150        class SongAdmin(admin.ModelAdmin):
    158151            readonly_fields = ("title", "nonexistant")
    159152
    160         self.assertRaisesMessage(ImproperlyConfigured,
    161             "SongAdmin.readonly_fields[1], 'nonexistant' is not a callable or an attribute of 'SongAdmin' or found in the model 'Song'.",
     153        self.assertRaisesRegexp(ImproperlyConfigured,
     154            "SongAdmin.readonly_fields\[1\], 'nonexistant' is not a callable or an attribute of 'SongAdmin' or found in the model 'Song'.",
    162155            validate,
    163156            SongAdmin, Song)
    164157
     
    186179        class BookAdmin(admin.ModelAdmin):
    187180            fields = ['authors']
    188181
    189         self.assertRaisesMessage(ImproperlyConfigured,
     182        self.assertRaisesRegexp(ImproperlyConfigured,
    190183            "'BookAdmin.fields' can't include the ManyToManyField field 'authors' because 'authors' manually specifies a 'through' model.",
    191184            validate,
    192185            BookAdmin, Book)
     
    197190                ('Header 1', {'fields': ('name',)}),
    198191                ('Header 2', {'fields': ('authors',)}),
    199192            )
    200         self.assertRaisesMessage(ImproperlyConfigured,
    201             "'FieldsetBookAdmin.fieldsets[1][1]['fields']' can't include the ManyToManyField field 'authors' because 'authors' manually specifies a 'through' model.",
     193        self.assertRaisesRegexp(ImproperlyConfigured,
     194            "'FieldsetBookAdmin.fieldsets\[1\]\[1\]\['fields'\]' can't include the ManyToManyField field 'authors' because 'authors' manually specifies a 'through' model.",
    202195            validate,
    203196            FieldsetBookAdmin, Book)
    204197
  • 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')
     
    4235        self.assertEqual(self.a1, Author.objects.get(first_name__exact='John'))
    4336
    4437    def test_filter_on_nonexistant_field(self):
    45         self.assertRaisesMessage(
     38        self.assertRaisesRegexp(
    4639            FieldError,
    4740            "Cannot resolve keyword 'firstname' into field. Choices are: Author_ID, article, first_name, last_name, primary_set",
    4841            Author.objects.filter,
     
    5346        a = Author.objects.get(last_name__exact='Smith')
    5447        self.assertEqual('John', a.first_name)
    5548        self.assertEqual('Smith', a.last_name)
    56         self.assertRaisesMessage(
     49        self.assertRaisesRegexp(
    5750            AttributeError,
    5851            "'Author' object has no attribute 'firstname'",
    5952            getattr,
    6053            a, 'firstname'
    6154        )
    6255
    63         self.assertRaisesMessage(
     56        self.assertRaisesRegexp(
    6457            AttributeError,
    6558            "'Author' object has no attribute 'last'",
    6659            getattr,
  • tests/regressiontests/file_storage/tests.py

    diff --git a/tests/regressiontests/file_storage/tests.py b/tests/regressiontests/file_storage/tests.py
    a b  
    1313from django.core.files.storage import FileSystemStorage, get_storage_class
    1414from django.core.files.uploadedfile import UploadedFile
    1515from django.core.exceptions import ImproperlyConfigured
     16#from django.test import TestCase
    1617from django.utils import unittest
    1718
    1819try:
     
    3233        Image = None
    3334
    3435class GetStorageClassTests(unittest.TestCase):
    35     def assertRaisesErrorWithMessage(self, error, message, callable,
    36         *args, **kwargs):
    37         self.assertRaises(error, callable, *args, **kwargs)
    38         try:
    39             callable(*args, **kwargs)
    40         except error, e:
    41             self.assertEqual(message, str(e))
    42 
    4336    def test_get_filesystem_storage(self):
    4437        """
    4538        get_storage_class returns the class for a storage backend name/path.
     
    5245        """
    5346        get_storage_class raises an error if the requested import don't exist.
    5447        """
    55         self.assertRaisesErrorWithMessage(
     48        self.assertRaisesRegexp(
    5649            ImproperlyConfigured,
    5750            "NonExistingStorage isn't a storage module.",
    5851            get_storage_class,
     
    6255        """
    6356        get_storage_class raises an error if the requested class don't exist.
    6457        """
    65         self.assertRaisesErrorWithMessage(
     58        self.assertRaisesRegexp(
    6659            ImproperlyConfigured,
    6760            'Storage module "django.core.files.storage" does not define a '\
    6861                '"NonExistingStorage" class.',
     
    7366        """
    7467        get_storage_class raises an error if the requested module don't exist.
    7568        """
    76         self.assertRaisesErrorWithMessage(
     69        self.assertRaisesRegexp(
    7770            ImproperlyConfigured,
    7871            'Error importing storage module django.core.files.non_existing_'\
    7972                'storage: "No module named non_existing_storage"',
  • tests/regressiontests/fixtures_regress/tests.py

    diff --git a/tests/regressiontests/fixtures_regress/tests.py b/tests/regressiontests/fixtures_regress/tests.py
    a b  
    343343
    344344
    345345class NaturalKeyFixtureTests(TestCase):
    346     def assertRaisesMessage(self, exc, msg, func, *args, **kwargs):
    347         try:
    348             func(*args, **kwargs)
    349         except Exception, e:
    350             self.assertEqual(msg, str(e))
    351             self.assertTrue(isinstance(e, exc), "Expected %s, got %s" % (exc, type(e)))
    352 
    353346    def test_nk_deserialize(self):
    354347        """
    355348        Test for ticket #13030 - Python based parser version
     
    507500        )
    508501
    509502    def test_dependency_sorting_tight_circular(self):
    510         self.assertRaisesMessage(
     503        self.assertRaisesRegexp(
    511504            CommandError,
    512505            """Can't resolve dependencies for fixtures_regress.Circle1, fixtures_regress.Circle2 in serialized app list.""",
    513506            sort_dependencies,
     
    515508        )
    516509
    517510    def test_dependency_sorting_tight_circular_2(self):
    518         self.assertRaisesMessage(
     511        self.assertRaisesRegexp(
    519512            CommandError,
    520513            """Can't resolve dependencies for fixtures_regress.Circle1, fixtures_regress.Circle2 in serialized app list.""",
    521514            sort_dependencies,
     
    523516        )
    524517
    525518    def test_dependency_self_referential(self):
    526         self.assertRaisesMessage(
     519        self.assertRaisesRegexp(
    527520            CommandError,
    528521            """Can't resolve dependencies for fixtures_regress.Circle3 in serialized app list.""",
    529522            sort_dependencies,
     
    531524        )
    532525
    533526    def test_dependency_sorting_long(self):
    534         self.assertRaisesMessage(
     527        self.assertRaisesRegexp(
    535528            CommandError,
    536529            """Can't resolve dependencies for fixtures_regress.Circle1, fixtures_regress.Circle2, fixtures_regress.Circle3 in serialized app list.""",
    537530            sort_dependencies,
  • tests/regressiontests/forms/fields.py

    diff --git a/tests/regressiontests/forms/fields.py b/tests/regressiontests/forms/fields.py
    a b  
    4949
    5050class FieldsTests(TestCase):
    5151
    52     def assertRaisesErrorWithMessage(self, error, message, callable, *args, **kwargs):
    53         self.assertRaises(error, callable, *args, **kwargs)
    54         try:
    55             callable(*args, **kwargs)
    56         except error, e:
    57             self.assertEqual(message, str(e))
    58 
    5952    def test_field_sets_widget_is_required(self):
    6053        self.assertEqual(Field(required=True).widget.is_required, True)
    6154        self.assertEqual(Field(required=False).widget.is_required, False)
     
    6659        f = CharField()
    6760        self.assertEqual(u'1', f.clean(1))
    6861        self.assertEqual(u'hello', f.clean('hello'))
    69         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
    70         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
     62        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, None)
     63        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, '')
    7164        self.assertEqual(u'[1, 2, 3]', f.clean([1, 2, 3]))
    7265
    7366    def test_charfield_1(self):
     
    8275        f = CharField(max_length=10, required=False)
    8376        self.assertEqual(u'12345', f.clean('12345'))
    8477        self.assertEqual(u'1234567890', f.clean('1234567890'))
    85         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value has at most 10 characters (it has 11).']", f.clean, '1234567890a')
     78        self.assertRaisesRegexp(ValidationError, "u'Ensure this value has at most 10 characters \(it has 11\).'", f.clean, '1234567890a')
    8679
    8780    def test_charfield_3(self):
    8881        f = CharField(min_length=10, required=False)
    8982        self.assertEqual(u'', f.clean(''))
    90         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value has at least 10 characters (it has 5).']", f.clean, '12345')
     83        self.assertRaisesRegexp(ValidationError, "u'Ensure this value has at least 10 characters \(it has 5\).'", f.clean, '12345')
    9184        self.assertEqual(u'1234567890', f.clean('1234567890'))
    9285        self.assertEqual(u'1234567890a', f.clean('1234567890a'))
    9386
    9487    def test_charfield_4(self):
    9588        f = CharField(min_length=10, required=True)
    96         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
    97         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value has at least 10 characters (it has 5).']", f.clean, '12345')
     89        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, '')
     90        self.assertRaisesRegexp(ValidationError, "u'Ensure this value has at least 10 characters \(it has 5\).'", f.clean, '12345')
    9891        self.assertEqual(u'1234567890', f.clean('1234567890'))
    9992        self.assertEqual(u'1234567890a', f.clean('1234567890a'))
    10093
     
    10295
    10396    def test_integerfield_5(self):
    10497        f = IntegerField()
    105         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
    106         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
     98        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, '')
     99        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, None)
    107100        self.assertEqual(1, f.clean('1'))
    108101        self.assertEqual(True, isinstance(f.clean('1'), int))
    109102        self.assertEqual(23, f.clean('23'))
    110         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a whole number.']", f.clean, 'a')
     103        self.assertRaisesRegexp(ValidationError, "u'Enter a whole number.'", f.clean, 'a')
    111104        self.assertEqual(42, f.clean(42))
    112         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a whole number.']", f.clean, 3.14)
     105        self.assertRaisesRegexp(ValidationError, "u'Enter a whole number.'", f.clean, 3.14)
    113106        self.assertEqual(1, f.clean('1 '))
    114107        self.assertEqual(1, f.clean(' 1'))
    115108        self.assertEqual(1, f.clean(' 1 '))
    116         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a whole number.']", f.clean, '1a')
     109        self.assertRaisesRegexp(ValidationError, "u'Enter a whole number.'", f.clean, '1a')
    117110
    118111    def test_integerfield_6(self):
    119112        f = IntegerField(required=False)
     
    124117        self.assertEqual(1, f.clean('1'))
    125118        self.assertEqual(True, isinstance(f.clean('1'), int))
    126119        self.assertEqual(23, f.clean('23'))
    127         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a whole number.']", f.clean, 'a')
     120        self.assertRaisesRegexp(ValidationError, "u'Enter a whole number.'", f.clean, 'a')
    128121        self.assertEqual(1, f.clean('1 '))
    129122        self.assertEqual(1, f.clean(' 1'))
    130123        self.assertEqual(1, f.clean(' 1 '))
    131         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a whole number.']", f.clean, '1a')
     124        self.assertRaisesRegexp(ValidationError, "u'Enter a whole number.'", f.clean, '1a')
    132125
    133126    def test_integerfield_7(self):
    134127        f = IntegerField(max_value=10)
    135         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
     128        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, None)
    136129        self.assertEqual(1, f.clean(1))
    137130        self.assertEqual(10, f.clean(10))
    138         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value is less than or equal to 10.']", f.clean, 11)
     131        self.assertRaisesRegexp(ValidationError, "u'Ensure this value is less than or equal to 10.'", f.clean, 11)
    139132        self.assertEqual(10, f.clean('10'))
    140         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value is less than or equal to 10.']", f.clean, '11')
     133        self.assertRaisesRegexp(ValidationError, "u'Ensure this value is less than or equal to 10.'", f.clean, '11')
    141134
    142135    def test_integerfield_8(self):
    143136        f = IntegerField(min_value=10)
    144         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
    145         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value is greater than or equal to 10.']", f.clean, 1)
     137        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, None)
     138        self.assertRaisesRegexp(ValidationError, "u'Ensure this value is greater than or equal to 10.'", f.clean, 1)
    146139        self.assertEqual(10, f.clean(10))
    147140        self.assertEqual(11, f.clean(11))
    148141        self.assertEqual(10, f.clean('10'))
     
    150143
    151144    def test_integerfield_9(self):
    152145        f = IntegerField(min_value=10, max_value=20)
    153         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
    154         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value is greater than or equal to 10.']", f.clean, 1)
     146        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, None)
     147        self.assertRaisesRegexp(ValidationError, "u'Ensure this value is greater than or equal to 10.'", f.clean, 1)
    155148        self.assertEqual(10, f.clean(10))
    156149        self.assertEqual(11, f.clean(11))
    157150        self.assertEqual(10, f.clean('10'))
    158151        self.assertEqual(11, f.clean('11'))
    159152        self.assertEqual(20, f.clean(20))
    160         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value is less than or equal to 20.']", f.clean, 21)
     153        self.assertRaisesRegexp(ValidationError, "u'Ensure this value is less than or equal to 20.'", f.clean, 21)
    161154
    162155    # FloatField ##################################################################
    163156
    164157    def test_floatfield_10(self):
    165158        f = FloatField()
    166         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
    167         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
     159        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, '')
     160        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, None)
    168161        self.assertEqual(1.0, f.clean('1'))
    169162        self.assertEqual(True, isinstance(f.clean('1'), float))
    170163        self.assertEqual(23.0, f.clean('23'))
    171164        self.assertEqual(3.1400000000000001, f.clean('3.14'))
    172165        self.assertEqual(3.1400000000000001, f.clean(3.14))
    173166        self.assertEqual(42.0, f.clean(42))
    174         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a number.']", f.clean, 'a')
     167        self.assertRaisesRegexp(ValidationError, "u'Enter a number.'", f.clean, 'a')
    175168        self.assertEqual(1.0, f.clean('1.0 '))
    176169        self.assertEqual(1.0, f.clean(' 1.0'))
    177170        self.assertEqual(1.0, f.clean(' 1.0 '))
    178         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a number.']", f.clean, '1.0a')
     171        self.assertRaisesRegexp(ValidationError, "u'Enter a number.'", f.clean, '1.0a')
    179172
    180173    def test_floatfield_11(self):
    181174        f = FloatField(required=False)
     
    185178
    186179    def test_floatfield_12(self):
    187180        f = FloatField(max_value=1.5, min_value=0.5)
    188         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value is less than or equal to 1.5.']", f.clean, '1.6')
    189         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value is greater than or equal to 0.5.']", f.clean, '0.4')
     181        self.assertRaisesRegexp(ValidationError, "u'Ensure this value is less than or equal to 1.5.'", f.clean, '1.6')
     182        self.assertRaisesRegexp(ValidationError, "u'Ensure this value is greater than or equal to 0.5.'", f.clean, '0.4')
    190183        self.assertEqual(1.5, f.clean('1.5'))
    191184        self.assertEqual(0.5, f.clean('0.5'))
    192185
     
    194187
    195188    def test_decimalfield_13(self):
    196189        f = DecimalField(max_digits=4, decimal_places=2)
    197         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
    198         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
     190        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, '')
     191        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, None)
    199192        self.assertEqual(f.clean('1'), Decimal("1"))
    200193        self.assertEqual(True, isinstance(f.clean('1'), Decimal))
    201194        self.assertEqual(f.clean('23'), Decimal("23"))
    202195        self.assertEqual(f.clean('3.14'), Decimal("3.14"))
    203196        self.assertEqual(f.clean(3.14), Decimal("3.14"))
    204197        self.assertEqual(f.clean(Decimal('3.14')), Decimal("3.14"))
    205         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a number.']", f.clean, 'NaN')
    206         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a number.']", f.clean, 'Inf')
    207         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a number.']", f.clean, '-Inf')
    208         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a number.']", f.clean, 'a')
    209         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a number.']", f.clean, u'łąść')
     198        self.assertRaisesRegexp(ValidationError, "u'Enter a number.'", f.clean, 'NaN')
     199        self.assertRaisesRegexp(ValidationError, "u'Enter a number.'", f.clean, 'Inf')
     200        self.assertRaisesRegexp(ValidationError, "u'Enter a number.'", f.clean, '-Inf')
     201        self.assertRaisesRegexp(ValidationError, "u'Enter a number.'", f.clean, 'a')
     202        self.assertRaisesRegexp(ValidationError, "u'Enter a number.'", f.clean, u'łąść')
    210203        self.assertEqual(f.clean('1.0 '), Decimal("1.0"))
    211204        self.assertEqual(f.clean(' 1.0'), Decimal("1.0"))
    212205        self.assertEqual(f.clean(' 1.0 '), Decimal("1.0"))
    213         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a number.']", f.clean, '1.0a')
    214         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure that there are no more than 4 digits in total.']", f.clean, '123.45')
    215         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure that there are no more than 2 decimal places.']", f.clean, '1.234')
    216         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure that there are no more than 2 digits before the decimal point.']", f.clean, '123.4')
     206        self.assertRaisesRegexp(ValidationError, "u'Enter a number.'", f.clean, '1.0a')
     207        self.assertRaisesRegexp(ValidationError, "u'Ensure that there are no more than 4 digits in total.'", f.clean, '123.45')
     208        self.assertRaisesRegexp(ValidationError, "u'Ensure that there are no more than 2 decimal places.'", f.clean, '1.234')
     209        self.assertRaisesRegexp(ValidationError, "u'Ensure that there are no more than 2 digits before the decimal point.'", f.clean, '123.4')
    217210        self.assertEqual(f.clean('-12.34'), Decimal("-12.34"))
    218         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure that there are no more than 4 digits in total.']", f.clean, '-123.45')
     211        self.assertRaisesRegexp(ValidationError, "u'Ensure that there are no more than 4 digits in total.'", f.clean, '-123.45')
    219212        self.assertEqual(f.clean('-.12'), Decimal("-0.12"))
    220213        self.assertEqual(f.clean('-00.12'), Decimal("-0.12"))
    221214        self.assertEqual(f.clean('-000.12'), Decimal("-0.12"))
    222         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure that there are no more than 2 decimal places.']", f.clean, '-000.123')
    223         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure that there are no more than 4 digits in total.']", f.clean, '-000.12345')
    224         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a number.']", f.clean, '--0.12')
     215        self.assertRaisesRegexp(ValidationError, "u'Ensure that there are no more than 2 decimal places.'", f.clean, '-000.123')
     216        self.assertRaisesRegexp(ValidationError, "u'Ensure that there are no more than 4 digits in total.'", f.clean, '-000.12345')
     217        self.assertRaisesRegexp(ValidationError, "u'Enter a number.'", f.clean, '--0.12')
    225218
    226219    def test_decimalfield_14(self):
    227220        f = DecimalField(max_digits=4, decimal_places=2, required=False)
     
    231224
    232225    def test_decimalfield_15(self):
    233226        f = DecimalField(max_digits=4, decimal_places=2, max_value=Decimal('1.5'), min_value=Decimal('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.assertRaisesRegexp(ValidationError, "u'Ensure this value is less than or equal to 1.5.'", f.clean, '1.6')
     228        self.assertRaisesRegexp(ValidationError, "u'Ensure this value is greater than or equal to 0.5.'", f.clean, '0.4')
    236229        self.assertEqual(f.clean('1.5'), Decimal("1.5"))
    237230        self.assertEqual(f.clean('0.5'), Decimal("0.5"))
    238231        self.assertEqual(f.clean('.5'), Decimal("0.5"))
     
    240233
    241234    def test_decimalfield_16(self):
    242235        f = DecimalField(decimal_places=2)
    243         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure that there are no more than 2 decimal places.']", f.clean, '0.00000001')
     236        self.assertRaisesRegexp(ValidationError, "u'Ensure that there are no more than 2 decimal places.'", f.clean, '0.00000001')
    244237
    245238    def test_decimalfield_17(self):
    246239        f = DecimalField(max_digits=3)
     
    250243        self.assertEqual(f.clean('0000000.100'), Decimal("0.100"))
    251244        # Only leading whole zeros "collapse" to one digit.
    252245        self.assertEqual(f.clean('000000.02'), Decimal('0.02'))
    253         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure that there are no more than 3 digits in total.']", f.clean, '000000.0002')
     246        self.assertRaisesRegexp(ValidationError, "u'Ensure that there are no more than 3 digits in total.'", f.clean, '000000.0002')
    254247        self.assertEqual(f.clean('.002'), Decimal("0.002"))
    255248
    256249    def test_decimalfield_18(self):
    257250        f = DecimalField(max_digits=2, decimal_places=2)
    258251        self.assertEqual(f.clean('.01'), Decimal(".01"))
    259         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure that there are no more than 0 digits before the decimal point.']", f.clean, '1.1')
     252        self.assertRaisesRegexp(ValidationError, "u'Ensure that there are no more than 0 digits before the decimal point.'", f.clean, '1.1')
    260253
    261254    # DateField ###################################################################
    262255
     
    274267        self.assertEqual(datetime.date(2006, 10, 25), f.clean('October 25, 2006'))
    275268        self.assertEqual(datetime.date(2006, 10, 25), f.clean('25 October 2006'))
    276269        self.assertEqual(datetime.date(2006, 10, 25), f.clean('25 October, 2006'))
    277         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid date.']", f.clean, '2006-4-31')
    278         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid date.']", f.clean, '200a-10-25')
    279         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid date.']", f.clean, '25/10/06')
    280         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
     270        self.assertRaisesRegexp(ValidationError, "u'Enter a valid date.'", f.clean, '2006-4-31')
     271        self.assertRaisesRegexp(ValidationError, "u'Enter a valid date.'", f.clean, '200a-10-25')
     272        self.assertRaisesRegexp(ValidationError, "u'Enter a valid date.'", f.clean, '25/10/06')
     273        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, None)
    281274
    282275    def test_datefield_20(self):
    283276        f = DateField(required=False)
     
    291284        self.assertEqual(datetime.date(2006, 10, 25), f.clean(datetime.date(2006, 10, 25)))
    292285        self.assertEqual(datetime.date(2006, 10, 25), f.clean(datetime.datetime(2006, 10, 25, 14, 30)))
    293286        self.assertEqual(datetime.date(2006, 10, 25), f.clean('2006 10 25'))
    294         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid date.']", f.clean, '2006-10-25')
    295         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid date.']", f.clean, '10/25/2006')
    296         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid date.']", f.clean, '10/25/06')
     287        self.assertRaisesRegexp(ValidationError, "u'Enter a valid date.'", f.clean, '2006-10-25')
     288        self.assertRaisesRegexp(ValidationError, "u'Enter a valid date.'", f.clean, '10/25/2006')
     289        self.assertRaisesRegexp(ValidationError, "u'Enter a valid date.'", f.clean, '10/25/06')
    297290
    298291    # TimeField ###################################################################
    299292
     
    303296        self.assertEqual(datetime.time(14, 25, 59), f.clean(datetime.time(14, 25, 59)))
    304297        self.assertEqual(datetime.time(14, 25), f.clean('14:25'))
    305298        self.assertEqual(datetime.time(14, 25, 59), f.clean('14:25:59'))
    306         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid time.']", f.clean, 'hello')
    307         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid time.']", f.clean, '1:24 p.m.')
     299        self.assertRaisesRegexp(ValidationError, "u'Enter a valid time.'", f.clean, 'hello')
     300        self.assertRaisesRegexp(ValidationError, "u'Enter a valid time.'", f.clean, '1:24 p.m.')
    308301
    309302    def test_timefield_23(self):
    310303        f = TimeField(input_formats=['%I:%M %p'])
     
    312305        self.assertEqual(datetime.time(14, 25, 59), f.clean(datetime.time(14, 25, 59)))
    313306        self.assertEqual(datetime.time(4, 25), f.clean('4:25 AM'))
    314307        self.assertEqual(datetime.time(16, 25), f.clean('4:25 PM'))
    315         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid time.']", f.clean, '14:30:45')
     308        self.assertRaisesRegexp(ValidationError, "u'Enter a valid time.'", f.clean, '14:30:45')
    316309
    317310    # DateTimeField ###############################################################
    318311
     
    334327        self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30), f.clean('10/25/06 14:30:00'))
    335328        self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30), f.clean('10/25/06 14:30'))
    336329        self.assertEqual(datetime.datetime(2006, 10, 25, 0, 0), f.clean('10/25/06'))
    337         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid date/time.']", f.clean, 'hello')
    338         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid date/time.']", f.clean, '2006-10-25 4:30 p.m.')
     330        self.assertRaisesRegexp(ValidationError, "u'Enter a valid date/time.'", f.clean, 'hello')
     331        self.assertRaisesRegexp(ValidationError, "u'Enter a valid date/time.'", f.clean, '2006-10-25 4:30 p.m.')
    339332
    340333    def test_datetimefield_25(self):
    341334        f = DateTimeField(input_formats=['%Y %m %d %I:%M %p'])
     
    344337        self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30, 59), f.clean(datetime.datetime(2006, 10, 25, 14, 30, 59)))
    345338        self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30, 59, 200), f.clean(datetime.datetime(2006, 10, 25, 14, 30, 59, 200)))
    346339        self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30), f.clean('2006 10 25 2:30 PM'))
    347         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid date/time.']", f.clean, '2006-10-25 14:30:45')
     340        self.assertRaisesRegexp(ValidationError, "u'Enter a valid date/time.'", f.clean, '2006-10-25 14:30:45')
    348341
    349342    def test_datetimefield_26(self):
    350343        f = DateTimeField(required=False)
     
    359352        f = RegexField('^\d[A-F]\d$')
    360353        self.assertEqual(u'2A2', f.clean('2A2'))
    361354        self.assertEqual(u'3F3', f.clean('3F3'))
    362         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid value.']", f.clean, '3G3')
    363         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid value.']", f.clean, ' 2A2')
    364         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid value.']", f.clean, '2A2 ')
    365         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
     355        self.assertRaisesRegexp(ValidationError, "u'Enter a valid value.'", f.clean, '3G3')
     356        self.assertRaisesRegexp(ValidationError, "u'Enter a valid value.'", f.clean, ' 2A2')
     357        self.assertRaisesRegexp(ValidationError, "u'Enter a valid value.'", f.clean, '2A2 ')
     358        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, '')
    366359
    367360    def test_regexfield_28(self):
    368361        f = RegexField('^\d[A-F]\d$', required=False)
    369362        self.assertEqual(u'2A2', f.clean('2A2'))
    370363        self.assertEqual(u'3F3', f.clean('3F3'))
    371         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid value.']", f.clean, '3G3')
     364        self.assertRaisesRegexp(ValidationError, "u'Enter a valid value.'", f.clean, '3G3')
    372365        self.assertEqual(u'', f.clean(''))
    373366
    374367    def test_regexfield_29(self):
    375368        f = RegexField(re.compile('^\d[A-F]\d$'))
    376369        self.assertEqual(u'2A2', f.clean('2A2'))
    377370        self.assertEqual(u'3F3', f.clean('3F3'))
    378         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid value.']", f.clean, '3G3')
    379         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid value.']", f.clean, ' 2A2')
    380         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid value.']", f.clean, '2A2 ')
     371        self.assertRaisesRegexp(ValidationError, "'Enter a valid value.'", f.clean, '3G3')
     372        self.assertRaisesRegexp(ValidationError, "u'Enter a valid value.'", f.clean, ' 2A2')
     373        self.assertRaisesRegexp(ValidationError, "u'Enter a valid value.'", f.clean, '2A2 ')
    381374
    382375    def test_regexfield_30(self):
    383376        f = RegexField('^\d\d\d\d$', error_message='Enter a four-digit number.')
    384377        self.assertEqual(u'1234', f.clean('1234'))
    385         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a four-digit number.']", f.clean, '123')
    386         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a four-digit number.']", f.clean, 'abcd')
     378        self.assertRaisesRegexp(ValidationError, "u'Enter a four-digit number.'", f.clean, '123')
     379        self.assertRaisesRegexp(ValidationError, "u'Enter a four-digit number.'", f.clean, 'abcd')
    387380
    388381    def test_regexfield_31(self):
    389382        f = RegexField('^\d+$', min_length=5, max_length=10)
    390         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value has at least 5 characters (it has 3).']", f.clean, '123')
    391         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value has at least 5 characters (it has 3).', u'Enter a valid value.']", f.clean, 'abc')
     383        self.assertRaisesRegexp(ValidationError, "u'Ensure this value has at least 5 characters \(it has 3\).'", f.clean, '123')
     384        self.assertRaisesRegexp(ValidationError, "u'Ensure this value has at least 5 characters \(it has 3\).', u'Enter a valid value.'", f.clean, 'abc')
    392385        self.assertEqual(u'12345', f.clean('12345'))
    393386        self.assertEqual(u'1234567890', f.clean('1234567890'))
    394         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value has at most 10 characters (it has 11).']", f.clean, '12345678901')
    395         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid value.']", f.clean, '12345a')
     387        self.assertRaisesRegexp(ValidationError, "u'Ensure this value has at most 10 characters \(it has 11\).'", f.clean, '12345678901')
     388        self.assertRaisesRegexp(ValidationError, "u'Enter a valid value.'", f.clean, '12345a')
    396389
    397390    # EmailField ##################################################################
    398391
    399392    def test_emailfield_32(self):
    400393        f = EmailField()
    401         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
    402         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
     394        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, '')
     395        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, None)
    403396        self.assertEqual(u'person@example.com', f.clean('person@example.com'))
    404         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'foo')
    405         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'foo@')
    406         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'foo@bar')
    407         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'example@invalid-.com')
    408         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'example@-invalid.com')
    409         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'example@inv-.alid-.com')
    410         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'example@inv-.-alid.com')
     397        self.assertRaisesRegexp(ValidationError, "u'Enter a valid e-mail address.'", f.clean, 'foo')
     398        self.assertRaisesRegexp(ValidationError, "u'Enter a valid e-mail address.'", f.clean, 'foo@')
     399        self.assertRaisesRegexp(ValidationError, "u'Enter a valid e-mail address.'", f.clean, 'foo@bar')
     400        self.assertRaisesRegexp(ValidationError, "u'Enter a valid e-mail address.'", f.clean, 'example@invalid-.com')
     401        self.assertRaisesRegexp(ValidationError, "u'Enter a valid e-mail address.'", f.clean, 'example@-invalid.com')
     402        self.assertRaisesRegexp(ValidationError, "u'Enter a valid e-mail address.'", f.clean, 'example@inv-.alid-.com')
     403        self.assertRaisesRegexp(ValidationError, "u'Enter a valid e-mail address.'", f.clean, 'example@inv-.-alid.com')
    411404        self.assertEqual(u'example@valid-----hyphens.com', f.clean('example@valid-----hyphens.com'))
    412405        self.assertEqual(u'example@valid-with-hyphens.com', f.clean('example@valid-with-hyphens.com'))
    413         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'example@.com')
     406        self.assertRaisesRegexp(ValidationError, "u'Enter a valid e-mail address.'", f.clean, 'example@.com')
    414407        self.assertEqual(u'local@domain.with.idn.xyz\xe4\xf6\xfc\xdfabc.part.com', f.clean('local@domain.with.idn.xyzäöüßabc.part.com'))
    415408
    416409    def test_email_regexp_for_performance(self):
    417410        f = EmailField()
    418411        # Check for runaway regex security problem. This will take for-freeking-ever
    419412        # if the security fix isn't in place.
    420         self.assertRaisesErrorWithMessage(
     413        self.assertRaisesRegexp(
    421414                ValidationError,
    422                 "[u'Enter a valid e-mail address.']",
     415                "u'Enter a valid e-mail address.'",
    423416                f.clean,
    424417                'viewx3dtextx26qx3d@yahoo.comx26latlngx3d15854521645943074058'
    425418            )
     
    430423        self.assertEqual(u'', f.clean(None))
    431424        self.assertEqual(u'person@example.com', f.clean('person@example.com'))
    432425        self.assertEqual(u'example@example.com', f.clean('      example@example.com  \t   \t '))
    433         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'foo')
    434         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'foo@')
    435         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'foo@bar')
     426        self.assertRaisesRegexp(ValidationError, "u'Enter a valid e-mail address.'", f.clean, 'foo')
     427        self.assertRaisesRegexp(ValidationError, "u'Enter a valid e-mail address.'", f.clean, 'foo@')
     428        self.assertRaisesRegexp(ValidationError, "u'Enter a valid e-mail address.'", f.clean, 'foo@bar')
    436429
    437430    def test_emailfield_34(self):
    438431        f = EmailField(min_length=10, max_length=15)
    439         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value has at least 10 characters (it has 9).']", f.clean, 'a@foo.com')
     432        self.assertRaisesRegexp(ValidationError, "u'Ensure this value has at least 10 characters \(it has 9\).'", f.clean, 'a@foo.com')
    440433        self.assertEqual(u'alf@foo.com', f.clean('alf@foo.com'))
    441         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value has at most 15 characters (it has 20).']", f.clean, 'alf123456788@foo.com')
     434        self.assertRaisesRegexp(ValidationError, "u'Ensure this value has at most 15 characters \(it has 20\).'", f.clean, 'alf123456788@foo.com')
    442435
    443436    # FileField ##################################################################
    444437
    445438    def test_filefield_35(self):
    446439        f = FileField()
    447         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
    448         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '', '')
     440        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, '')
     441        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, '', '')
    449442        self.assertEqual('files/test1.pdf', f.clean('', 'files/test1.pdf'))
    450         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
    451         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None, '')
     443        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, None)
     444        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, None, '')
    452445        self.assertEqual('files/test2.pdf', f.clean(None, 'files/test2.pdf'))
    453         self.assertRaisesErrorWithMessage(ValidationError, "[u'No file was submitted. Check the encoding type on the form.']", f.clean, SimpleUploadedFile('', ''))
    454         self.assertRaisesErrorWithMessage(ValidationError, "[u'No file was submitted. Check the encoding type on the form.']", f.clean, SimpleUploadedFile('', ''), '')
     446        self.assertRaisesRegexp(ValidationError, "u'No file was submitted. Check the encoding type on the form.'", f.clean, SimpleUploadedFile('', ''))
     447        self.assertRaisesRegexp(ValidationError, "u'No file was submitted. Check the encoding type on the form.'", f.clean, SimpleUploadedFile('', ''), '')
    455448        self.assertEqual('files/test3.pdf', f.clean(None, 'files/test3.pdf'))
    456         self.assertRaisesErrorWithMessage(ValidationError, "[u'No file was submitted. Check the encoding type on the form.']", f.clean, 'some content that is not a file')
    457         self.assertRaisesErrorWithMessage(ValidationError, "[u'The submitted file is empty.']", f.clean, SimpleUploadedFile('name', None))
    458         self.assertRaisesErrorWithMessage(ValidationError, "[u'The submitted file is empty.']", f.clean, SimpleUploadedFile('name', ''))
     449        self.assertRaisesRegexp(ValidationError, "u'No file was submitted. Check the encoding type on the form.'", f.clean, 'some content that is not a file')
     450        self.assertRaisesRegexp(ValidationError, "u'The submitted file is empty.'", f.clean, SimpleUploadedFile('name', None))
     451        self.assertRaisesRegexp(ValidationError, "u'The submitted file is empty.'", f.clean, SimpleUploadedFile('name', ''))
    459452        self.assertEqual(SimpleUploadedFile, type(f.clean(SimpleUploadedFile('name', 'Some File Content'))))
    460453        self.assertEqual(SimpleUploadedFile, type(f.clean(SimpleUploadedFile('我隻氣墊船裝滿晒鱔.txt', 'मेरी मँडराने वाली नाव सर्पमीनों से भरी ह'))))
    461454        self.assertEqual(SimpleUploadedFile, type(f.clean(SimpleUploadedFile('name', 'Some File Content'), 'files/test4.pdf')))
    462455
    463456    def test_filefield_36(self):
    464457        f = FileField(max_length = 5)
    465         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this filename has at most 5 characters (it has 18).']", f.clean, SimpleUploadedFile('test_maxlength.txt', 'hello world'))
     458        self.assertRaisesRegexp(ValidationError, "u'Ensure this filename has at most 5 characters \(it has 18\).'", f.clean, SimpleUploadedFile('test_maxlength.txt', 'hello world'))
    466459        self.assertEqual('files/test1.pdf', f.clean('', 'files/test1.pdf'))
    467460        self.assertEqual('files/test2.pdf', f.clean(None, 'files/test2.pdf'))
    468461        self.assertEqual(SimpleUploadedFile, type(f.clean(SimpleUploadedFile('name', 'Some File Content'))))
     
    471464
    472465    def test_urlfield_37(self):
    473466        f = URLField()
    474         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
    475         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
     467        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, '')
     468        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, None)
    476469        self.assertEqual(u'http://localhost/', f.clean('http://localhost'))
    477470        self.assertEqual(u'http://example.com/', f.clean('http://example.com'))
    478471        self.assertEqual(u'http://example.com./', f.clean('http://example.com.'))
     
    482475        self.assertEqual(u'http://subdomain.domain.com/', f.clean('subdomain.domain.com'))
    483476        self.assertEqual(u'http://200.8.9.10/', f.clean('http://200.8.9.10'))
    484477        self.assertEqual(u'http://200.8.9.10:8000/test', f.clean('http://200.8.9.10:8000/test'))
    485         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'foo')
    486         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://')
    487         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://example')
    488         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://example.')
    489         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'com.')
    490         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, '.')
    491         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://.com')
    492         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://invalid-.com')
    493         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://-invalid.com')
    494         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://inv-.alid-.com')
    495         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://inv-.-alid.com')
     478        self.assertRaisesRegexp(ValidationError, "u'Enter a valid URL.'", f.clean, 'foo')
     479        self.assertRaisesRegexp(ValidationError, "u'Enter a valid URL.'", f.clean, 'http://')
     480        self.assertRaisesRegexp(ValidationError, "u'Enter a valid URL.'", f.clean, 'http://example')
     481        self.assertRaisesRegexp(ValidationError, "u'Enter a valid URL.'", f.clean, 'http://example.')
     482        self.assertRaisesRegexp(ValidationError, "u'Enter a valid URL.'", f.clean, 'com.')
     483        self.assertRaisesRegexp(ValidationError, "u'Enter a valid URL.'", f.clean, '.')
     484        self.assertRaisesRegexp(ValidationError, "u'Enter a valid URL.'", f.clean, 'http://.com')
     485        self.assertRaisesRegexp(ValidationError, "u'Enter a valid URL.'", f.clean, 'http://invalid-.com')
     486        self.assertRaisesRegexp(ValidationError, "u'Enter a valid URL.'", f.clean, 'http://-invalid.com')
     487        self.assertRaisesRegexp(ValidationError, "u'Enter a valid URL.'", f.clean, 'http://inv-.alid-.com')
     488        self.assertRaisesRegexp(ValidationError, "u'Enter a valid URL.'", f.clean, 'http://inv-.-alid.com')
    496489        self.assertEqual(u'http://valid-----hyphens.com/', f.clean('http://valid-----hyphens.com'))
    497490        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'))
    498491
    499492    def test_url_regex_ticket11198(self):
    500493        f = URLField()
    501494        # hangs "forever" if catastrophic backtracking in ticket:#11198 not fixed
    502         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://%s' % ("X"*200,))
     495        self.assertRaisesRegexp(ValidationError, "u'Enter a valid URL.'", f.clean, 'http://%s' % ("X"*200,))
    503496
    504497        # a second test, to make sure the problem is really addressed, even on
    505498        # domains that don't fail the domain label length check in the regex
    506         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://%s' % ("X"*60,))
     499        self.assertRaisesRegexp(ValidationError, "u'Enter a valid URL.'", f.clean, 'http://%s' % ("X"*60,))
    507500
    508501    def test_urlfield_38(self):
    509502        f = URLField(required=False)
     
    511504        self.assertEqual(u'', f.clean(None))
    512505        self.assertEqual(u'http://example.com/', f.clean('http://example.com'))
    513506        self.assertEqual(u'http://www.example.com/', f.clean('http://www.example.com'))
    514         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'foo')
    515         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://')
    516         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://example')
    517         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://example.')
    518         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://.com')
     507        self.assertRaisesRegexp(ValidationError, "u'Enter a valid URL.'", f.clean, 'foo')
     508        self.assertRaisesRegexp(ValidationError, "u'Enter a valid URL.'", f.clean, 'http://')
     509        self.assertRaisesRegexp(ValidationError, "u'Enter a valid URL.'", f.clean, 'http://example')
     510        self.assertRaisesRegexp(ValidationError, "u'Enter a valid URL.'", f.clean, 'http://example.')
     511        self.assertRaisesRegexp(ValidationError, "u'Enter a valid URL.'", f.clean, 'http://.com')
    519512
    520513    def test_urlfield_39(self):
    521514        f = URLField(verify_exists=True)
    522515        self.assertEqual(u'http://www.google.com/', f.clean('http://www.google.com')) # This will fail if there's no Internet connection
    523         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://example')
     516        self.assertRaisesRegexp(ValidationError, "u'Enter a valid URL.'", f.clean, 'http://example')
    524517        self.assertRaises(ValidationError, f.clean, 'http://www.broken.djangoproject.com') # bad domain
    525518        try:
    526519            f.clean('http://www.broken.djangoproject.com') # bad domain
     
    546539
    547540    def test_urlfield_41(self):
    548541        f = URLField(min_length=15, max_length=20)
    549         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value has at least 15 characters (it has 13).']", f.clean, 'http://f.com')
     542        self.assertRaisesRegexp(ValidationError, "u'Ensure this value has at least 15 characters \(it has 13\).'", f.clean, 'http://f.com')
    550543        self.assertEqual(u'http://example.com/', f.clean('http://example.com'))
    551         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value has at most 20 characters (it has 38).']", f.clean, 'http://abcdefghijklmnopqrstuvwxyz.com')
     544        self.assertRaisesRegexp(ValidationError, "u'Ensure this value has at most 20 characters \(it has 38\).'", f.clean, 'http://abcdefghijklmnopqrstuvwxyz.com')
    552545
    553546    def test_urlfield_42(self):
    554547        f = URLField(required=False)
     
    569562
    570563    def test_booleanfield_44(self):
    571564        f = BooleanField()
    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.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, '')
     566        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, None)
    574567        self.assertEqual(True, f.clean(True))
    575         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, False)
     568        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, False)
    576569        self.assertEqual(True, f.clean(1))
    577         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, 0)
     570        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, 0)
    578571        self.assertEqual(True, f.clean('Django rocks'))
    579572        self.assertEqual(True, f.clean('True'))
    580         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, 'False')
     573        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, 'False')
    581574
    582575    def test_booleanfield_45(self):
    583576        f = BooleanField(required=False)
     
    596589
    597590    def test_choicefield_46(self):
    598591        f = ChoiceField(choices=[('1', 'One'), ('2', 'Two')])
    599         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
    600         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
     592        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, '')
     593        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, None)
    601594        self.assertEqual(u'1', f.clean(1))
    602595        self.assertEqual(u'1', f.clean('1'))
    603         self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. 3 is not one of the available choices.']", f.clean, '3')
     596        self.assertRaisesRegexp(ValidationError, "u'Select a valid choice. 3 is not one of the available choices.'", f.clean, '3')
    604597
    605598    def test_choicefield_47(self):
    606599        f = ChoiceField(choices=[('1', 'One'), ('2', 'Two')], required=False)
     
    608601        self.assertEqual(u'', f.clean(None))
    609602        self.assertEqual(u'1', f.clean(1))
    610603        self.assertEqual(u'1', f.clean('1'))
    611         self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. 3 is not one of the available choices.']", f.clean, '3')
     604        self.assertRaisesRegexp(ValidationError, "u'Select a valid choice. 3 is not one of the available choices.'", f.clean, '3')
    612605
    613606    def test_choicefield_48(self):
    614607        f = ChoiceField(choices=[('J', 'John'), ('P', 'Paul')])
    615608        self.assertEqual(u'J', f.clean('J'))
    616         self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. John is not one of the available choices.']", f.clean, 'John')
     609        self.assertRaisesRegexp(ValidationError, "u'Select a valid choice. John is not one of the available choices.'", f.clean, 'John')
    617610
    618611    def test_choicefield_49(self):
    619612        f = ChoiceField(choices=[('Numbers', (('1', 'One'), ('2', 'Two'))), ('Letters', (('3','A'),('4','B'))), ('5','Other')])
     
    623616        self.assertEqual(u'3', f.clean('3'))
    624617        self.assertEqual(u'5', f.clean(5))
    625618        self.assertEqual(u'5', f.clean('5'))
    626         self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. 6 is not one of the available choices.']", f.clean, '6')
     619        self.assertRaisesRegexp(ValidationError, "u'Select a valid choice. 6 is not one of the available choices.'", f.clean, '6')
    627620
    628621    # TypedChoiceField ############################################################
    629622    # TypedChoiceField is just like ChoiceField, except that coerced types will
     
    632625    def test_typedchoicefield_50(self):
    633626        f = TypedChoiceField(choices=[(1, "+1"), (-1, "-1")], coerce=int)
    634627        self.assertEqual(1, f.clean('1'))
    635         self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. 2 is not one of the available choices.']", f.clean, '2')
     628        self.assertRaisesRegexp(ValidationError, "u'Select a valid choice. 2 is not one of the available choices.'", f.clean, '2')
    636629
    637630    def test_typedchoicefield_51(self):
    638631        # Different coercion, same validation.
     
    648641        # Even more weirdness: if you have a valid choice but your coercion function
    649642        # can't coerce, you'll still get a validation error. Don't do this!
    650643        f = TypedChoiceField(choices=[('A', 'A'), ('B', 'B')], coerce=int)
    651         self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. B is not one of the available choices.']", f.clean, 'B')
     644        self.assertRaisesRegexp(ValidationError, "u'Select a valid choice. B is not one of the available choices.'", f.clean, 'B')
    652645        # Required fields require values
    653         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
     646        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, '')
    654647
    655648    def test_typedchoicefield_54(self):
    656649        # Non-required fields aren't required
     
    712705
    713706    def test_multiplechoicefield_60(self):
    714707        f = MultipleChoiceField(choices=[('1', 'One'), ('2', 'Two')])
    715         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
    716         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
     708        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, '')
     709        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, None)
    717710        self.assertEqual([u'1'], f.clean([1]))
    718711        self.assertEqual([u'1'], f.clean(['1']))
    719712        self.assertEqual([u'1', u'2'], f.clean(['1', '2']))
    720713        self.assertEqual([u'1', u'2'], f.clean([1, '2']))
    721714        self.assertEqual([u'1', u'2'], f.clean((1, '2')))
    722         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a list of values.']", f.clean, 'hello')
    723         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, [])
    724         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, ())
    725         self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. 3 is not one of the available choices.']", f.clean, ['3'])
     715        self.assertRaisesRegexp(ValidationError, "u'Enter a list of values.'", f.clean, 'hello')
     716        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, [])
     717        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, ())
     718        self.assertRaisesRegexp(ValidationError, "u'Select a valid choice. 3 is not one of the available choices.'", f.clean, ['3'])
    726719
    727720    def test_multiplechoicefield_61(self):
    728721        f = MultipleChoiceField(choices=[('1', 'One'), ('2', 'Two')], required=False)
     
    733726        self.assertEqual([u'1', u'2'], f.clean(['1', '2']))
    734727        self.assertEqual([u'1', u'2'], f.clean([1, '2']))
    735728        self.assertEqual([u'1', u'2'], f.clean((1, '2')))
    736         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a list of values.']", f.clean, 'hello')
     729        self.assertRaisesRegexp(ValidationError, "u'Enter a list of values.'", f.clean, 'hello')
    737730        self.assertEqual([], f.clean([]))
    738731        self.assertEqual([], f.clean(()))
    739         self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. 3 is not one of the available choices.']", f.clean, ['3'])
     732        self.assertRaisesRegexp(ValidationError, "u'Select a valid choice. 3 is not one of the available choices.'", f.clean, ['3'])
    740733
    741734    def test_multiplechoicefield_62(self):
    742735        f = MultipleChoiceField(choices=[('Numbers', (('1', 'One'), ('2', 'Two'))), ('Letters', (('3','A'),('4','B'))), ('5','Other')])
     
    746739        self.assertEqual([u'1', u'5'], f.clean([1, '5']))
    747740        self.assertEqual([u'1', u'5'], f.clean(['1', 5]))
    748741        self.assertEqual([u'1', u'5'], f.clean(['1', '5']))
    749         self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. 6 is not one of the available choices.']", f.clean, ['6'])
    750         self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. 6 is not one of the available choices.']", f.clean, ['1','6'])
     742        self.assertRaisesRegexp(ValidationError, "u'Select a valid choice. 6 is not one of the available choices.'", f.clean, ['6'])
     743        self.assertRaisesRegexp(ValidationError, "u'Select a valid choice. 6 is not one of the available choices.'", f.clean, ['1','6'])
    751744
    752745    # ComboField ##################################################################
    753746
    754747    def test_combofield_63(self):
    755748        f = ComboField(fields=[CharField(max_length=20), EmailField()])
    756749        self.assertEqual(u'test@example.com', f.clean('test@example.com'))
    757         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value has at most 20 characters (it has 28).']", f.clean, 'longemailaddress@example.com')
    758         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'not an e-mail')
    759         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
    760         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
     750        self.assertRaisesRegexp(ValidationError, "u'Ensure this value has at most 20 characters \(it has 28\).'", f.clean, 'longemailaddress@example.com')
     751        self.assertRaisesRegexp(ValidationError, "u'Enter a valid e-mail address.'", f.clean, 'not an e-mail')
     752        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, '')
     753        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, None)
    761754
    762755    def test_combofield_64(self):
    763756        f = ComboField(fields=[CharField(max_length=20), EmailField()], required=False)
    764757        self.assertEqual(u'test@example.com', f.clean('test@example.com'))
    765         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value has at most 20 characters (it has 28).']", f.clean, 'longemailaddress@example.com')
    766         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'not an e-mail')
     758        self.assertRaisesRegexp(ValidationError, "u'Ensure this value has at most 20 characters \(it has 28\).'", f.clean, 'longemailaddress@example.com')
     759        self.assertRaisesRegexp(ValidationError, "u'Enter a valid e-mail address.'", f.clean, 'not an e-mail')
    767760        self.assertEqual(u'', f.clean(''))
    768761        self.assertEqual(u'', f.clean(None))
    769762
     
    792785        for exp, got in zip(expected, fix_os_paths(f.choices)):
    793786            self.assertEqual(exp[1], got[1])
    794787            self.assertTrue(got[0].endswith(exp[0]))
    795         self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. fields.py is not one of the available choices.']", f.clean, 'fields.py')
     788        self.assertRaisesRegexp(ValidationError, "u'Select a valid choice. fields.py is not one of the available choices.'", f.clean, 'fields.py')
    796789        assert fix_os_paths(f.clean(path + 'fields.py')).endswith('/django/forms/fields.py')
    797790
    798791    def test_filepathfield_67(self):
     
    840833        f = SplitDateTimeField()
    841834        assert isinstance(f.widget, SplitDateTimeWidget)
    842835        self.assertEqual(datetime.datetime(2006, 1, 10, 7, 30), f.clean([datetime.date(2006, 1, 10), datetime.time(7, 30)]))
    843         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
    844         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
    845         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a list of values.']", f.clean, 'hello')
    846         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid date.', u'Enter a valid time.']", f.clean, ['hello', 'there'])
    847         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid time.']", f.clean, ['2006-01-10', 'there'])
    848         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid date.']", f.clean, ['hello', '07:30'])
     836        self.assertRaisesRegexp(ValidationError, "[u'This field is required.']", f.clean, None)
     837        self.assertRaisesRegexp(ValidationError, "[u'This field is required.']", f.clean, '')
     838        self.assertRaisesRegexp(ValidationError, "[u'Enter a list of values.']", f.clean, 'hello')
     839        self.assertRaisesRegexp(ValidationError, "[u'Enter a valid date.', u'Enter a valid time.']", f.clean, ['hello', 'there'])
     840        self.assertRaisesRegexp(ValidationError, "[u'Enter a valid time.']", f.clean, ['2006-01-10', 'there'])
     841        self.assertRaisesRegexp(ValidationError, "[u'Enter a valid date.']", f.clean, ['hello', '07:30'])
    849842
    850843    def test_splitdatetimefield_70(self):
    851844        f = SplitDateTimeField(required=False)
     
    855848        self.assertEqual(None, f.clean(''))
    856849        self.assertEqual(None, f.clean(['']))
    857850        self.assertEqual(None, f.clean(['', '']))
    858         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a list of values.']", f.clean, 'hello')
    859         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid date.', u'Enter a valid time.']", f.clean, ['hello', 'there'])
    860         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid time.']", f.clean, ['2006-01-10', 'there'])
    861         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid date.']", f.clean, ['hello', '07:30'])
    862         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid time.']", f.clean, ['2006-01-10', ''])
    863         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid time.']", f.clean, ['2006-01-10'])
    864         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid date.']", f.clean, ['', '07:30'])
     851        self.assertRaisesRegexp(ValidationError, "u'Enter a list of values.'", f.clean, 'hello')
     852        self.assertRaisesRegexp(ValidationError, "u'Enter a valid date.', u'Enter a valid time.'", f.clean, ['hello', 'there'])
     853        self.assertRaisesRegexp(ValidationError, "u'Enter a valid time.'", f.clean, ['2006-01-10', 'there'])
     854        self.assertRaisesRegexp(ValidationError, "u'Enter a valid date.'", f.clean, ['hello', '07:30'])
     855        self.assertRaisesRegexp(ValidationError, "u'Enter a valid time.'", f.clean, ['2006-01-10', ''])
     856        self.assertRaisesRegexp(ValidationError, "u'Enter a valid time.'", f.clean, ['2006-01-10'])
     857        self.assertRaisesRegexp(ValidationError, "u'Enter a valid date.'", f.clean, ['', '07:30'])
  • tests/regressiontests/forms/localflavor/be.py

    diff --git a/tests/regressiontests/forms/localflavor/be.py b/tests/regressiontests/forms/localflavor/be.py
    a b  
    88    """
    99    Test case to validate BE localflavor
    1010    """
    11     def assertRaisesErrorWithMessage(self, error, message, callable, *args, **kwargs):
    12         self.assertRaises(error, callable, *args, **kwargs)
    13         try:
    14             callable(*args, **kwargs)
    15         except error, e:
    16             self.assertEqual(message, str(e))
    17 
    1811    def test_postal_code_field(self):
    1912        f = BEPostalCodeField()
    2013        self.assertEqual(u'1451', f.clean('1451'))
    2114        self.assertEqual(u'2540', f.clean('2540'))
    22         err_message = "[u'Enter a valid postal code in the range and format 1XXX - 9XXX.']"
    23         self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '0287')
    24         self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '14309')
    25         self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '873')
    26         self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '35 74')
    27         self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '859A')
     15        err_message = "\[u'Enter a valid postal code in the range and format 1XXX - 9XXX.'\]"
     16        self.assertRaisesRegexp(ValidationError, err_message, f.clean, '0287')
     17        self.assertRaisesRegexp(ValidationError, err_message, f.clean, '14309')
     18        self.assertRaisesRegexp(ValidationError, err_message, f.clean, '873')
     19        self.assertRaisesRegexp(ValidationError, err_message, f.clean, '35 74')
     20        self.assertRaisesRegexp(ValidationError, err_message, f.clean, '859A')
    2821        err_message = "[u'This field is required.']"
    29         self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '')
     22        self.assertRaisesRegexp(ValidationError, err_message, f.clean, '')
    3023        f = BEPostalCodeField(required=False)
    3124        self.assertEqual(u'1451', f.clean('1451'))
    3225        self.assertEqual(u'2540', f.clean('2540'))
    3326        self.assertEqual(u'', f.clean(''))
    34         err_message = "[u'Enter a valid postal code in the range and format 1XXX - 9XXX.']"
    35         self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '0287')
    36         self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '14309')
    37         self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '873')
    38         self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '35 74')
    39         self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '859A')
     27        err_message = "\[u'Enter a valid postal code in the range and format 1XXX - 9XXX.'\]"
     28        self.assertRaisesRegexp(ValidationError, err_message, f.clean, '0287')
     29        self.assertRaisesRegexp(ValidationError, err_message, f.clean, '14309')
     30        self.assertRaisesRegexp(ValidationError, err_message, f.clean, '873')
     31        self.assertRaisesRegexp(ValidationError, err_message, f.clean, '35 74')
     32        self.assertRaisesRegexp(ValidationError, err_message, f.clean, '859A')
    4033
    4134    def test_phone_number_field(self):
    4235        f = BEPhoneNumberField()
     
    5144        self.assertEqual(u'0412.34.56.78', f.clean('0412.34.56.78'))
    5245        self.assertEqual(u'012345678', f.clean('012345678'))
    5346        self.assertEqual(u'0412345678', f.clean('0412345678'))
    54         err_message = "[u'Enter a valid phone number in one of the formats 0x xxx xx xx, 0xx xx xx xx, 04xx xx xx xx, 0x/xxx.xx.xx, 0xx/xx.xx.xx, 04xx/xx.xx.xx, 0xxxxxxxx, 04xxxxxxxx, 0x.xxx.xx.xx, 0xx.xx.xx.xx, 04xx.xx.xx.xx.']"
    55         self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '01234567')
    56         self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '12/345.67.89')
    57         self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '012/345.678.90')
    58         self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '012/34.56.789')
    59         self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '0123/45.67.89')
    60         self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '012/345 678 90')
    61         self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '012/34 56 789')
    62         self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '012.34 56 789')
    63         err_message = "[u'This field is required.']"
    64         self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '')
     47        err_message = "\[u'Enter a valid phone number in one of the formats 0x xxx xx xx, 0xx xx xx xx, 04xx xx xx xx, 0x/xxx.xx.xx, 0xx/xx.xx.xx, 04xx/xx.xx.xx, 0xxxxxxxx, 04xxxxxxxx, 0x.xxx.xx.xx, 0xx.xx.xx.xx, 04xx.xx.xx.xx.'\]"
     48        self.assertRaisesRegexp(ValidationError, err_message, f.clean, '01234567')
     49        self.assertRaisesRegexp(ValidationError, err_message, f.clean, '12/345.67.89')
     50        self.assertRaisesRegexp(ValidationError, err_message, f.clean, '012/345.678.90')
     51        self.assertRaisesRegexp(ValidationError, err_message, f.clean, '012/34.56.789')
     52        self.assertRaisesRegexp(ValidationError, err_message, f.clean, '0123/45.67.89')
     53        self.assertRaisesRegexp(ValidationError, err_message, f.clean, '012/345 678 90')
     54        self.assertRaisesRegexp(ValidationError, err_message, f.clean, '012/34 56 789')
     55        self.assertRaisesRegexp(ValidationError, err_message, f.clean, '012.34 56 789')
     56        err_message = "\[u'This field is required.'\]"
     57        self.assertRaisesRegexp(ValidationError, err_message, f.clean, '')
    6558        f = BEPhoneNumberField(required=False)
    6659        self.assertEqual(u'01 234 56 78', f.clean('01 234 56 78'))
    6760        self.assertEqual(u'01/234.56.78', f.clean('01/234.56.78'))
     
    7568        self.assertEqual(u'012345678', f.clean('012345678'))
    7669        self.assertEqual(u'0412345678', f.clean('0412345678'))
    7770        self.assertEqual(u'', f.clean(''))
    78         err_message = "[u'Enter a valid phone number in one of the formats 0x xxx xx xx, 0xx xx xx xx, 04xx xx xx xx, 0x/xxx.xx.xx, 0xx/xx.xx.xx, 04xx/xx.xx.xx, 0xxxxxxxx, 04xxxxxxxx, 0x.xxx.xx.xx, 0xx.xx.xx.xx, 04xx.xx.xx.xx.']"
    79         self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '01234567')
    80         self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '12/345.67.89')
    81         self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '012/345.678.90')
    82         self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '012/34.56.789')
    83         self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '0123/45.67.89')
    84         self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '012/345 678 90')
    85         self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '012/34 56 789')
    86         self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '012.34 56 789')
     71        err_message = "\[u'Enter a valid phone number in one of the formats 0x xxx xx xx, 0xx xx xx xx, 04xx xx xx xx, 0x/xxx.xx.xx, 0xx/xx.xx.xx, 04xx/xx.xx.xx, 0xxxxxxxx, 04xxxxxxxx, 0x.xxx.xx.xx, 0xx.xx.xx.xx, 04xx.xx.xx.xx.'\]"
     72        self.assertRaisesRegexp(ValidationError, err_message, f.clean, '01234567')
     73        self.assertRaisesRegexp(ValidationError, err_message, f.clean, '12/345.67.89')
     74        self.assertRaisesRegexp(ValidationError, err_message, f.clean, '012/345.678.90')
     75        self.assertRaisesRegexp(ValidationError, err_message, f.clean, '012/34.56.789')
     76        self.assertRaisesRegexp(ValidationError, err_message, f.clean, '0123/45.67.89')
     77        self.assertRaisesRegexp(ValidationError, err_message, f.clean, '012/345 678 90')
     78        self.assertRaisesRegexp(ValidationError, err_message, f.clean, '012/34 56 789')
     79        self.assertRaisesRegexp(ValidationError, err_message, f.clean, '012.34 56 789')
    8780
    8881    def test_phone_number_field(self):
    8982        w = BERegionSelect()
  • tests/regressiontests/queries/tests.py

    diff --git a/tests/regressiontests/queries/tests.py b/tests/regressiontests/queries/tests.py
    a b  
    2121    def assertValueQuerysetEqual(self, qs, values):
    2222        return self.assertQuerysetEqual(qs, values, transform=lambda x: x)
    2323
    24     def assertRaisesMessage(self, exc, msg, func, *args, **kwargs):
    25         try:
    26             func(*args, **kwargs)
    27         except Exception, e:
    28             self.assertEqual(msg, str(e))
    29             self.assertTrue(isinstance(e, exc), "Expected %s, got %s" % (exc, type(e)))
    30 
    3124
    3225class Queries1Tests(BaseQuerysetTest):
    3326    def setUp(self):
     
    356349    def test_heterogeneous_qs_combination(self):
    357350        # Combining querysets built on different models should behave in a well-defined
    358351        # fashion. We raise an error.
    359         self.assertRaisesMessage(
     352        self.assertRaisesRegexp(
    360353            AssertionError,
    361354            'Cannot combine queries on two different base models.',
    362355            lambda: Author.objects.all() & Tag.objects.all()
    363356        )
    364         self.assertRaisesMessage(
     357        self.assertRaisesRegexp(
    365358            AssertionError,
    366359            'Cannot combine queries on two different base models.',
    367360            lambda: Author.objects.all() | Tag.objects.all()
     
    670663            []
    671664        )
    672665        q.query.low_mark = 1
    673         self.assertRaisesMessage(
     666        self.assertRaisesRegexp(
    674667            AssertionError,
    675668            'Cannot change a query once a slice has been taken',
    676669            q.extra, select={'is_recent': "pub_date > '2006-01-01'"}
     
    701694        )
    702695
    703696        # Multi-valued values() and values_list() querysets should raise errors.
    704         self.assertRaisesMessage(
     697        self.assertRaisesRegexp(
    705698            TypeError,
    706699            'Cannot use a multi-field ValuesQuerySet as a filter value.',
    707700            lambda: Tag.objects.filter(name__in=Tag.objects.filter(parent=self.t1).values('name', 'id'))
    708701        )
    709         self.assertRaisesMessage(
     702        self.assertRaisesRegexp(
    710703            TypeError,
    711704            'Cannot use a multi-field ValuesListQuerySet as a filter value.',
    712705            lambda: Tag.objects.filter(name__in=Tag.objects.filter(parent=self.t1).values_list('name', 'id'))
     
    948941    def test_ticket8683(self):
    949942        # Raise proper error when a DateQuerySet gets passed a wrong type of
    950943        # field
    951         self.assertRaisesMessage(
     944        self.assertRaisesRegexp(
    952945            AssertionError,
    953946            "'name' isn't a DateField.",
    954947            Item.objects.dates, 'name', 'month'
     
    14611454        self.assertQuerysetEqual(Article.objects.all()[0:0], [])
    14621455        self.assertQuerysetEqual(Article.objects.all()[0:0][:10], [])
    14631456        self.assertEqual(Article.objects.all()[:0].count(), 0)
    1464         self.assertRaisesMessage(
     1457        self.assertRaisesRegexp(
    14651458            AssertionError,
    14661459            'Cannot change a query once a slice has been taken.',
    14671460            Article.objects.all()[:0].latest, 'created'
     
    15081501    def test_infinite_loop(self):
    15091502        # If you're not careful, it's possible to introduce infinite loops via
    15101503        # default ordering on foreign keys in a cycle. We detect that.
    1511         self.assertRaisesMessage(
     1504        self.assertRaisesRegexp(
    15121505            FieldError,
    15131506            'Infinite loop caused by ordering.',
    15141507            LoopX.objects.all
    15151508        )
    1516         self.assertRaisesMessage(
     1509        self.assertRaisesRegexp(
    15171510            FieldError,
    15181511            'Infinite loop caused by ordering.',
    15191512            LoopZ.objects.all
  • tests/regressiontests/urlpatterns_reverse/tests.py

    diff --git a/tests/regressiontests/urlpatterns_reverse/tests.py b/tests/regressiontests/urlpatterns_reverse/tests.py
    a b  
    133133class NoURLPatternsTests(TestCase):
    134134    urls = 'regressiontests.urlpatterns_reverse.no_urls'
    135135
    136     def assertRaisesErrorWithMessage(self, error, message, callable,
    137         *args, **kwargs):
    138         self.assertRaises(error, callable, *args, **kwargs)
    139         try:
    140             callable(*args, **kwargs)
    141         except error, e:
    142             self.assertEqual(message, str(e))
    143 
    144136    def test_no_urls_exception(self):
    145137        """
    146138        RegexURLResolver should raise an exception when no urlpatterns exist.
    147139        """
    148140        resolver = RegexURLResolver(r'^$', self.urls)
    149141
    150         self.assertRaisesErrorWithMessage(ImproperlyConfigured,
     142        self.assertRaisesRegexp(ImproperlyConfigured,
    151143            "The included urlconf regressiontests.urlpatterns_reverse.no_urls "\
    152144            "doesn't have any patterns in it", getattr, resolver, 'url_patterns')
    153145
  • tests/regressiontests/utils/datastructures.py

    diff --git a/tests/regressiontests/utils/datastructures.py b/tests/regressiontests/utils/datastructures.py
    a b  
    22Tests for stuff in django.utils.datastructures.
    33"""
    44import pickle
    5 import unittest
    65
    76from django.utils.datastructures import *
     7from django.utils.unittest import TestCase
    88
    99
    10 class DatastructuresTestCase(unittest.TestCase):
    11     def assertRaisesErrorWithMessage(self, error, message, callable,
    12         *args, **kwargs):
    13         self.assertRaises(error, callable, *args, **kwargs)
    14         try:
    15             callable(*args, **kwargs)
    16         except error, e:
    17             self.assertEqual(message, str(e))
    18 
    19 
    20 class SortedDictTests(DatastructuresTestCase):
     10class SortedDictTests(TestCase):
    2111    def setUp(self):
    2212        self.d1 = SortedDict()
    2313        self.d1[7] = 'seven'
     
    123113        self.assertEquals(self.d1, {})
    124114        self.assertEquals(self.d1.keyOrder, [])
    125115
    126 class MergeDictTests(DatastructuresTestCase):
     116class MergeDictTests(TestCase):
    127117
    128118    def test_simple_mergedict(self):
    129119        d1 = {'chris':'cool', 'camri':'cute', 'cotton':'adorable',
     
    177167                           ('key2', ['value2', 'value3']),
    178168                           ('key4', ['value5', 'value6'])])
    179169
    180 class MultiValueDictTests(DatastructuresTestCase):
     170class MultiValueDictTests(TestCase):
    181171
    182172    def test_multivaluedict(self):
    183173        d = MultiValueDict({'name': ['Adrian', 'Simon'],
     
    196186        # MultiValueDictKeyError: "Key 'lastname' not found in
    197187        # <MultiValueDict: {'position': ['Developer'],
    198188        #                   'name': ['Adrian', 'Simon']}>"
    199         self.assertRaisesErrorWithMessage(MultiValueDictKeyError,
    200             '"Key \'lastname\' not found in <MultiValueDict: {\'position\':'\
    201             ' [\'Developer\'], \'name\': [\'Adrian\', \'Simon\']}>"',
     189        self.assertRaisesRegexp(MultiValueDictKeyError,
     190            '"Key \'lastname\' not found in <MultiValueDict: \{\'position\':'\
     191            ' \[\'Developer\'\], \'name\': \[\'Adrian\', \'Simon\'\]\}>"',
    202192            d.__getitem__, 'lastname')
    203193
    204194        self.assertEquals(d.get('lastname'), None)
     
    212202                          ['Developer', 'Simon', 'Willison'])
    213203
    214204
    215 class DotExpandedDictTests(DatastructuresTestCase):
     205class DotExpandedDictTests(TestCase):
    216206
    217207    def test_dotexpandeddict(self):
    218208
     
    226216        self.assertEquals(d['person']['2']['firstname'], ['Adrian'])
    227217
    228218
    229 class ImmutableListTests(DatastructuresTestCase):
     219class ImmutableListTests(TestCase):
    230220
    231221    def test_sort(self):
    232222        d = ImmutableList(range(10))
    233223
    234224        # AttributeError: ImmutableList object is immutable.
    235         self.assertRaisesErrorWithMessage(AttributeError,
     225        self.assertRaisesRegexp(AttributeError,
    236226            'ImmutableList object is immutable.', d.sort)
    237227
    238228        self.assertEquals(repr(d), '(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)')
     
    243233        self.assertEquals(d[1], 1)
    244234
    245235        # AttributeError: Object is immutable!
    246         self.assertRaisesErrorWithMessage(AttributeError,
     236        self.assertRaisesRegexp(AttributeError,
    247237            'Object is immutable!', d.__setitem__, 1, 'test')
    248238
    249239
    250 class DictWrapperTests(DatastructuresTestCase):
     240class DictWrapperTests(TestCase):
    251241
    252242    def test_dictwrapper(self):
    253243        f = lambda x: "*%s" % x
Back to Top