Ticket #14503: 14503-assertraisesregex-r14981.diff

File 14503-assertraisesregex-r14981.diff, 79.7 KB (added by Ramiro Morales, 14 years ago)

Updated patch for trunk as of now

  • 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,
    44             "'InvalidFields.fields' refers to field 'spam' that is missing from the form.",
     36        self.assertRaisesRegexp(ImproperlyConfigured,
     37            "'InvalidFields\.fields' refers to field 'spam' that is missing from the form\.",
    4538            validate,
    4639            InvalidFields, Song)
    4740
     
    5144        """
    5245        class ExcludedFields1(admin.ModelAdmin):
    5346            exclude = ('foo')
    54         self.assertRaisesMessage(ImproperlyConfigured,
    55             "'ExcludedFields1.exclude' must be a list or tuple.",
     47        self.assertRaisesRegexp(ImproperlyConfigured,
     48            "'ExcludedFields1\.exclude' must be a list or tuple\.",
    5649            validate,
    5750            ExcludedFields1, Book)
    5851
    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,
    77             "'ExcludedFieldsInline.exclude' must be a list or tuple.",
     69        self.assertRaisesRegexp(ImproperlyConfigured,
     70            "'ExcludedFieldsInline\.exclude' must be a list or tuple\.",
    7871            validate,
    7972            ExcludedFieldsAlbumAdmin, Album)
    8073
     
    9184            model = Album
    9285            inlines = [SongInline]
    9386
    94         self.assertRaisesMessage(ImproperlyConfigured,
    95             "SongInline cannot exclude the field 'album' - this is the foreign key to the parent model Album.",
     87        self.assertRaisesRegexp(ImproperlyConfigured,
     88            "SongInline cannot exclude the field 'album' - this is the foreign key to the parent model Album\.",
    9689            validate,
    9790            AlbumAdmin, Album)
    9891
     
    112105        class TwoAlbumFKAndAnEInline(admin.TabularInline):
    113106            model = TwoAlbumFKAndAnE
    114107
    115         self.assertRaisesMessage(Exception,
    116             "<class 'regressiontests.admin_validation.models.TwoAlbumFKAndAnE'> has more than 1 ForeignKey to <class 'regressiontests.admin_validation.models.Album'>",
     108        self.assertRaisesRegexp(Exception,
     109            "<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)
    119112
     
    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,
    190             "'BookAdmin.fields' can't include the ManyToManyField field 'authors' because 'authors' manually specifies a 'through' model.",
     182        self.assertRaisesRegexp(ImproperlyConfigured,
     183            "'BookAdmin\.fields' can't include the ManyToManyField field 'authors' because 'authors' manually specifies a 'through' model\.",
    191184            validate,
    192185            BookAdmin, Book)
    193186
     
    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,
    47             "Cannot resolve keyword 'firstname' into field. Choices are: Author_ID, article, first_name, last_name, primary_set",
     40            "Cannot resolve keyword 'firstname' into field\. Choices are: Author_ID, article, first_name, last_name, primary_set",
    4841            Author.objects.filter,
    4942            firstname__exact='John'
    5043        )
     
    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  
    3636
    3737
    3838class GetStorageClassTests(unittest.TestCase):
    39     def assertRaisesErrorWithMessage(self, error, message, callable,
    40         *args, **kwargs):
    41         self.assertRaises(error, callable, *args, **kwargs)
    42         try:
    43             callable(*args, **kwargs)
    44         except error, e:
    45             self.assertEqual(message, str(e))
    46 
    4739    def test_get_filesystem_storage(self):
    4840        """
    4941        get_storage_class returns the class for a storage backend name/path.
     
    5648        """
    5749        get_storage_class raises an error if the requested import don't exist.
    5850        """
    59         self.assertRaisesErrorWithMessage(
     51        self.assertRaisesRegexp(
    6052            ImproperlyConfigured,
    61             "NonExistingStorage isn't a storage module.",
     53            "NonExistingStorage isn't a storage module\.",
    6254            get_storage_class,
    6355            'NonExistingStorage')
    6456
     
    6658        """
    6759        get_storage_class raises an error if the requested class don't exist.
    6860        """
    69         self.assertRaisesErrorWithMessage(
     61        self.assertRaisesRegexp(
    7062            ImproperlyConfigured,
    71             'Storage module "django.core.files.storage" does not define a '\
    72                 '"NonExistingStorage" class.',
     63            'Storage module "django\.core\.files\.storage" does not define a '\
     64                '"NonExistingStorage" class\.',
    7365            get_storage_class,
    7466            'django.core.files.storage.NonExistingStorage')
    7567
  • tests/regressiontests/fixtures_regress/tests.py

    diff --git a/tests/regressiontests/fixtures_regress/tests.py b/tests/regressiontests/fixtures_regress/tests.py
    a b  
    364364
    365365
    366366class NaturalKeyFixtureTests(TestCase):
    367     def assertRaisesMessage(self, exc, msg, func, *args, **kwargs):
    368         try:
    369             func(*args, **kwargs)
    370         except Exception, e:
    371             self.assertEqual(msg, str(e))
    372             self.assertTrue(isinstance(e, exc), "Expected %s, got %s" % (exc, type(e)))
    373 
    374367    def test_nk_deserialize(self):
    375368        """
    376369        Test for ticket #13030 - Python based parser version
     
    528521        )
    529522
    530523    def test_dependency_sorting_tight_circular(self):
    531         self.assertRaisesMessage(
     524        self.assertRaisesRegexp(
    532525            CommandError,
    533             """Can't resolve dependencies for fixtures_regress.Circle1, fixtures_regress.Circle2 in serialized app list.""",
     526            """Can't resolve dependencies for fixtures_regress\.Circle1, fixtures_regress\.Circle2 in serialized app list\.""",
    534527            sort_dependencies,
    535528            [('fixtures_regress', [Person, Circle2, Circle1, Store, Book])],
    536529        )
    537530
    538531    def test_dependency_sorting_tight_circular_2(self):
    539         self.assertRaisesMessage(
     532        self.assertRaisesRegexp(
    540533            CommandError,
    541             """Can't resolve dependencies for fixtures_regress.Circle1, fixtures_regress.Circle2 in serialized app list.""",
     534            """Can't resolve dependencies for fixtures_regress\.Circle1, fixtures_regress\.Circle2 in serialized app list\.""",
    542535            sort_dependencies,
    543536            [('fixtures_regress', [Circle1, Book, Circle2])],
    544537        )
    545538
    546539    def test_dependency_self_referential(self):
    547         self.assertRaisesMessage(
     540        self.assertRaisesRegexp(
    548541            CommandError,
    549             """Can't resolve dependencies for fixtures_regress.Circle3 in serialized app list.""",
     542            """Can't resolve dependencies for fixtures_regress\.Circle3 in serialized app list\.""",
    550543            sort_dependencies,
    551544            [('fixtures_regress', [Book, Circle3])],
    552545        )
    553546
    554547    def test_dependency_sorting_long(self):
    555         self.assertRaisesMessage(
     548        self.assertRaisesRegexp(
    556549            CommandError,
    557             """Can't resolve dependencies for fixtures_regress.Circle1, fixtures_regress.Circle2, fixtures_regress.Circle3 in serialized app list.""",
     550            """Can't resolve dependencies for fixtures_regress\.Circle1, fixtures_regress\.Circle2, fixtures_regress\.Circle3 in serialized app list\.""",
    558551            sort_dependencies,
    559552            [('fixtures_regress', [Person, Circle2, Circle1, Circle3, Store, Book])],
    560553        )
  • tests/regressiontests/forms/tests/fields.py

    diff --git a/tests/regressiontests/forms/tests/fields.py b/tests/regressiontests/forms/tests/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.assertTrue(Field(required=True).widget.is_required)
    6154        self.assertFalse(Field(required=False).widget.is_required)
     
    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_2(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_4(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_5(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_1(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_2(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_3(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_4(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_5(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_1(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_2(self):
    181174        f = FloatField(required=False)
     
    185178
    186179    def test_floatfield_3(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_1(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_2(self):
    227220        f = DecimalField(max_digits=4, decimal_places=2, required=False)
     
    231224
    232225    def test_decimalfield_3(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_4(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_5(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_6(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_2(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_2(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_2(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_3(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_2(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_3(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, "\[u'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_4(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_5(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_1(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_3(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_1(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_2(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_1(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        self.assertEqual(u'http://www.example.com/s/http://code.djangoproject.com/ticket/13804', f.clean('www.example.com/s/http://code.djangoproject.com/ticket/13804'))
     
    500493    def test_url_regex_ticket11198(self):
    501494        f = URLField()
    502495        # hangs "forever" if catastrophic backtracking in ticket:#11198 not fixed
    503         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://%s' % ("X"*200,))
     496        self.assertRaisesRegexp(ValidationError, "\[u'Enter a valid URL\.'\]", f.clean, 'http://%s' % ("X"*200,))
    504497
    505498        # a second test, to make sure the problem is really addressed, even on
    506499        # domains that don't fail the domain label length check in the regex
    507         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://%s' % ("X"*60,))
     500        self.assertRaisesRegexp(ValidationError, "\[u'Enter a valid URL\.'\]", f.clean, 'http://%s' % ("X"*60,))
    508501
    509502    def test_urlfield_2(self):
    510503        f = URLField(required=False)
     
    512505        self.assertEqual(u'', f.clean(None))
    513506        self.assertEqual(u'http://example.com/', f.clean('http://example.com'))
    514507        self.assertEqual(u'http://www.example.com/', f.clean('http://www.example.com'))
    515         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'foo')
    516         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://')
    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://example.')
    519         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://.com')
     508        self.assertRaisesRegexp(ValidationError, "\[u'Enter a valid URL\.'\]", f.clean, 'foo')
     509        self.assertRaisesRegexp(ValidationError, "\[u'Enter a valid URL\.'\]", f.clean, 'http://')
     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://example.')
     512        self.assertRaisesRegexp(ValidationError, "\[u'Enter a valid URL\.'\]", f.clean, 'http://.com')
    520513
    521514    def test_urlfield_3(self):
    522515        f = URLField(verify_exists=True)
    523516        self.assertEqual(u'http://www.google.com/', f.clean('http://www.google.com')) # This will fail if there's no Internet connection
    524         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://example')
     517        self.assertRaisesRegexp(ValidationError, "\[u'Enter a valid URL\.'\]", f.clean, 'http://example')
    525518        self.assertRaises(ValidationError, f.clean, 'http://www.broken.djangoproject.com') # bad domain
    526519        try:
    527520            f.clean('http://www.broken.djangoproject.com') # bad domain
     
    547540
    548541    def test_urlfield_5(self):
    549542        f = URLField(min_length=15, max_length=20)
    550         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value has at least 15 characters (it has 13).']", f.clean, 'http://f.com')
     543        self.assertRaisesRegexp(ValidationError, "\[u'Ensure this value has at least 15 characters \(it has 13\)\.'\]", f.clean, 'http://f.com')
    551544        self.assertEqual(u'http://example.com/', f.clean('http://example.com'))
    552         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value has at most 20 characters (it has 38).']", f.clean, 'http://abcdefghijklmnopqrstuvwxyz.com')
     545        self.assertRaisesRegexp(ValidationError, "\[u'Ensure this value has at most 20 characters \(it has 38\)\.'\]", f.clean, 'http://abcdefghijklmnopqrstuvwxyz.com')
    553546
    554547    def test_urlfield_6(self):
    555548        f = URLField(required=False)
     
    570563
    571564    def test_booleanfield_1(self):
    572565        f = BooleanField()
    573         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
    574         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
     566        self.assertRaisesRegexp(ValidationError, "\[u'This field is required\.'\]", f.clean, '')
     567        self.assertRaisesRegexp(ValidationError, "\[u'This field is required\.'\]", f.clean, None)
    575568        self.assertEqual(True, f.clean(True))
    576         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, False)
     569        self.assertRaisesRegexp(ValidationError, "\[u'This field is required\.'\]", f.clean, False)
    577570        self.assertEqual(True, f.clean(1))
    578         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, 0)
     571        self.assertRaisesRegexp(ValidationError, "\[u'This field is required\.'\]", f.clean, 0)
    579572        self.assertEqual(True, f.clean('Django rocks'))
    580573        self.assertEqual(True, f.clean('True'))
    581         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, 'False')
     574        self.assertRaisesRegexp(ValidationError, "\[u'This field is required\.'\]", f.clean, 'False')
    582575
    583576    def test_booleanfield_2(self):
    584577        f = BooleanField(required=False)
     
    597590
    598591    def test_choicefield_1(self):
    599592        f = ChoiceField(choices=[('1', 'One'), ('2', 'Two')])
    600         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
    601         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
     593        self.assertRaisesRegexp(ValidationError, "\[u'This field is required\.'\]", f.clean, '')
     594        self.assertRaisesRegexp(ValidationError, "\[u'This field is required\.'\]", f.clean, None)
    602595        self.assertEqual(u'1', f.clean(1))
    603596        self.assertEqual(u'1', f.clean('1'))
    604         self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. 3 is not one of the available choices.']", f.clean, '3')
     597        self.assertRaisesRegexp(ValidationError, "\[u'Select a valid choice\. 3 is not one of the available choices\.'\]", f.clean, '3')
    605598
    606599    def test_choicefield_2(self):
    607600        f = ChoiceField(choices=[('1', 'One'), ('2', 'Two')], required=False)
     
    609602        self.assertEqual(u'', f.clean(None))
    610603        self.assertEqual(u'1', f.clean(1))
    611604        self.assertEqual(u'1', f.clean('1'))
    612         self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. 3 is not one of the available choices.']", f.clean, '3')
     605        self.assertRaisesRegexp(ValidationError, "\[u'Select a valid choice\. 3 is not one of the available choices\.'\]", f.clean, '3')
    613606
    614607    def test_choicefield_3(self):
    615608        f = ChoiceField(choices=[('J', 'John'), ('P', 'Paul')])
    616609        self.assertEqual(u'J', f.clean('J'))
    617         self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. John is not one of the available choices.']", f.clean, 'John')
     610        self.assertRaisesRegexp(ValidationError, "\[u'Select a valid choice\. John is not one of the available choices\.'\]", f.clean, 'John')
    618611
    619612    def test_choicefield_4(self):
    620613        f = ChoiceField(choices=[('Numbers', (('1', 'One'), ('2', 'Two'))), ('Letters', (('3','A'),('4','B'))), ('5','Other')])
     
    624617        self.assertEqual(u'3', f.clean('3'))
    625618        self.assertEqual(u'5', f.clean(5))
    626619        self.assertEqual(u'5', f.clean('5'))
    627         self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. 6 is not one of the available choices.']", f.clean, '6')
     620        self.assertRaisesRegexp(ValidationError, "\[u'Select a valid choice\. 6 is not one of the available choices\.'\]", f.clean, '6')
    628621
    629622    # TypedChoiceField ############################################################
    630623    # TypedChoiceField is just like ChoiceField, except that coerced types will
     
    633626    def test_typedchoicefield_1(self):
    634627        f = TypedChoiceField(choices=[(1, "+1"), (-1, "-1")], coerce=int)
    635628        self.assertEqual(1, f.clean('1'))
    636         self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. 2 is not one of the available choices.']", f.clean, '2')
     629        self.assertRaisesRegexp(ValidationError, "\[u'Select a valid choice\. 2 is not one of the available choices\.'\]", f.clean, '2')
    637630
    638631    def test_typedchoicefield_2(self):
    639632        # Different coercion, same validation.
     
    649642        # Even more weirdness: if you have a valid choice but your coercion function
    650643        # can't coerce, you'll still get a validation error. Don't do this!
    651644        f = TypedChoiceField(choices=[('A', 'A'), ('B', 'B')], coerce=int)
    652         self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. B is not one of the available choices.']", f.clean, 'B')
     645        self.assertRaisesRegexp(ValidationError, "\[u'Select a valid choice\. B is not one of the available choices\.'\]", f.clean, 'B')
    653646        # Required fields require values
    654         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
     647        self.assertRaisesRegexp(ValidationError, "\[u'This field is required\.'\]", f.clean, '')
    655648
    656649    def test_typedchoicefield_5(self):
    657650        # Non-required fields aren't required
     
    713706
    714707    def test_multiplechoicefield_1(self):
    715708        f = MultipleChoiceField(choices=[('1', 'One'), ('2', 'Two')])
    716         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
    717         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
     709        self.assertRaisesRegexp(ValidationError, "\[u'This field is required\.'\]", f.clean, '')
     710        self.assertRaisesRegexp(ValidationError, "\[u'This field is required\.'\]", f.clean, None)
    718711        self.assertEqual([u'1'], f.clean([1]))
    719712        self.assertEqual([u'1'], f.clean(['1']))
    720713        self.assertEqual([u'1', u'2'], f.clean(['1', '2']))
    721714        self.assertEqual([u'1', u'2'], f.clean([1, '2']))
    722715        self.assertEqual([u'1', u'2'], f.clean((1, '2')))
    723         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a list of values.']", f.clean, 'hello')
    724         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, [])
    725         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, ())
    726         self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. 3 is not one of the available choices.']", f.clean, ['3'])
     716        self.assertRaisesRegexp(ValidationError, "\[u'Enter a list of values\.'\]", f.clean, 'hello')
     717        self.assertRaisesRegexp(ValidationError, "\[u'This field is required\.'\]", f.clean, [])
     718        self.assertRaisesRegexp(ValidationError, "\[u'This field is required\.'\]", f.clean, ())
     719        self.assertRaisesRegexp(ValidationError, "\[u'Select a valid choice\. 3 is not one of the available choices\.'\]", f.clean, ['3'])
    727720
    728721    def test_multiplechoicefield_2(self):
    729722        f = MultipleChoiceField(choices=[('1', 'One'), ('2', 'Two')], required=False)
     
    734727        self.assertEqual([u'1', u'2'], f.clean(['1', '2']))
    735728        self.assertEqual([u'1', u'2'], f.clean([1, '2']))
    736729        self.assertEqual([u'1', u'2'], f.clean((1, '2')))
    737         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a list of values.']", f.clean, 'hello')
     730        self.assertRaisesRegexp(ValidationError, "\[u'Enter a list of values\.'\]", f.clean, 'hello')
    738731        self.assertEqual([], f.clean([]))
    739732        self.assertEqual([], f.clean(()))
    740         self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. 3 is not one of the available choices.']", f.clean, ['3'])
     733        self.assertRaisesRegexp(ValidationError, "\[u'Select a valid choice\. 3 is not one of the available choices\.'\]", f.clean, ['3'])
    741734
    742735    def test_multiplechoicefield_3(self):
    743736        f = MultipleChoiceField(choices=[('Numbers', (('1', 'One'), ('2', 'Two'))), ('Letters', (('3','A'),('4','B'))), ('5','Other')])
     
    747740        self.assertEqual([u'1', u'5'], f.clean([1, '5']))
    748741        self.assertEqual([u'1', u'5'], f.clean(['1', 5]))
    749742        self.assertEqual([u'1', u'5'], f.clean(['1', '5']))
    750         self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. 6 is not one of the available choices.']", f.clean, ['6'])
    751         self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. 6 is not one of the available choices.']", f.clean, ['1','6'])
     743        self.assertRaisesRegexp(ValidationError, "\[u'Select a valid choice\. 6 is not one of the available choices\.'\]", f.clean, ['6'])
     744        self.assertRaisesRegexp(ValidationError, "\[u'Select a valid choice\. 6 is not one of the available choices\.'\]", f.clean, ['1','6'])
    752745
    753746    # TypedMultipleChoiceField ############################################################
    754747    # TypedMultipleChoiceField is just like MultipleChoiceField, except that coerced types
     
    757750    def test_typedmultiplechoicefield_1(self):
    758751        f = TypedMultipleChoiceField(choices=[(1, "+1"), (-1, "-1")], coerce=int)
    759752        self.assertEqual([1], f.clean(['1']))
    760         self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. 2 is not one of the available choices.']", f.clean, ['2'])
     753        self.assertRaisesRegexp(ValidationError, "\[u'Select a valid choice\. 2 is not one of the available choices\.'\]", f.clean, ['2'])
    761754
    762755    def test_typedmultiplechoicefield_2(self):
    763756        # Different coercion, same validation.
     
    772765    def test_typedmultiplechoicefield_4(self):
    773766        f = TypedMultipleChoiceField(choices=[(1, "+1"), (-1, "-1")], coerce=int)
    774767        self.assertEqual([1, -1], f.clean(['1','-1']))
    775         self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. 2 is not one of the available choices.']", f.clean, ['1','2'])
     768        self.assertRaisesRegexp(ValidationError, "\[u'Select a valid choice\. 2 is not one of the available choices\.'\]", f.clean, ['1','2'])
    776769
    777770    def test_typedmultiplechoicefield_5(self):
    778771        # Even more weirdness: if you have a valid choice but your coercion function
    779772        # can't coerce, you'll still get a validation error. Don't do this!
    780773        f = TypedMultipleChoiceField(choices=[('A', 'A'), ('B', 'B')], coerce=int)
    781         self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. B is not one of the available choices.']", f.clean, ['B'])
     774        self.assertRaisesRegexp(ValidationError, "\[u'Select a valid choice\. B is not one of the available choices\.'\]", f.clean, ['B'])
    782775        # Required fields require values
    783         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, [])
     776        self.assertRaisesRegexp(ValidationError, "\[u'This field is required\.'\]", f.clean, [])
    784777
    785778    def test_typedmultiplechoicefield_6(self):
    786779        # Non-required fields aren't required
     
    797790    def test_combofield_1(self):
    798791        f = ComboField(fields=[CharField(max_length=20), EmailField()])
    799792        self.assertEqual(u'test@example.com', f.clean('test@example.com'))
    800         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value has at most 20 characters (it has 28).']", f.clean, 'longemailaddress@example.com')
    801         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'not an e-mail')
    802         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
    803         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
     793        self.assertRaisesRegexp(ValidationError, "\[u'Ensure this value has at most 20 characters \(it has 28\)\.'\]", f.clean, 'longemailaddress@example.com')
     794        self.assertRaisesRegexp(ValidationError, "\[u'Enter a valid e-mail address\.'\]", f.clean, 'not an e-mail')
     795        self.assertRaisesRegexp(ValidationError, "\[u'This field is required\.'\]", f.clean, '')
     796        self.assertRaisesRegexp(ValidationError, "\[u'This field is required\.'\]", f.clean, None)
    804797
    805798    def test_combofield_2(self):
    806799        f = ComboField(fields=[CharField(max_length=20), EmailField()], required=False)
    807800        self.assertEqual(u'test@example.com', f.clean('test@example.com'))
    808         self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value has at most 20 characters (it has 28).']", f.clean, 'longemailaddress@example.com')
    809         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'not an e-mail')
     801        self.assertRaisesRegexp(ValidationError, "\[u'Ensure this value has at most 20 characters \(it has 28\)\.'\]", f.clean, 'longemailaddress@example.com')
     802        self.assertRaisesRegexp(ValidationError, "\[u'Enter a valid e-mail address\.'\]", f.clean, 'not an e-mail')
    810803        self.assertEqual(u'', f.clean(''))
    811804        self.assertEqual(u'', f.clean(None))
    812805
     
    835828        for exp, got in zip(expected, fix_os_paths(f.choices)):
    836829            self.assertEqual(exp[1], got[1])
    837830            self.assertTrue(got[0].endswith(exp[0]))
    838         self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. fields.py is not one of the available choices.']", f.clean, 'fields.py')
     831        self.assertRaisesRegexp(ValidationError, "\[u'Select a valid choice\. fields\.py is not one of the available choices\.'\]", f.clean, 'fields.py')
    839832        assert fix_os_paths(f.clean(path + 'fields.py')).endswith('/django/forms/fields.py')
    840833
    841834    def test_filepathfield_3(self):
     
    883876        f = SplitDateTimeField()
    884877        assert isinstance(f.widget, SplitDateTimeWidget)
    885878        self.assertEqual(datetime.datetime(2006, 1, 10, 7, 30), f.clean([datetime.date(2006, 1, 10), datetime.time(7, 30)]))
    886         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
    887         self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
    888         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a list of values.']", f.clean, 'hello')
    889         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid date.', u'Enter a valid time.']", f.clean, ['hello', 'there'])
    890         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid time.']", f.clean, ['2006-01-10', 'there'])
    891         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid date.']", f.clean, ['hello', '07:30'])
     879        self.assertRaisesRegexp(ValidationError, "\[u'This field is required\.'\]", f.clean, None)
     880        self.assertRaisesRegexp(ValidationError, "\[u'This field is required\.'\]", f.clean, '')
     881        self.assertRaisesRegexp(ValidationError, "\[u'Enter a list of values\.'\]", f.clean, 'hello')
     882        self.assertRaisesRegexp(ValidationError, "\[u'Enter a valid date\.', u'Enter a valid time\.'\]", f.clean, ['hello', 'there'])
     883        self.assertRaisesRegexp(ValidationError, "\[u'Enter a valid time\.'\]", f.clean, ['2006-01-10', 'there'])
     884        self.assertRaisesRegexp(ValidationError, "\[u'Enter a valid date\.'\]", f.clean, ['hello', '07:30'])
    892885
    893886    def test_splitdatetimefield_2(self):
    894887        f = SplitDateTimeField(required=False)
     
    898891        self.assertEqual(None, f.clean(''))
    899892        self.assertEqual(None, f.clean(['']))
    900893        self.assertEqual(None, f.clean(['', '']))
    901         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a list of values.']", f.clean, 'hello')
    902         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid date.', u'Enter a valid time.']", f.clean, ['hello', 'there'])
    903         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid time.']", f.clean, ['2006-01-10', 'there'])
    904         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid date.']", f.clean, ['hello', '07:30'])
    905         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid time.']", f.clean, ['2006-01-10', ''])
    906         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid time.']", f.clean, ['2006-01-10'])
    907         self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid date.']", f.clean, ['', '07:30'])
     894        self.assertRaisesRegexp(ValidationError, "\[u'Enter a list of values\.'\]", f.clean, 'hello')
     895        self.assertRaisesRegexp(ValidationError, "\[u'Enter a valid date\.', u'Enter a valid time\.'\]", f.clean, ['hello', 'there'])
     896        self.assertRaisesRegexp(ValidationError, "\[u'Enter a valid time\.'\]", f.clean, ['2006-01-10', 'there'])
     897        self.assertRaisesRegexp(ValidationError, "\[u'Enter a valid date\.'\]", f.clean, ['hello', '07:30'])
     898        self.assertRaisesRegexp(ValidationError, "\[u'Enter a valid time\.'\]", f.clean, ['2006-01-10', ''])
     899        self.assertRaisesRegexp(ValidationError, "\[u'Enter a valid time\.'\]", f.clean, ['2006-01-10'])
     900        self.assertRaisesRegexp(ValidationError, "\[u'Enter a valid date\.'\]", f.clean, ['', '07:30'])
  • tests/regressiontests/queries/tests.py

    diff --git a/tests/regressiontests/queries/tests.py b/tests/regressiontests/queries/tests.py
    a b  
    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         else:
    31             if hasattr(exc, '__name__'):
    32                 excName = exc.__name__
    33             else:
    34                 excName = str(exc)
    35             raise AssertionError, "%s not raised" % excName
    36 
    3724
    3825class Queries1Tests(BaseQuerysetTest):
    3926    def setUp(self):
     
    362349    def test_heterogeneous_qs_combination(self):
    363350        # Combining querysets built on different models should behave in a well-defined
    364351        # fashion. We raise an error.
    365         self.assertRaisesMessage(
     352        self.assertRaisesRegexp(
    366353            AssertionError,
    367             'Cannot combine queries on two different base models.',
     354            'Cannot combine queries on two different base models\.',
    368355            lambda: Author.objects.all() & Tag.objects.all()
    369356        )
    370         self.assertRaisesMessage(
     357        self.assertRaisesRegexp(
    371358            AssertionError,
    372             'Cannot combine queries on two different base models.',
     359            'Cannot combine queries on two different base models\.',
    373360            lambda: Author.objects.all() | Tag.objects.all()
    374361        )
    375362
     
    676663            []
    677664        )
    678665        q.query.low_mark = 1
    679         self.assertRaisesMessage(
     666        self.assertRaisesRegexp(
    680667            AssertionError,
    681668            'Cannot change a query once a slice has been taken',
    682669            q.extra, select={'is_recent': "pub_date > '2006-01-01'"}
     
    707694        )
    708695
    709696        # Multi-valued values() and values_list() querysets should raise errors.
    710         self.assertRaisesMessage(
     697        self.assertRaisesRegexp(
    711698            TypeError,
    712             'Cannot use a multi-field ValuesQuerySet as a filter value.',
     699            'Cannot use a multi-field ValuesQuerySet as a filter value\.',
    713700            lambda: Tag.objects.filter(name__in=Tag.objects.filter(parent=self.t1).values('name', 'id'))
    714701        )
    715         self.assertRaisesMessage(
     702        self.assertRaisesRegexp(
    716703            TypeError,
    717             'Cannot use a multi-field ValuesListQuerySet as a filter value.',
     704            'Cannot use a multi-field ValuesListQuerySet as a filter value\.',
    718705            lambda: Tag.objects.filter(name__in=Tag.objects.filter(parent=self.t1).values_list('name', 'id'))
    719706        )
    720707
     
    954941    def test_ticket8683(self):
    955942        # Raise proper error when a DateQuerySet gets passed a wrong type of
    956943        # field
    957         self.assertRaisesMessage(
     944        self.assertRaisesRegexp(
    958945            AssertionError,
    959             "'name' isn't a DateField.",
     946            "'name' isn't a DateField\.",
    960947            Item.objects.dates, 'name', 'month'
    961948        )
    962949
     
    14841471        self.assertQuerysetEqual(Article.objects.all()[0:0], [])
    14851472        self.assertQuerysetEqual(Article.objects.all()[0:0][:10], [])
    14861473        self.assertEqual(Article.objects.all()[:0].count(), 0)
    1487         self.assertRaisesMessage(
     1474        self.assertRaisesRegexp(
    14881475            AssertionError,
    1489             'Cannot change a query once a slice has been taken.',
     1476            'Cannot change a query once a slice has been taken\.',
    14901477            Article.objects.all()[:0].latest, 'created'
    14911478        )
    14921479
     
    15311518    def test_infinite_loop(self):
    15321519        # If you're not careful, it's possible to introduce infinite loops via
    15331520        # default ordering on foreign keys in a cycle. We detect that.
    1534         self.assertRaisesMessage(
     1521        self.assertRaisesRegexp(
    15351522            FieldError,
    1536             'Infinite loop caused by ordering.',
     1523            'Infinite loop caused by ordering\.',
    15371524            lambda: list(LoopX.objects.all()) # Force queryset evaluation with list()
    15381525        )
    1539         self.assertRaisesMessage(
     1526        self.assertRaisesRegexp(
    15401527            FieldError,
    1541             'Infinite loop caused by ordering.',
     1528            'Infinite loop caused by ordering\.',
    15421529            lambda: list(LoopZ.objects.all()) # Force queryset evaluation with list()
    15431530        )
    15441531
  • 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,
    151             "The included urlconf regressiontests.urlpatterns_reverse.no_urls "\
     142        self.assertRaisesRegexp(ImproperlyConfigured,
     143            "The included urlconf regressiontests\.urlpatterns_reverse\.no_urls "\
    152144            "doesn't have any patterns in it", getattr, resolver, 'url_patterns')
    153145
    154146class URLPatternReverse(TestCase):
  • 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.copycompat import copy
    87from django.utils.datastructures import *
     8from django.utils.unittest import TestCase
    99
    1010
    11 class DatastructuresTestCase(unittest.TestCase):
    12     def assertRaisesErrorWithMessage(self, error, message, callable,
    13         *args, **kwargs):
    14         self.assertRaises(error, callable, *args, **kwargs)
    15         try:
    16             callable(*args, **kwargs)
    17         except error, e:
    18             self.assertEqual(message, str(e))
    19 
    20 
    21 class SortedDictTests(DatastructuresTestCase):
     11class SortedDictTests(TestCase):
    2212    def setUp(self):
    2313        self.d1 = SortedDict()
    2414        self.d1[7] = 'seven'
     
    124114        self.assertEquals(self.d1, {})
    125115        self.assertEquals(self.d1.keyOrder, [])
    126116
    127 class MergeDictTests(DatastructuresTestCase):
     117class MergeDictTests(TestCase):
    128118
    129119    def test_simple_mergedict(self):
    130120        d1 = {'chris':'cool', 'camri':'cute', 'cotton':'adorable',
     
    178168                           ('key2', ['value2', 'value3']),
    179169                           ('key4', ['value5', 'value6'])])
    180170
    181 class MultiValueDictTests(DatastructuresTestCase):
     171class MultiValueDictTests(TestCase):
    182172
    183173    def test_multivaluedict(self):
    184174        d = MultiValueDict({'name': ['Adrian', 'Simon'],
     
    197187        # MultiValueDictKeyError: "Key 'lastname' not found in
    198188        # <MultiValueDict: {'position': ['Developer'],
    199189        #                   'name': ['Adrian', 'Simon']}>"
    200         self.assertRaisesErrorWithMessage(MultiValueDictKeyError,
    201             '"Key \'lastname\' not found in <MultiValueDict: {\'position\':'\
    202             ' [\'Developer\'], \'name\': [\'Adrian\', \'Simon\']}>"',
     190        self.assertRaisesRegexp(MultiValueDictKeyError,
     191            '"Key \'lastname\' not found in \<MultiValueDict: \{\'position\':'\
     192            ' \[\'Developer\'\], \'name\': \[\'Adrian\', \'Simon\'\]\}\>"',
    203193            d.__getitem__, 'lastname')
    204194
    205195        self.assertEquals(d.get('lastname'), None)
     
    233223            self.assertEqual(d2["key"], ["Penguin"])
    234224
    235225
    236 class DotExpandedDictTests(DatastructuresTestCase):
     226class DotExpandedDictTests(TestCase):
    237227
    238228    def test_dotexpandeddict(self):
    239229
     
    247237        self.assertEquals(d['person']['2']['firstname'], ['Adrian'])
    248238
    249239
    250 class ImmutableListTests(DatastructuresTestCase):
     240class ImmutableListTests(TestCase):
    251241
    252242    def test_sort(self):
    253243        d = ImmutableList(range(10))
    254244
    255245        # AttributeError: ImmutableList object is immutable.
    256         self.assertRaisesErrorWithMessage(AttributeError,
    257             'ImmutableList object is immutable.', d.sort)
     246        self.assertRaisesRegexp(AttributeError,
     247            'ImmutableList object is immutable\.', d.sort)
    258248
    259249        self.assertEquals(repr(d), '(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)')
    260250
     
    264254        self.assertEquals(d[1], 1)
    265255
    266256        # AttributeError: Object is immutable!
    267         self.assertRaisesErrorWithMessage(AttributeError,
     257        self.assertRaisesRegexp(AttributeError,
    268258            'Object is immutable!', d.__setitem__, 1, 'test')
    269259
    270260
    271 class DictWrapperTests(DatastructuresTestCase):
     261class DictWrapperTests(TestCase):
    272262
    273263    def test_dictwrapper(self):
    274264        f = lambda x: "*%s" % x
Back to Top