Code

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

File 14503-replacement-with-assertraisesregexp.diff, 82.7 KB (added by ramiro, 3 years ago)

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

Line 
1diff --git a/tests/regressiontests/admin_validation/tests.py b/tests/regressiontests/admin_validation/tests.py
2--- a/tests/regressiontests/admin_validation/tests.py
3+++ b/tests/regressiontests/admin_validation/tests.py
4@@ -18,13 +18,6 @@
5     fields = ['spam']
6 
7 class ValidationTestCase(TestCase):
8-    def assertRaisesMessage(self, exc, msg, func, *args, **kwargs):
9-        try:
10-            func(*args, **kwargs)
11-        except Exception, e:
12-            self.assertEqual(msg, str(e))
13-            self.assertTrue(isinstance(e, exc), "Expected %s, got %s" % (exc, type(e)))
14-
15     def test_readonly_and_editable(self):
16         class SongAdmin(admin.ModelAdmin):
17             readonly_fields = ["original_release"]
18@@ -40,7 +33,7 @@
19         # Regression test for #8027: custom ModelForms with fields/fieldsets
20         """
21         validate(ValidFields, Song)
22-        self.assertRaisesMessage(ImproperlyConfigured,
23+        self.assertRaisesRegexp(ImproperlyConfigured,
24             "'InvalidFields.fields' refers to field 'spam' that is missing from the form.",
25             validate,
26             InvalidFields, Song)
27@@ -51,7 +44,7 @@
28         """
29         class ExcludedFields1(admin.ModelAdmin):
30             exclude = ('foo')
31-        self.assertRaisesMessage(ImproperlyConfigured,
32+        self.assertRaisesRegexp(ImproperlyConfigured,
33             "'ExcludedFields1.exclude' must be a list or tuple.",
34             validate,
35             ExcludedFields1, Book)
36@@ -59,8 +52,8 @@
37     def test_exclude_duplicate_values(self):
38         class ExcludedFields2(admin.ModelAdmin):
39             exclude = ('name', 'name')
40-        self.assertRaisesMessage(ImproperlyConfigured,
41-            "There are duplicate field(s) in ExcludedFields2.exclude",
42+        self.assertRaisesRegexp(ImproperlyConfigured,
43+            "There are duplicate field\(s\) in ExcludedFields2.exclude",
44             validate,
45             ExcludedFields2, Book)
46 
47@@ -73,7 +66,7 @@
48             model = Album
49             inlines = [ExcludedFieldsInline]
50 
51-        self.assertRaisesMessage(ImproperlyConfigured,
52+        self.assertRaisesRegexp(ImproperlyConfigured,
53             "'ExcludedFieldsInline.exclude' must be a list or tuple.",
54             validate,
55             ExcludedFieldsAlbumAdmin, Album)
56@@ -91,7 +84,7 @@
57             model = Album
58             inlines = [SongInline]
59 
60-        self.assertRaisesMessage(ImproperlyConfigured,
61+        self.assertRaisesRegexp(ImproperlyConfigured,
62             "SongInline cannot exclude the field 'album' - this is the foreign key to the parent model Album.",
63             validate,
64             AlbumAdmin, Album)
65@@ -112,7 +105,7 @@
66         class TwoAlbumFKAndAnEInline(admin.TabularInline):
67             model = TwoAlbumFKAndAnE
68 
69-        self.assertRaisesMessage(Exception,
70+        self.assertRaisesRegexp(Exception,
71             "<class 'regressiontests.admin_validation.models.TwoAlbumFKAndAnE'> has more than 1 ForeignKey to <class 'regressiontests.admin_validation.models.Album'>",
72             validate_inline,
73             TwoAlbumFKAndAnEInline, None, Album)
74@@ -157,8 +150,8 @@
75         class SongAdmin(admin.ModelAdmin):
76             readonly_fields = ("title", "nonexistant")
77 
78-        self.assertRaisesMessage(ImproperlyConfigured,
79-            "SongAdmin.readonly_fields[1], 'nonexistant' is not a callable or an attribute of 'SongAdmin' or found in the model 'Song'.",
80+        self.assertRaisesRegexp(ImproperlyConfigured,
81+            "SongAdmin.readonly_fields\[1\], 'nonexistant' is not a callable or an attribute of 'SongAdmin' or found in the model 'Song'.",
82             validate,
83             SongAdmin, Song)
84 
85@@ -186,7 +179,7 @@
86         class BookAdmin(admin.ModelAdmin):
87             fields = ['authors']
88 
89-        self.assertRaisesMessage(ImproperlyConfigured,
90+        self.assertRaisesRegexp(ImproperlyConfigured,
91             "'BookAdmin.fields' can't include the ManyToManyField field 'authors' because 'authors' manually specifies a 'through' model.",
92             validate,
93             BookAdmin, Book)
94@@ -197,8 +190,8 @@
95                 ('Header 1', {'fields': ('name',)}),
96                 ('Header 2', {'fields': ('authors',)}),
97             )
98-        self.assertRaisesMessage(ImproperlyConfigured,
99-            "'FieldsetBookAdmin.fieldsets[1][1]['fields']' can't include the ManyToManyField field 'authors' because 'authors' manually specifies a 'through' model.",
100+        self.assertRaisesRegexp(ImproperlyConfigured,
101+            "'FieldsetBookAdmin.fieldsets\[1\]\[1\]\['fields'\]' can't include the ManyToManyField field 'authors' because 'authors' manually specifies a 'through' model.",
102             validate,
103             FieldsetBookAdmin, Book)
104 
105diff --git a/tests/regressiontests/custom_columns_regress/tests.py b/tests/regressiontests/custom_columns_regress/tests.py
106--- a/tests/regressiontests/custom_columns_regress/tests.py
107+++ b/tests/regressiontests/custom_columns_regress/tests.py
108@@ -9,13 +9,6 @@
109 
110 class CustomColumnRegression(TestCase):
111 
112-    def assertRaisesMessage(self, exc, msg, func, *args, **kwargs):
113-        try:
114-            func(*args, **kwargs)
115-        except Exception, e:
116-            self.assertEqual(msg, str(e))
117-            self.assertTrue(isinstance(e, exc), "Expected %s, got %s" % (exc, type(e)))
118-
119     def setUp(self):
120         self.a1 = Author.objects.create(first_name='John', last_name='Smith')
121         self.a2 = Author.objects.create(first_name='Peter', last_name='Jones')
122@@ -42,7 +35,7 @@
123         self.assertEqual(self.a1, Author.objects.get(first_name__exact='John'))
124 
125     def test_filter_on_nonexistant_field(self):
126-        self.assertRaisesMessage(
127+        self.assertRaisesRegexp(
128             FieldError,
129             "Cannot resolve keyword 'firstname' into field. Choices are: Author_ID, article, first_name, last_name, primary_set",
130             Author.objects.filter,
131@@ -53,14 +46,14 @@
132         a = Author.objects.get(last_name__exact='Smith')
133         self.assertEqual('John', a.first_name)
134         self.assertEqual('Smith', a.last_name)
135-        self.assertRaisesMessage(
136+        self.assertRaisesRegexp(
137             AttributeError,
138             "'Author' object has no attribute 'firstname'",
139             getattr,
140             a, 'firstname'
141         )
142 
143-        self.assertRaisesMessage(
144+        self.assertRaisesRegexp(
145             AttributeError,
146             "'Author' object has no attribute 'last'",
147             getattr,
148diff --git a/tests/regressiontests/file_storage/tests.py b/tests/regressiontests/file_storage/tests.py
149--- a/tests/regressiontests/file_storage/tests.py
150+++ b/tests/regressiontests/file_storage/tests.py
151@@ -13,6 +13,7 @@
152 from django.core.files.storage import FileSystemStorage, get_storage_class
153 from django.core.files.uploadedfile import UploadedFile
154 from django.core.exceptions import ImproperlyConfigured
155+from django.test import TestCase
156 from django.utils import unittest
157 
158 try:
159@@ -31,15 +32,7 @@
160     except ImportError:
161         Image = None
162 
163-class GetStorageClassTests(unittest.TestCase):
164-    def assertRaisesErrorWithMessage(self, error, message, callable,
165-        *args, **kwargs):
166-        self.assertRaises(error, callable, *args, **kwargs)
167-        try:
168-            callable(*args, **kwargs)
169-        except error, e:
170-            self.assertEqual(message, str(e))
171-
172+class GetStorageClassTests(TestCase):
173     def test_get_filesystem_storage(self):
174         """
175         get_storage_class returns the class for a storage backend name/path.
176@@ -52,7 +45,7 @@
177         """
178         get_storage_class raises an error if the requested import don't exist.
179         """
180-        self.assertRaisesErrorWithMessage(
181+        self.assertRaisesRegexp(
182             ImproperlyConfigured,
183             "NonExistingStorage isn't a storage module.",
184             get_storage_class,
185@@ -62,7 +55,7 @@
186         """
187         get_storage_class raises an error if the requested class don't exist.
188         """
189-        self.assertRaisesErrorWithMessage(
190+        self.assertRaisesRegexp(
191             ImproperlyConfigured,
192             'Storage module "django.core.files.storage" does not define a '\
193                 '"NonExistingStorage" class.',
194@@ -73,7 +66,7 @@
195         """
196         get_storage_class raises an error if the requested module don't exist.
197         """
198-        self.assertRaisesErrorWithMessage(
199+        self.assertRaisesRegexp(
200             ImproperlyConfigured,
201             'Error importing storage module django.core.files.non_existing_'\
202                 'storage: "No module named non_existing_storage"',
203diff --git a/tests/regressiontests/fixtures_regress/tests.py b/tests/regressiontests/fixtures_regress/tests.py
204--- a/tests/regressiontests/fixtures_regress/tests.py
205+++ b/tests/regressiontests/fixtures_regress/tests.py
206@@ -343,13 +343,6 @@
207 
208 
209 class NaturalKeyFixtureTests(TestCase):
210-    def assertRaisesMessage(self, exc, msg, func, *args, **kwargs):
211-        try:
212-            func(*args, **kwargs)
213-        except Exception, e:
214-            self.assertEqual(msg, str(e))
215-            self.assertTrue(isinstance(e, exc), "Expected %s, got %s" % (exc, type(e)))
216-
217     def test_nk_deserialize(self):
218         """
219         Test for ticket #13030 - Python based parser version
220@@ -507,7 +500,7 @@
221         )
222 
223     def test_dependency_sorting_tight_circular(self):
224-        self.assertRaisesMessage(
225+        self.assertRaisesRegexp(
226             CommandError,
227             """Can't resolve dependencies for fixtures_regress.Circle1, fixtures_regress.Circle2 in serialized app list.""",
228             sort_dependencies,
229@@ -515,7 +508,7 @@
230         )
231 
232     def test_dependency_sorting_tight_circular_2(self):
233-        self.assertRaisesMessage(
234+        self.assertRaisesRegexp(
235             CommandError,
236             """Can't resolve dependencies for fixtures_regress.Circle1, fixtures_regress.Circle2 in serialized app list.""",
237             sort_dependencies,
238@@ -523,7 +516,7 @@
239         )
240 
241     def test_dependency_self_referential(self):
242-        self.assertRaisesMessage(
243+        self.assertRaisesRegexp(
244             CommandError,
245             """Can't resolve dependencies for fixtures_regress.Circle3 in serialized app list.""",
246             sort_dependencies,
247@@ -531,7 +524,7 @@
248         )
249 
250     def test_dependency_sorting_long(self):
251-        self.assertRaisesMessage(
252+        self.assertRaisesRegexp(
253             CommandError,
254             """Can't resolve dependencies for fixtures_regress.Circle1, fixtures_regress.Circle2, fixtures_regress.Circle3 in serialized app list.""",
255             sort_dependencies,
256diff --git a/tests/regressiontests/forms/fields.py b/tests/regressiontests/forms/fields.py
257--- a/tests/regressiontests/forms/fields.py
258+++ b/tests/regressiontests/forms/fields.py
259@@ -33,7 +33,7 @@
260 from django.core.files.uploadedfile import SimpleUploadedFile
261 from django.forms import *
262 from django.forms.widgets import RadioFieldRenderer
263-from django.utils.unittest import TestCase
264+from django.test import TestCase
265 
266 
267 def fix_os_paths(x):
268@@ -49,13 +49,6 @@
269 
270 class FieldsTests(TestCase):
271 
272-    def assertRaisesErrorWithMessage(self, error, message, callable, *args, **kwargs):
273-        self.assertRaises(error, callable, *args, **kwargs)
274-        try:
275-            callable(*args, **kwargs)
276-        except error, e:
277-            self.assertEqual(message, str(e))
278-
279     def test_field_sets_widget_is_required(self):
280         self.assertEqual(Field(required=True).widget.is_required, True)
281         self.assertEqual(Field(required=False).widget.is_required, False)
282@@ -66,8 +59,8 @@
283         f = CharField()
284         self.assertEqual(u'1', f.clean(1))
285         self.assertEqual(u'hello', f.clean('hello'))
286-        self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
287-        self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
288+        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, None)
289+        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, '')
290         self.assertEqual(u'[1, 2, 3]', f.clean([1, 2, 3]))
291 
292     def test_charfield_1(self):
293@@ -82,19 +75,19 @@
294         f = CharField(max_length=10, required=False)
295         self.assertEqual(u'12345', f.clean('12345'))
296         self.assertEqual(u'1234567890', f.clean('1234567890'))
297-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value has at most 10 characters (it has 11).']", f.clean, '1234567890a')
298+        self.assertRaisesRegexp(ValidationError, "u'Ensure this value has at most 10 characters \(it has 11\).'", f.clean, '1234567890a')
299 
300     def test_charfield_3(self):
301         f = CharField(min_length=10, required=False)
302         self.assertEqual(u'', f.clean(''))
303-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value has at least 10 characters (it has 5).']", f.clean, '12345')
304+        self.assertRaisesRegexp(ValidationError, "u'Ensure this value has at least 10 characters \(it has 5\).'", f.clean, '12345')
305         self.assertEqual(u'1234567890', f.clean('1234567890'))
306         self.assertEqual(u'1234567890a', f.clean('1234567890a'))
307 
308     def test_charfield_4(self):
309         f = CharField(min_length=10, required=True)
310-        self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
311-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value has at least 10 characters (it has 5).']", f.clean, '12345')
312+        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, '')
313+        self.assertRaisesRegexp(ValidationError, "u'Ensure this value has at least 10 characters \(it has 5\).'", f.clean, '12345')
314         self.assertEqual(u'1234567890', f.clean('1234567890'))
315         self.assertEqual(u'1234567890a', f.clean('1234567890a'))
316 
317@@ -102,18 +95,18 @@
318 
319     def test_integerfield_5(self):
320         f = IntegerField()
321-        self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
322-        self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
323+        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, '')
324+        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, None)
325         self.assertEqual(1, f.clean('1'))
326         self.assertEqual(True, isinstance(f.clean('1'), int))
327         self.assertEqual(23, f.clean('23'))
328-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a whole number.']", f.clean, 'a')
329+        self.assertRaisesRegexp(ValidationError, "u'Enter a whole number.'", f.clean, 'a')
330         self.assertEqual(42, f.clean(42))
331-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a whole number.']", f.clean, 3.14)
332+        self.assertRaisesRegexp(ValidationError, "u'Enter a whole number.'", f.clean, 3.14)
333         self.assertEqual(1, f.clean('1 '))
334         self.assertEqual(1, f.clean(' 1'))
335         self.assertEqual(1, f.clean(' 1 '))
336-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a whole number.']", f.clean, '1a')
337+        self.assertRaisesRegexp(ValidationError, "u'Enter a whole number.'", f.clean, '1a')
338 
339     def test_integerfield_6(self):
340         f = IntegerField(required=False)
341@@ -124,25 +117,25 @@
342         self.assertEqual(1, f.clean('1'))
343         self.assertEqual(True, isinstance(f.clean('1'), int))
344         self.assertEqual(23, f.clean('23'))
345-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a whole number.']", f.clean, 'a')
346+        self.assertRaisesRegexp(ValidationError, "u'Enter a whole number.'", f.clean, 'a')
347         self.assertEqual(1, f.clean('1 '))
348         self.assertEqual(1, f.clean(' 1'))
349         self.assertEqual(1, f.clean(' 1 '))
350-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a whole number.']", f.clean, '1a')
351+        self.assertRaisesRegexp(ValidationError, "u'Enter a whole number.'", f.clean, '1a')
352 
353     def test_integerfield_7(self):
354         f = IntegerField(max_value=10)
355-        self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
356+        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, None)
357         self.assertEqual(1, f.clean(1))
358         self.assertEqual(10, f.clean(10))
359-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value is less than or equal to 10.']", f.clean, 11)
360+        self.assertRaisesRegexp(ValidationError, "u'Ensure this value is less than or equal to 10.'", f.clean, 11)
361         self.assertEqual(10, f.clean('10'))
362-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value is less than or equal to 10.']", f.clean, '11')
363+        self.assertRaisesRegexp(ValidationError, "u'Ensure this value is less than or equal to 10.'", f.clean, '11')
364 
365     def test_integerfield_8(self):
366         f = IntegerField(min_value=10)
367-        self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
368-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value is greater than or equal to 10.']", f.clean, 1)
369+        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, None)
370+        self.assertRaisesRegexp(ValidationError, "u'Ensure this value is greater than or equal to 10.'", f.clean, 1)
371         self.assertEqual(10, f.clean(10))
372         self.assertEqual(11, f.clean(11))
373         self.assertEqual(10, f.clean('10'))
374@@ -150,32 +143,32 @@
375 
376     def test_integerfield_9(self):
377         f = IntegerField(min_value=10, max_value=20)
378-        self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
379-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value is greater than or equal to 10.']", f.clean, 1)
380+        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, None)
381+        self.assertRaisesRegexp(ValidationError, "u'Ensure this value is greater than or equal to 10.'", f.clean, 1)
382         self.assertEqual(10, f.clean(10))
383         self.assertEqual(11, f.clean(11))
384         self.assertEqual(10, f.clean('10'))
385         self.assertEqual(11, f.clean('11'))
386         self.assertEqual(20, f.clean(20))
387-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value is less than or equal to 20.']", f.clean, 21)
388+        self.assertRaisesRegexp(ValidationError, "u'Ensure this value is less than or equal to 20.'", f.clean, 21)
389 
390     # FloatField ##################################################################
391 
392     def test_floatfield_10(self):
393         f = FloatField()
394-        self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
395-        self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
396+        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, '')
397+        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, None)
398         self.assertEqual(1.0, f.clean('1'))
399         self.assertEqual(True, isinstance(f.clean('1'), float))
400         self.assertEqual(23.0, f.clean('23'))
401         self.assertEqual(3.1400000000000001, f.clean('3.14'))
402         self.assertEqual(3.1400000000000001, f.clean(3.14))
403         self.assertEqual(42.0, f.clean(42))
404-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a number.']", f.clean, 'a')
405+        self.assertRaisesRegexp(ValidationError, "u'Enter a number.'", f.clean, 'a')
406         self.assertEqual(1.0, f.clean('1.0 '))
407         self.assertEqual(1.0, f.clean(' 1.0'))
408         self.assertEqual(1.0, f.clean(' 1.0 '))
409-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a number.']", f.clean, '1.0a')
410+        self.assertRaisesRegexp(ValidationError, "u'Enter a number.'", f.clean, '1.0a')
411 
412     def test_floatfield_11(self):
413         f = FloatField(required=False)
414@@ -185,8 +178,8 @@
415 
416     def test_floatfield_12(self):
417         f = FloatField(max_value=1.5, min_value=0.5)
418-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value is less than or equal to 1.5.']", f.clean, '1.6')
419-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value is greater than or equal to 0.5.']", f.clean, '0.4')
420+        self.assertRaisesRegexp(ValidationError, "u'Ensure this value is less than or equal to 1.5.'", f.clean, '1.6')
421+        self.assertRaisesRegexp(ValidationError, "u'Ensure this value is greater than or equal to 0.5.'", f.clean, '0.4')
422         self.assertEqual(1.5, f.clean('1.5'))
423         self.assertEqual(0.5, f.clean('0.5'))
424 
425@@ -194,34 +187,34 @@
426 
427     def test_decimalfield_13(self):
428         f = DecimalField(max_digits=4, decimal_places=2)
429-        self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
430-        self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
431+        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, '')
432+        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, None)
433         self.assertEqual(f.clean('1'), Decimal("1"))
434         self.assertEqual(True, isinstance(f.clean('1'), Decimal))
435         self.assertEqual(f.clean('23'), Decimal("23"))
436         self.assertEqual(f.clean('3.14'), Decimal("3.14"))
437         self.assertEqual(f.clean(3.14), Decimal("3.14"))
438         self.assertEqual(f.clean(Decimal('3.14')), Decimal("3.14"))
439-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a number.']", f.clean, 'NaN')
440-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a number.']", f.clean, 'Inf')
441-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a number.']", f.clean, '-Inf')
442-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a number.']", f.clean, 'a')
443-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a number.']", f.clean, u'łąść')
444+        self.assertRaisesRegexp(ValidationError, "u'Enter a number.'", f.clean, 'NaN')
445+        self.assertRaisesRegexp(ValidationError, "u'Enter a number.'", f.clean, 'Inf')
446+        self.assertRaisesRegexp(ValidationError, "u'Enter a number.'", f.clean, '-Inf')
447+        self.assertRaisesRegexp(ValidationError, "u'Enter a number.'", f.clean, 'a')
448+        self.assertRaisesRegexp(ValidationError, "u'Enter a number.'", f.clean, u'łąść')
449         self.assertEqual(f.clean('1.0 '), Decimal("1.0"))
450         self.assertEqual(f.clean(' 1.0'), Decimal("1.0"))
451         self.assertEqual(f.clean(' 1.0 '), Decimal("1.0"))
452-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a number.']", f.clean, '1.0a')
453-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure that there are no more than 4 digits in total.']", f.clean, '123.45')
454-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure that there are no more than 2 decimal places.']", f.clean, '1.234')
455-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure that there are no more than 2 digits before the decimal point.']", f.clean, '123.4')
456+        self.assertRaisesRegexp(ValidationError, "u'Enter a number.'", f.clean, '1.0a')
457+        self.assertRaisesRegexp(ValidationError, "u'Ensure that there are no more than 4 digits in total.'", f.clean, '123.45')
458+        self.assertRaisesRegexp(ValidationError, "u'Ensure that there are no more than 2 decimal places.'", f.clean, '1.234')
459+        self.assertRaisesRegexp(ValidationError, "u'Ensure that there are no more than 2 digits before the decimal point.'", f.clean, '123.4')
460         self.assertEqual(f.clean('-12.34'), Decimal("-12.34"))
461-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure that there are no more than 4 digits in total.']", f.clean, '-123.45')
462+        self.assertRaisesRegexp(ValidationError, "u'Ensure that there are no more than 4 digits in total.'", f.clean, '-123.45')
463         self.assertEqual(f.clean('-.12'), Decimal("-0.12"))
464         self.assertEqual(f.clean('-00.12'), Decimal("-0.12"))
465         self.assertEqual(f.clean('-000.12'), Decimal("-0.12"))
466-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure that there are no more than 2 decimal places.']", f.clean, '-000.123')
467-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure that there are no more than 4 digits in total.']", f.clean, '-000.12345')
468-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a number.']", f.clean, '--0.12')
469+        self.assertRaisesRegexp(ValidationError, "u'Ensure that there are no more than 2 decimal places.'", f.clean, '-000.123')
470+        self.assertRaisesRegexp(ValidationError, "u'Ensure that there are no more than 4 digits in total.'", f.clean, '-000.12345')
471+        self.assertRaisesRegexp(ValidationError, "u'Enter a number.'", f.clean, '--0.12')
472 
473     def test_decimalfield_14(self):
474         f = DecimalField(max_digits=4, decimal_places=2, required=False)
475@@ -231,8 +224,8 @@
476 
477     def test_decimalfield_15(self):
478         f = DecimalField(max_digits=4, decimal_places=2, max_value=Decimal('1.5'), min_value=Decimal('0.5'))
479-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value is less than or equal to 1.5.']", f.clean, '1.6')
480-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value is greater than or equal to 0.5.']", f.clean, '0.4')
481+        self.assertRaisesRegexp(ValidationError, "u'Ensure this value is less than or equal to 1.5.'", f.clean, '1.6')
482+        self.assertRaisesRegexp(ValidationError, "u'Ensure this value is greater than or equal to 0.5.'", f.clean, '0.4')
483         self.assertEqual(f.clean('1.5'), Decimal("1.5"))
484         self.assertEqual(f.clean('0.5'), Decimal("0.5"))
485         self.assertEqual(f.clean('.5'), Decimal("0.5"))
486@@ -240,7 +233,7 @@
487 
488     def test_decimalfield_16(self):
489         f = DecimalField(decimal_places=2)
490-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure that there are no more than 2 decimal places.']", f.clean, '0.00000001')
491+        self.assertRaisesRegexp(ValidationError, "u'Ensure that there are no more than 2 decimal places.'", f.clean, '0.00000001')
492 
493     def test_decimalfield_17(self):
494         f = DecimalField(max_digits=3)
495@@ -250,13 +243,13 @@
496         self.assertEqual(f.clean('0000000.100'), Decimal("0.100"))
497         # Only leading whole zeros "collapse" to one digit.
498         self.assertEqual(f.clean('000000.02'), Decimal('0.02'))
499-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure that there are no more than 3 digits in total.']", f.clean, '000000.0002')
500+        self.assertRaisesRegexp(ValidationError, "u'Ensure that there are no more than 3 digits in total.'", f.clean, '000000.0002')
501         self.assertEqual(f.clean('.002'), Decimal("0.002"))
502 
503     def test_decimalfield_18(self):
504         f = DecimalField(max_digits=2, decimal_places=2)
505         self.assertEqual(f.clean('.01'), Decimal(".01"))
506-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure that there are no more than 0 digits before the decimal point.']", f.clean, '1.1')
507+        self.assertRaisesRegexp(ValidationError, "u'Ensure that there are no more than 0 digits before the decimal point.'", f.clean, '1.1')
508 
509     # DateField ###################################################################
510 
511@@ -274,10 +267,10 @@
512         self.assertEqual(datetime.date(2006, 10, 25), f.clean('October 25, 2006'))
513         self.assertEqual(datetime.date(2006, 10, 25), f.clean('25 October 2006'))
514         self.assertEqual(datetime.date(2006, 10, 25), f.clean('25 October, 2006'))
515-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid date.']", f.clean, '2006-4-31')
516-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid date.']", f.clean, '200a-10-25')
517-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid date.']", f.clean, '25/10/06')
518-        self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
519+        self.assertRaisesRegexp(ValidationError, "u'Enter a valid date.'", f.clean, '2006-4-31')
520+        self.assertRaisesRegexp(ValidationError, "u'Enter a valid date.'", f.clean, '200a-10-25')
521+        self.assertRaisesRegexp(ValidationError, "u'Enter a valid date.'", f.clean, '25/10/06')
522+        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, None)
523 
524     def test_datefield_20(self):
525         f = DateField(required=False)
526@@ -291,9 +284,9 @@
527         self.assertEqual(datetime.date(2006, 10, 25), f.clean(datetime.date(2006, 10, 25)))
528         self.assertEqual(datetime.date(2006, 10, 25), f.clean(datetime.datetime(2006, 10, 25, 14, 30)))
529         self.assertEqual(datetime.date(2006, 10, 25), f.clean('2006 10 25'))
530-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid date.']", f.clean, '2006-10-25')
531-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid date.']", f.clean, '10/25/2006')
532-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid date.']", f.clean, '10/25/06')
533+        self.assertRaisesRegexp(ValidationError, "u'Enter a valid date.'", f.clean, '2006-10-25')
534+        self.assertRaisesRegexp(ValidationError, "u'Enter a valid date.'", f.clean, '10/25/2006')
535+        self.assertRaisesRegexp(ValidationError, "u'Enter a valid date.'", f.clean, '10/25/06')
536 
537     # TimeField ###################################################################
538 
539@@ -303,8 +296,8 @@
540         self.assertEqual(datetime.time(14, 25, 59), f.clean(datetime.time(14, 25, 59)))
541         self.assertEqual(datetime.time(14, 25), f.clean('14:25'))
542         self.assertEqual(datetime.time(14, 25, 59), f.clean('14:25:59'))
543-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid time.']", f.clean, 'hello')
544-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid time.']", f.clean, '1:24 p.m.')
545+        self.assertRaisesRegexp(ValidationError, "u'Enter a valid time.'", f.clean, 'hello')
546+        self.assertRaisesRegexp(ValidationError, "u'Enter a valid time.'", f.clean, '1:24 p.m.')
547 
548     def test_timefield_23(self):
549         f = TimeField(input_formats=['%I:%M %p'])
550@@ -312,7 +305,7 @@
551         self.assertEqual(datetime.time(14, 25, 59), f.clean(datetime.time(14, 25, 59)))
552         self.assertEqual(datetime.time(4, 25), f.clean('4:25 AM'))
553         self.assertEqual(datetime.time(16, 25), f.clean('4:25 PM'))
554-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid time.']", f.clean, '14:30:45')
555+        self.assertRaisesRegexp(ValidationError, "u'Enter a valid time.'", f.clean, '14:30:45')
556 
557     # DateTimeField ###############################################################
558 
559@@ -334,8 +327,8 @@
560         self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30), f.clean('10/25/06 14:30:00'))
561         self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30), f.clean('10/25/06 14:30'))
562         self.assertEqual(datetime.datetime(2006, 10, 25, 0, 0), f.clean('10/25/06'))
563-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid date/time.']", f.clean, 'hello')
564-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid date/time.']", f.clean, '2006-10-25 4:30 p.m.')
565+        self.assertRaisesRegexp(ValidationError, "u'Enter a valid date/time.'", f.clean, 'hello')
566+        self.assertRaisesRegexp(ValidationError, "u'Enter a valid date/time.'", f.clean, '2006-10-25 4:30 p.m.')
567 
568     def test_datetimefield_25(self):
569         f = DateTimeField(input_formats=['%Y %m %d %I:%M %p'])
570@@ -344,7 +337,7 @@
571         self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30, 59), f.clean(datetime.datetime(2006, 10, 25, 14, 30, 59)))
572         self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30, 59, 200), f.clean(datetime.datetime(2006, 10, 25, 14, 30, 59, 200)))
573         self.assertEqual(datetime.datetime(2006, 10, 25, 14, 30), f.clean('2006 10 25 2:30 PM'))
574-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid date/time.']", f.clean, '2006-10-25 14:30:45')
575+        self.assertRaisesRegexp(ValidationError, "u'Enter a valid date/time.'", f.clean, '2006-10-25 14:30:45')
576 
577     def test_datetimefield_26(self):
578         f = DateTimeField(required=False)
579@@ -359,67 +352,67 @@
580         f = RegexField('^\d[A-F]\d$')
581         self.assertEqual(u'2A2', f.clean('2A2'))
582         self.assertEqual(u'3F3', f.clean('3F3'))
583-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid value.']", f.clean, '3G3')
584-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid value.']", f.clean, ' 2A2')
585-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid value.']", f.clean, '2A2 ')
586-        self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
587+        self.assertRaisesRegexp(ValidationError, "u'Enter a valid value.'", f.clean, '3G3')
588+        self.assertRaisesRegexp(ValidationError, "u'Enter a valid value.'", f.clean, ' 2A2')
589+        self.assertRaisesRegexp(ValidationError, "u'Enter a valid value.'", f.clean, '2A2 ')
590+        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, '')
591 
592     def test_regexfield_28(self):
593         f = RegexField('^\d[A-F]\d$', required=False)
594         self.assertEqual(u'2A2', f.clean('2A2'))
595         self.assertEqual(u'3F3', f.clean('3F3'))
596-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid value.']", f.clean, '3G3')
597+        self.assertRaisesRegexp(ValidationError, "u'Enter a valid value.'", f.clean, '3G3')
598         self.assertEqual(u'', f.clean(''))
599 
600     def test_regexfield_29(self):
601         f = RegexField(re.compile('^\d[A-F]\d$'))
602         self.assertEqual(u'2A2', f.clean('2A2'))
603         self.assertEqual(u'3F3', f.clean('3F3'))
604-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid value.']", f.clean, '3G3')
605-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid value.']", f.clean, ' 2A2')
606-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid value.']", f.clean, '2A2 ')
607+        self.assertRaisesRegexp(ValidationError, "'Enter a valid value.'", f.clean, '3G3')
608+        self.assertRaisesRegexp(ValidationError, "u'Enter a valid value.'", f.clean, ' 2A2')
609+        self.assertRaisesRegexp(ValidationError, "u'Enter a valid value.'", f.clean, '2A2 ')
610 
611     def test_regexfield_30(self):
612         f = RegexField('^\d\d\d\d$', error_message='Enter a four-digit number.')
613         self.assertEqual(u'1234', f.clean('1234'))
614-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a four-digit number.']", f.clean, '123')
615-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a four-digit number.']", f.clean, 'abcd')
616+        self.assertRaisesRegexp(ValidationError, "u'Enter a four-digit number.'", f.clean, '123')
617+        self.assertRaisesRegexp(ValidationError, "u'Enter a four-digit number.'", f.clean, 'abcd')
618 
619     def test_regexfield_31(self):
620         f = RegexField('^\d+$', min_length=5, max_length=10)
621-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value has at least 5 characters (it has 3).']", f.clean, '123')
622-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value has at least 5 characters (it has 3).', u'Enter a valid value.']", f.clean, 'abc')
623+        self.assertRaisesRegexp(ValidationError, "u'Ensure this value has at least 5 characters \(it has 3\).'", f.clean, '123')
624+        self.assertRaisesRegexp(ValidationError, "u'Ensure this value has at least 5 characters \(it has 3\).', u'Enter a valid value.'", f.clean, 'abc')
625         self.assertEqual(u'12345', f.clean('12345'))
626         self.assertEqual(u'1234567890', f.clean('1234567890'))
627-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value has at most 10 characters (it has 11).']", f.clean, '12345678901')
628-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid value.']", f.clean, '12345a')
629+        self.assertRaisesRegexp(ValidationError, "u'Ensure this value has at most 10 characters \(it has 11\).'", f.clean, '12345678901')
630+        self.assertRaisesRegexp(ValidationError, "u'Enter a valid value.'", f.clean, '12345a')
631 
632     # EmailField ##################################################################
633 
634     def test_emailfield_32(self):
635         f = EmailField()
636-        self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
637-        self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
638+        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, '')
639+        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, None)
640         self.assertEqual(u'person@example.com', f.clean('person@example.com'))
641-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'foo')
642-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'foo@')
643-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'foo@bar')
644-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'example@invalid-.com')
645-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'example@-invalid.com')
646-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'example@inv-.alid-.com')
647-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'example@inv-.-alid.com')
648+        self.assertRaisesRegexp(ValidationError, "u'Enter a valid e-mail address.'", f.clean, 'foo')
649+        self.assertRaisesRegexp(ValidationError, "u'Enter a valid e-mail address.'", f.clean, 'foo@')
650+        self.assertRaisesRegexp(ValidationError, "u'Enter a valid e-mail address.'", f.clean, 'foo@bar')
651+        self.assertRaisesRegexp(ValidationError, "u'Enter a valid e-mail address.'", f.clean, 'example@invalid-.com')
652+        self.assertRaisesRegexp(ValidationError, "u'Enter a valid e-mail address.'", f.clean, 'example@-invalid.com')
653+        self.assertRaisesRegexp(ValidationError, "u'Enter a valid e-mail address.'", f.clean, 'example@inv-.alid-.com')
654+        self.assertRaisesRegexp(ValidationError, "u'Enter a valid e-mail address.'", f.clean, 'example@inv-.-alid.com')
655         self.assertEqual(u'example@valid-----hyphens.com', f.clean('example@valid-----hyphens.com'))
656         self.assertEqual(u'example@valid-with-hyphens.com', f.clean('example@valid-with-hyphens.com'))
657-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'example@.com')
658+        self.assertRaisesRegexp(ValidationError, "u'Enter a valid e-mail address.'", f.clean, 'example@.com')
659         self.assertEqual(u'local@domain.with.idn.xyz\xe4\xf6\xfc\xdfabc.part.com', f.clean('local@domain.with.idn.xyzäöüßabc.part.com'))
660 
661     def test_email_regexp_for_performance(self):
662         f = EmailField()
663         # Check for runaway regex security problem. This will take for-freeking-ever
664         # if the security fix isn't in place.
665-        self.assertRaisesErrorWithMessage(
666+        self.assertRaisesRegexp(
667                 ValidationError,
668-                "[u'Enter a valid e-mail address.']",
669+                "u'Enter a valid e-mail address.'",
670                 f.clean,
671                 'viewx3dtextx26qx3d@yahoo.comx26latlngx3d15854521645943074058'
672             )
673@@ -430,39 +423,39 @@
674         self.assertEqual(u'', f.clean(None))
675         self.assertEqual(u'person@example.com', f.clean('person@example.com'))
676         self.assertEqual(u'example@example.com', f.clean('      example@example.com  \t   \t '))
677-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'foo')
678-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'foo@')
679-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'foo@bar')
680+        self.assertRaisesRegexp(ValidationError, "u'Enter a valid e-mail address.'", f.clean, 'foo')
681+        self.assertRaisesRegexp(ValidationError, "u'Enter a valid e-mail address.'", f.clean, 'foo@')
682+        self.assertRaisesRegexp(ValidationError, "u'Enter a valid e-mail address.'", f.clean, 'foo@bar')
683 
684     def test_emailfield_34(self):
685         f = EmailField(min_length=10, max_length=15)
686-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value has at least 10 characters (it has 9).']", f.clean, 'a@foo.com')
687+        self.assertRaisesRegexp(ValidationError, "u'Ensure this value has at least 10 characters \(it has 9\).'", f.clean, 'a@foo.com')
688         self.assertEqual(u'alf@foo.com', f.clean('alf@foo.com'))
689-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value has at most 15 characters (it has 20).']", f.clean, 'alf123456788@foo.com')
690+        self.assertRaisesRegexp(ValidationError, "u'Ensure this value has at most 15 characters \(it has 20\).'", f.clean, 'alf123456788@foo.com')
691 
692     # FileField ##################################################################
693 
694     def test_filefield_35(self):
695         f = FileField()
696-        self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
697-        self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '', '')
698+        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, '')
699+        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, '', '')
700         self.assertEqual('files/test1.pdf', f.clean('', 'files/test1.pdf'))
701-        self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
702-        self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None, '')
703+        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, None)
704+        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, None, '')
705         self.assertEqual('files/test2.pdf', f.clean(None, 'files/test2.pdf'))
706-        self.assertRaisesErrorWithMessage(ValidationError, "[u'No file was submitted. Check the encoding type on the form.']", f.clean, SimpleUploadedFile('', ''))
707-        self.assertRaisesErrorWithMessage(ValidationError, "[u'No file was submitted. Check the encoding type on the form.']", f.clean, SimpleUploadedFile('', ''), '')
708+        self.assertRaisesRegexp(ValidationError, "u'No file was submitted. Check the encoding type on the form.'", f.clean, SimpleUploadedFile('', ''))
709+        self.assertRaisesRegexp(ValidationError, "u'No file was submitted. Check the encoding type on the form.'", f.clean, SimpleUploadedFile('', ''), '')
710         self.assertEqual('files/test3.pdf', f.clean(None, 'files/test3.pdf'))
711-        self.assertRaisesErrorWithMessage(ValidationError, "[u'No file was submitted. Check the encoding type on the form.']", f.clean, 'some content that is not a file')
712-        self.assertRaisesErrorWithMessage(ValidationError, "[u'The submitted file is empty.']", f.clean, SimpleUploadedFile('name', None))
713-        self.assertRaisesErrorWithMessage(ValidationError, "[u'The submitted file is empty.']", f.clean, SimpleUploadedFile('name', ''))
714+        self.assertRaisesRegexp(ValidationError, "u'No file was submitted. Check the encoding type on the form.'", f.clean, 'some content that is not a file')
715+        self.assertRaisesRegexp(ValidationError, "u'The submitted file is empty.'", f.clean, SimpleUploadedFile('name', None))
716+        self.assertRaisesRegexp(ValidationError, "u'The submitted file is empty.'", f.clean, SimpleUploadedFile('name', ''))
717         self.assertEqual(SimpleUploadedFile, type(f.clean(SimpleUploadedFile('name', 'Some File Content'))))
718         self.assertEqual(SimpleUploadedFile, type(f.clean(SimpleUploadedFile('我隻氣墊船裝滿晒鱔.txt', 'मेरी मँडराने वाली नाव सर्पमीनों से भरी ह'))))
719         self.assertEqual(SimpleUploadedFile, type(f.clean(SimpleUploadedFile('name', 'Some File Content'), 'files/test4.pdf')))
720 
721     def test_filefield_36(self):
722         f = FileField(max_length = 5)
723-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this filename has at most 5 characters (it has 18).']", f.clean, SimpleUploadedFile('test_maxlength.txt', 'hello world'))
724+        self.assertRaisesRegexp(ValidationError, "u'Ensure this filename has at most 5 characters \(it has 18\).'", f.clean, SimpleUploadedFile('test_maxlength.txt', 'hello world'))
725         self.assertEqual('files/test1.pdf', f.clean('', 'files/test1.pdf'))
726         self.assertEqual('files/test2.pdf', f.clean(None, 'files/test2.pdf'))
727         self.assertEqual(SimpleUploadedFile, type(f.clean(SimpleUploadedFile('name', 'Some File Content'))))
728@@ -471,8 +464,8 @@
729 
730     def test_urlfield_37(self):
731         f = URLField()
732-        self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
733-        self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
734+        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, '')
735+        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, None)
736         self.assertEqual(u'http://localhost/', f.clean('http://localhost'))
737         self.assertEqual(u'http://example.com/', f.clean('http://example.com'))
738         self.assertEqual(u'http://example.com./', f.clean('http://example.com.'))
739@@ -482,28 +475,28 @@
740         self.assertEqual(u'http://subdomain.domain.com/', f.clean('subdomain.domain.com'))
741         self.assertEqual(u'http://200.8.9.10/', f.clean('http://200.8.9.10'))
742         self.assertEqual(u'http://200.8.9.10:8000/test', f.clean('http://200.8.9.10:8000/test'))
743-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'foo')
744-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://')
745-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://example')
746-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://example.')
747-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'com.')
748-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, '.')
749-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://.com')
750-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://invalid-.com')
751-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://-invalid.com')
752-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://inv-.alid-.com')
753-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://inv-.-alid.com')
754+        self.assertRaisesRegexp(ValidationError, "u'Enter a valid URL.'", f.clean, 'foo')
755+        self.assertRaisesRegexp(ValidationError, "u'Enter a valid URL.'", f.clean, 'http://')
756+        self.assertRaisesRegexp(ValidationError, "u'Enter a valid URL.'", f.clean, 'http://example')
757+        self.assertRaisesRegexp(ValidationError, "u'Enter a valid URL.'", f.clean, 'http://example.')
758+        self.assertRaisesRegexp(ValidationError, "u'Enter a valid URL.'", f.clean, 'com.')
759+        self.assertRaisesRegexp(ValidationError, "u'Enter a valid URL.'", f.clean, '.')
760+        self.assertRaisesRegexp(ValidationError, "u'Enter a valid URL.'", f.clean, 'http://.com')
761+        self.assertRaisesRegexp(ValidationError, "u'Enter a valid URL.'", f.clean, 'http://invalid-.com')
762+        self.assertRaisesRegexp(ValidationError, "u'Enter a valid URL.'", f.clean, 'http://-invalid.com')
763+        self.assertRaisesRegexp(ValidationError, "u'Enter a valid URL.'", f.clean, 'http://inv-.alid-.com')
764+        self.assertRaisesRegexp(ValidationError, "u'Enter a valid URL.'", f.clean, 'http://inv-.-alid.com')
765         self.assertEqual(u'http://valid-----hyphens.com/', f.clean('http://valid-----hyphens.com'))
766         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'))
767 
768     def test_url_regex_ticket11198(self):
769         f = URLField()
770         # hangs "forever" if catastrophic backtracking in ticket:#11198 not fixed
771-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://%s' % ("X"*200,))
772+        self.assertRaisesRegexp(ValidationError, "u'Enter a valid URL.'", f.clean, 'http://%s' % ("X"*200,))
773 
774         # a second test, to make sure the problem is really addressed, even on
775         # domains that don't fail the domain label length check in the regex
776-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://%s' % ("X"*60,))
777+        self.assertRaisesRegexp(ValidationError, "u'Enter a valid URL.'", f.clean, 'http://%s' % ("X"*60,))
778 
779     def test_urlfield_38(self):
780         f = URLField(required=False)
781@@ -511,16 +504,16 @@
782         self.assertEqual(u'', f.clean(None))
783         self.assertEqual(u'http://example.com/', f.clean('http://example.com'))
784         self.assertEqual(u'http://www.example.com/', f.clean('http://www.example.com'))
785-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'foo')
786-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://')
787-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://example')
788-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://example.')
789-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://.com')
790+        self.assertRaisesRegexp(ValidationError, "u'Enter a valid URL.'", f.clean, 'foo')
791+        self.assertRaisesRegexp(ValidationError, "u'Enter a valid URL.'", f.clean, 'http://')
792+        self.assertRaisesRegexp(ValidationError, "u'Enter a valid URL.'", f.clean, 'http://example')
793+        self.assertRaisesRegexp(ValidationError, "u'Enter a valid URL.'", f.clean, 'http://example.')
794+        self.assertRaisesRegexp(ValidationError, "u'Enter a valid URL.'", f.clean, 'http://.com')
795 
796     def test_urlfield_39(self):
797         f = URLField(verify_exists=True)
798         self.assertEqual(u'http://www.google.com/', f.clean('http://www.google.com')) # This will fail if there's no Internet connection
799-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://example')
800+        self.assertRaisesRegexp(ValidationError, "u'Enter a valid URL.'", f.clean, 'http://example')
801         self.assertRaises(ValidationError, f.clean, 'http://www.broken.djangoproject.com') # bad domain
802         try:
803             f.clean('http://www.broken.djangoproject.com') # bad domain
804@@ -546,9 +539,9 @@
805 
806     def test_urlfield_41(self):
807         f = URLField(min_length=15, max_length=20)
808-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value has at least 15 characters (it has 13).']", f.clean, 'http://f.com')
809+        self.assertRaisesRegexp(ValidationError, "u'Ensure this value has at least 15 characters \(it has 13\).'", f.clean, 'http://f.com')
810         self.assertEqual(u'http://example.com/', f.clean('http://example.com'))
811-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value has at most 20 characters (it has 38).']", f.clean, 'http://abcdefghijklmnopqrstuvwxyz.com')
812+        self.assertRaisesRegexp(ValidationError, "u'Ensure this value has at most 20 characters \(it has 38\).'", f.clean, 'http://abcdefghijklmnopqrstuvwxyz.com')
813 
814     def test_urlfield_42(self):
815         f = URLField(required=False)
816@@ -569,15 +562,15 @@
817 
818     def test_booleanfield_44(self):
819         f = BooleanField()
820-        self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
821-        self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
822+        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, '')
823+        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, None)
824         self.assertEqual(True, f.clean(True))
825-        self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, False)
826+        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, False)
827         self.assertEqual(True, f.clean(1))
828-        self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, 0)
829+        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, 0)
830         self.assertEqual(True, f.clean('Django rocks'))
831         self.assertEqual(True, f.clean('True'))
832-        self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, 'False')
833+        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, 'False')
834 
835     def test_booleanfield_45(self):
836         f = BooleanField(required=False)
837@@ -596,11 +589,11 @@
838 
839     def test_choicefield_46(self):
840         f = ChoiceField(choices=[('1', 'One'), ('2', 'Two')])
841-        self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
842-        self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
843+        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, '')
844+        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, None)
845         self.assertEqual(u'1', f.clean(1))
846         self.assertEqual(u'1', f.clean('1'))
847-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. 3 is not one of the available choices.']", f.clean, '3')
848+        self.assertRaisesRegexp(ValidationError, "u'Select a valid choice. 3 is not one of the available choices.'", f.clean, '3')
849 
850     def test_choicefield_47(self):
851         f = ChoiceField(choices=[('1', 'One'), ('2', 'Two')], required=False)
852@@ -608,12 +601,12 @@
853         self.assertEqual(u'', f.clean(None))
854         self.assertEqual(u'1', f.clean(1))
855         self.assertEqual(u'1', f.clean('1'))
856-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. 3 is not one of the available choices.']", f.clean, '3')
857+        self.assertRaisesRegexp(ValidationError, "u'Select a valid choice. 3 is not one of the available choices.'", f.clean, '3')
858 
859     def test_choicefield_48(self):
860         f = ChoiceField(choices=[('J', 'John'), ('P', 'Paul')])
861         self.assertEqual(u'J', f.clean('J'))
862-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. John is not one of the available choices.']", f.clean, 'John')
863+        self.assertRaisesRegexp(ValidationError, "u'Select a valid choice. John is not one of the available choices.'", f.clean, 'John')
864 
865     def test_choicefield_49(self):
866         f = ChoiceField(choices=[('Numbers', (('1', 'One'), ('2', 'Two'))), ('Letters', (('3','A'),('4','B'))), ('5','Other')])
867@@ -623,7 +616,7 @@
868         self.assertEqual(u'3', f.clean('3'))
869         self.assertEqual(u'5', f.clean(5))
870         self.assertEqual(u'5', f.clean('5'))
871-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. 6 is not one of the available choices.']", f.clean, '6')
872+        self.assertRaisesRegexp(ValidationError, "u'Select a valid choice. 6 is not one of the available choices.'", f.clean, '6')
873 
874     # TypedChoiceField ############################################################
875     # TypedChoiceField is just like ChoiceField, except that coerced types will
876@@ -632,7 +625,7 @@
877     def test_typedchoicefield_50(self):
878         f = TypedChoiceField(choices=[(1, "+1"), (-1, "-1")], coerce=int)
879         self.assertEqual(1, f.clean('1'))
880-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. 2 is not one of the available choices.']", f.clean, '2')
881+        self.assertRaisesRegexp(ValidationError, "u'Select a valid choice. 2 is not one of the available choices.'", f.clean, '2')
882 
883     def test_typedchoicefield_51(self):
884         # Different coercion, same validation.
885@@ -648,9 +641,9 @@
886         # Even more weirdness: if you have a valid choice but your coercion function
887         # can't coerce, you'll still get a validation error. Don't do this!
888         f = TypedChoiceField(choices=[('A', 'A'), ('B', 'B')], coerce=int)
889-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. B is not one of the available choices.']", f.clean, 'B')
890+        self.assertRaisesRegexp(ValidationError, "u'Select a valid choice. B is not one of the available choices.'", f.clean, 'B')
891         # Required fields require values
892-        self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
893+        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, '')
894 
895     def test_typedchoicefield_54(self):
896         # Non-required fields aren't required
897@@ -712,17 +705,17 @@
898 
899     def test_multiplechoicefield_60(self):
900         f = MultipleChoiceField(choices=[('1', 'One'), ('2', 'Two')])
901-        self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
902-        self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
903+        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, '')
904+        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, None)
905         self.assertEqual([u'1'], f.clean([1]))
906         self.assertEqual([u'1'], f.clean(['1']))
907         self.assertEqual([u'1', u'2'], f.clean(['1', '2']))
908         self.assertEqual([u'1', u'2'], f.clean([1, '2']))
909         self.assertEqual([u'1', u'2'], f.clean((1, '2')))
910-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a list of values.']", f.clean, 'hello')
911-        self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, [])
912-        self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, ())
913-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. 3 is not one of the available choices.']", f.clean, ['3'])
914+        self.assertRaisesRegexp(ValidationError, "u'Enter a list of values.'", f.clean, 'hello')
915+        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, [])
916+        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, ())
917+        self.assertRaisesRegexp(ValidationError, "u'Select a valid choice. 3 is not one of the available choices.'", f.clean, ['3'])
918 
919     def test_multiplechoicefield_61(self):
920         f = MultipleChoiceField(choices=[('1', 'One'), ('2', 'Two')], required=False)
921@@ -733,10 +726,10 @@
922         self.assertEqual([u'1', u'2'], f.clean(['1', '2']))
923         self.assertEqual([u'1', u'2'], f.clean([1, '2']))
924         self.assertEqual([u'1', u'2'], f.clean((1, '2')))
925-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a list of values.']", f.clean, 'hello')
926+        self.assertRaisesRegexp(ValidationError, "u'Enter a list of values.'", f.clean, 'hello')
927         self.assertEqual([], f.clean([]))
928         self.assertEqual([], f.clean(()))
929-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. 3 is not one of the available choices.']", f.clean, ['3'])
930+        self.assertRaisesRegexp(ValidationError, "u'Select a valid choice. 3 is not one of the available choices.'", f.clean, ['3'])
931 
932     def test_multiplechoicefield_62(self):
933         f = MultipleChoiceField(choices=[('Numbers', (('1', 'One'), ('2', 'Two'))), ('Letters', (('3','A'),('4','B'))), ('5','Other')])
934@@ -746,24 +739,24 @@
935         self.assertEqual([u'1', u'5'], f.clean([1, '5']))
936         self.assertEqual([u'1', u'5'], f.clean(['1', 5]))
937         self.assertEqual([u'1', u'5'], f.clean(['1', '5']))
938-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. 6 is not one of the available choices.']", f.clean, ['6'])
939-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. 6 is not one of the available choices.']", f.clean, ['1','6'])
940+        self.assertRaisesRegexp(ValidationError, "u'Select a valid choice. 6 is not one of the available choices.'", f.clean, ['6'])
941+        self.assertRaisesRegexp(ValidationError, "u'Select a valid choice. 6 is not one of the available choices.'", f.clean, ['1','6'])
942 
943     # ComboField ##################################################################
944 
945     def test_combofield_63(self):
946         f = ComboField(fields=[CharField(max_length=20), EmailField()])
947         self.assertEqual(u'test@example.com', f.clean('test@example.com'))
948-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value has at most 20 characters (it has 28).']", f.clean, 'longemailaddress@example.com')
949-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'not an e-mail')
950-        self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
951-        self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
952+        self.assertRaisesRegexp(ValidationError, "u'Ensure this value has at most 20 characters \(it has 28\).'", f.clean, 'longemailaddress@example.com')
953+        self.assertRaisesRegexp(ValidationError, "u'Enter a valid e-mail address.'", f.clean, 'not an e-mail')
954+        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, '')
955+        self.assertRaisesRegexp(ValidationError, "u'This field is required.'", f.clean, None)
956 
957     def test_combofield_64(self):
958         f = ComboField(fields=[CharField(max_length=20), EmailField()], required=False)
959         self.assertEqual(u'test@example.com', f.clean('test@example.com'))
960-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value has at most 20 characters (it has 28).']", f.clean, 'longemailaddress@example.com')
961-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'not an e-mail')
962+        self.assertRaisesRegexp(ValidationError, "u'Ensure this value has at most 20 characters \(it has 28\).'", f.clean, 'longemailaddress@example.com')
963+        self.assertRaisesRegexp(ValidationError, "u'Enter a valid e-mail address.'", f.clean, 'not an e-mail')
964         self.assertEqual(u'', f.clean(''))
965         self.assertEqual(u'', f.clean(None))
966 
967@@ -792,7 +785,7 @@
968         for exp, got in zip(expected, fix_os_paths(f.choices)):
969             self.assertEqual(exp[1], got[1])
970             self.assertTrue(got[0].endswith(exp[0]))
971-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. fields.py is not one of the available choices.']", f.clean, 'fields.py')
972+        self.assertRaisesRegexp(ValidationError, "u'Select a valid choice. fields.py is not one of the available choices.'", f.clean, 'fields.py')
973         assert fix_os_paths(f.clean(path + 'fields.py')).endswith('/django/forms/fields.py')
974 
975     def test_filepathfield_67(self):
976@@ -840,12 +833,12 @@
977         f = SplitDateTimeField()
978         assert isinstance(f.widget, SplitDateTimeWidget)
979         self.assertEqual(datetime.datetime(2006, 1, 10, 7, 30), f.clean([datetime.date(2006, 1, 10), datetime.time(7, 30)]))
980-        self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
981-        self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
982-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a list of values.']", f.clean, 'hello')
983-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid date.', u'Enter a valid time.']", f.clean, ['hello', 'there'])
984-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid time.']", f.clean, ['2006-01-10', 'there'])
985-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid date.']", f.clean, ['hello', '07:30'])
986+        self.assertRaisesRegexp(ValidationError, "[u'This field is required.']", f.clean, None)
987+        self.assertRaisesRegexp(ValidationError, "[u'This field is required.']", f.clean, '')
988+        self.assertRaisesRegexp(ValidationError, "[u'Enter a list of values.']", f.clean, 'hello')
989+        self.assertRaisesRegexp(ValidationError, "[u'Enter a valid date.', u'Enter a valid time.']", f.clean, ['hello', 'there'])
990+        self.assertRaisesRegexp(ValidationError, "[u'Enter a valid time.']", f.clean, ['2006-01-10', 'there'])
991+        self.assertRaisesRegexp(ValidationError, "[u'Enter a valid date.']", f.clean, ['hello', '07:30'])
992 
993     def test_splitdatetimefield_70(self):
994         f = SplitDateTimeField(required=False)
995@@ -855,10 +848,10 @@
996         self.assertEqual(None, f.clean(''))
997         self.assertEqual(None, f.clean(['']))
998         self.assertEqual(None, f.clean(['', '']))
999-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a list of values.']", f.clean, 'hello')
1000-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid date.', u'Enter a valid time.']", f.clean, ['hello', 'there'])
1001-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid time.']", f.clean, ['2006-01-10', 'there'])
1002-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid date.']", f.clean, ['hello', '07:30'])
1003-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid time.']", f.clean, ['2006-01-10', ''])
1004-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid time.']", f.clean, ['2006-01-10'])
1005-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid date.']", f.clean, ['', '07:30'])
1006+        self.assertRaisesRegexp(ValidationError, "u'Enter a list of values.'", f.clean, 'hello')
1007+        self.assertRaisesRegexp(ValidationError, "u'Enter a valid date.', u'Enter a valid time.'", f.clean, ['hello', 'there'])
1008+        self.assertRaisesRegexp(ValidationError, "u'Enter a valid time.'", f.clean, ['2006-01-10', 'there'])
1009+        self.assertRaisesRegexp(ValidationError, "u'Enter a valid date.'", f.clean, ['hello', '07:30'])
1010+        self.assertRaisesRegexp(ValidationError, "u'Enter a valid time.'", f.clean, ['2006-01-10', ''])
1011+        self.assertRaisesRegexp(ValidationError, "u'Enter a valid time.'", f.clean, ['2006-01-10'])
1012+        self.assertRaisesRegexp(ValidationError, "u'Enter a valid date.'", f.clean, ['', '07:30'])
1013diff --git a/tests/regressiontests/forms/localflavor/be.py b/tests/regressiontests/forms/localflavor/be.py
1014--- a/tests/regressiontests/forms/localflavor/be.py
1015+++ b/tests/regressiontests/forms/localflavor/be.py
1016@@ -8,35 +8,28 @@
1017     """
1018     Test case to validate BE localflavor
1019     """
1020-    def assertRaisesErrorWithMessage(self, error, message, callable, *args, **kwargs):
1021-        self.assertRaises(error, callable, *args, **kwargs)
1022-        try:
1023-            callable(*args, **kwargs)
1024-        except error, e:
1025-            self.assertEqual(message, str(e))
1026-
1027     def test_postal_code_field(self):
1028         f = BEPostalCodeField()
1029         self.assertEqual(u'1451', f.clean('1451'))
1030         self.assertEqual(u'2540', f.clean('2540'))
1031-        err_message = "[u'Enter a valid postal code in the range and format 1XXX - 9XXX.']"
1032-        self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '0287')
1033-        self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '14309')
1034-        self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '873')
1035-        self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '35 74')
1036-        self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '859A')
1037+        err_message = "\[u'Enter a valid postal code in the range and format 1XXX - 9XXX.'\]"
1038+        self.assertRaisesRegexp(ValidationError, err_message, f.clean, '0287')
1039+        self.assertRaisesRegexp(ValidationError, err_message, f.clean, '14309')
1040+        self.assertRaisesRegexp(ValidationError, err_message, f.clean, '873')
1041+        self.assertRaisesRegexp(ValidationError, err_message, f.clean, '35 74')
1042+        self.assertRaisesRegexp(ValidationError, err_message, f.clean, '859A')
1043         err_message = "[u'This field is required.']"
1044-        self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '')
1045+        self.assertRaisesRegexp(ValidationError, err_message, f.clean, '')
1046         f = BEPostalCodeField(required=False)
1047         self.assertEqual(u'1451', f.clean('1451'))
1048         self.assertEqual(u'2540', f.clean('2540'))
1049         self.assertEqual(u'', f.clean(''))
1050-        err_message = "[u'Enter a valid postal code in the range and format 1XXX - 9XXX.']"
1051-        self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '0287')
1052-        self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '14309')
1053-        self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '873')
1054-        self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '35 74')
1055-        self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '859A')
1056+        err_message = "\[u'Enter a valid postal code in the range and format 1XXX - 9XXX.'\]"
1057+        self.assertRaisesRegexp(ValidationError, err_message, f.clean, '0287')
1058+        self.assertRaisesRegexp(ValidationError, err_message, f.clean, '14309')
1059+        self.assertRaisesRegexp(ValidationError, err_message, f.clean, '873')
1060+        self.assertRaisesRegexp(ValidationError, err_message, f.clean, '35 74')
1061+        self.assertRaisesRegexp(ValidationError, err_message, f.clean, '859A')
1062 
1063     def test_phone_number_field(self):
1064         f = BEPhoneNumberField()
1065@@ -51,17 +44,17 @@
1066         self.assertEqual(u'0412.34.56.78', f.clean('0412.34.56.78'))
1067         self.assertEqual(u'012345678', f.clean('012345678'))
1068         self.assertEqual(u'0412345678', f.clean('0412345678'))
1069-        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.']"
1070-        self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '01234567')
1071-        self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '12/345.67.89')
1072-        self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '012/345.678.90')
1073-        self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '012/34.56.789')
1074-        self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '0123/45.67.89')
1075-        self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '012/345 678 90')
1076-        self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '012/34 56 789')
1077-        self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '012.34 56 789')
1078-        err_message = "[u'This field is required.']"
1079-        self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '')
1080+        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.'\]"
1081+        self.assertRaisesRegexp(ValidationError, err_message, f.clean, '01234567')
1082+        self.assertRaisesRegexp(ValidationError, err_message, f.clean, '12/345.67.89')
1083+        self.assertRaisesRegexp(ValidationError, err_message, f.clean, '012/345.678.90')
1084+        self.assertRaisesRegexp(ValidationError, err_message, f.clean, '012/34.56.789')
1085+        self.assertRaisesRegexp(ValidationError, err_message, f.clean, '0123/45.67.89')
1086+        self.assertRaisesRegexp(ValidationError, err_message, f.clean, '012/345 678 90')
1087+        self.assertRaisesRegexp(ValidationError, err_message, f.clean, '012/34 56 789')
1088+        self.assertRaisesRegexp(ValidationError, err_message, f.clean, '012.34 56 789')
1089+        err_message = "\[u'This field is required.'\]"
1090+        self.assertRaisesRegexp(ValidationError, err_message, f.clean, '')
1091         f = BEPhoneNumberField(required=False)
1092         self.assertEqual(u'01 234 56 78', f.clean('01 234 56 78'))
1093         self.assertEqual(u'01/234.56.78', f.clean('01/234.56.78'))
1094@@ -75,15 +68,15 @@
1095         self.assertEqual(u'012345678', f.clean('012345678'))
1096         self.assertEqual(u'0412345678', f.clean('0412345678'))
1097         self.assertEqual(u'', f.clean(''))
1098-        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.']"
1099-        self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '01234567')
1100-        self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '12/345.67.89')
1101-        self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '012/345.678.90')
1102-        self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '012/34.56.789')
1103-        self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '0123/45.67.89')
1104-        self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '012/345 678 90')
1105-        self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '012/34 56 789')
1106-        self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '012.34 56 789')
1107+        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.'\]"
1108+        self.assertRaisesRegexp(ValidationError, err_message, f.clean, '01234567')
1109+        self.assertRaisesRegexp(ValidationError, err_message, f.clean, '12/345.67.89')
1110+        self.assertRaisesRegexp(ValidationError, err_message, f.clean, '012/345.678.90')
1111+        self.assertRaisesRegexp(ValidationError, err_message, f.clean, '012/34.56.789')
1112+        self.assertRaisesRegexp(ValidationError, err_message, f.clean, '0123/45.67.89')
1113+        self.assertRaisesRegexp(ValidationError, err_message, f.clean, '012/345 678 90')
1114+        self.assertRaisesRegexp(ValidationError, err_message, f.clean, '012/34 56 789')
1115+        self.assertRaisesRegexp(ValidationError, err_message, f.clean, '012.34 56 789')
1116 
1117     def test_phone_number_field(self):
1118         w = BERegionSelect()
1119diff --git a/tests/regressiontests/queries/tests.py b/tests/regressiontests/queries/tests.py
1120--- a/tests/regressiontests/queries/tests.py
1121+++ b/tests/regressiontests/queries/tests.py
1122@@ -21,13 +21,6 @@
1123     def assertValueQuerysetEqual(self, qs, values):
1124         return self.assertQuerysetEqual(qs, values, transform=lambda x: x)
1125 
1126-    def assertRaisesMessage(self, exc, msg, func, *args, **kwargs):
1127-        try:
1128-            func(*args, **kwargs)
1129-        except Exception, e:
1130-            self.assertEqual(msg, str(e))
1131-            self.assertTrue(isinstance(e, exc), "Expected %s, got %s" % (exc, type(e)))
1132-
1133 
1134 class Queries1Tests(BaseQuerysetTest):
1135     def setUp(self):
1136@@ -356,12 +349,12 @@
1137     def test_heterogeneous_qs_combination(self):
1138         # Combining querysets built on different models should behave in a well-defined
1139         # fashion. We raise an error.
1140-        self.assertRaisesMessage(
1141+        self.assertRaisesRegexp(
1142             AssertionError,
1143             'Cannot combine queries on two different base models.',
1144             lambda: Author.objects.all() & Tag.objects.all()
1145         )
1146-        self.assertRaisesMessage(
1147+        self.assertRaisesRegexp(
1148             AssertionError,
1149             'Cannot combine queries on two different base models.',
1150             lambda: Author.objects.all() | Tag.objects.all()
1151@@ -670,7 +663,7 @@
1152             []
1153         )
1154         q.query.low_mark = 1
1155-        self.assertRaisesMessage(
1156+        self.assertRaisesRegexp(
1157             AssertionError,
1158             'Cannot change a query once a slice has been taken',
1159             q.extra, select={'is_recent': "pub_date > '2006-01-01'"}
1160@@ -701,12 +694,12 @@
1161         )
1162 
1163         # Multi-valued values() and values_list() querysets should raise errors.
1164-        self.assertRaisesMessage(
1165+        self.assertRaisesRegexp(
1166             TypeError,
1167             'Cannot use a multi-field ValuesQuerySet as a filter value.',
1168             lambda: Tag.objects.filter(name__in=Tag.objects.filter(parent=self.t1).values('name', 'id'))
1169         )
1170-        self.assertRaisesMessage(
1171+        self.assertRaisesRegexp(
1172             TypeError,
1173             'Cannot use a multi-field ValuesListQuerySet as a filter value.',
1174             lambda: Tag.objects.filter(name__in=Tag.objects.filter(parent=self.t1).values_list('name', 'id'))
1175@@ -948,7 +941,7 @@
1176     def test_ticket8683(self):
1177         # Raise proper error when a DateQuerySet gets passed a wrong type of
1178         # field
1179-        self.assertRaisesMessage(
1180+        self.assertRaisesRegexp(
1181             AssertionError,
1182             "'name' isn't a DateField.",
1183             Item.objects.dates, 'name', 'month'
1184@@ -1461,7 +1454,7 @@
1185         self.assertQuerysetEqual(Article.objects.all()[0:0], [])
1186         self.assertQuerysetEqual(Article.objects.all()[0:0][:10], [])
1187         self.assertEqual(Article.objects.all()[:0].count(), 0)
1188-        self.assertRaisesMessage(
1189+        self.assertRaisesRegexp(
1190             AssertionError,
1191             'Cannot change a query once a slice has been taken.',
1192             Article.objects.all()[:0].latest, 'created'
1193@@ -1508,12 +1501,12 @@
1194     def test_infinite_loop(self):
1195         # If you're not careful, it's possible to introduce infinite loops via
1196         # default ordering on foreign keys in a cycle. We detect that.
1197-        self.assertRaisesMessage(
1198+        self.assertRaisesRegexp(
1199             FieldError,
1200             'Infinite loop caused by ordering.',
1201             LoopX.objects.all
1202         )
1203-        self.assertRaisesMessage(
1204+        self.assertRaisesRegexp(
1205             FieldError,
1206             'Infinite loop caused by ordering.',
1207             LoopZ.objects.all
1208diff --git a/tests/regressiontests/urlpatterns_reverse/tests.py b/tests/regressiontests/urlpatterns_reverse/tests.py
1209--- a/tests/regressiontests/urlpatterns_reverse/tests.py
1210+++ b/tests/regressiontests/urlpatterns_reverse/tests.py
1211@@ -133,21 +133,13 @@
1212 class NoURLPatternsTests(TestCase):
1213     urls = 'regressiontests.urlpatterns_reverse.no_urls'
1214 
1215-    def assertRaisesErrorWithMessage(self, error, message, callable,
1216-        *args, **kwargs):
1217-        self.assertRaises(error, callable, *args, **kwargs)
1218-        try:
1219-            callable(*args, **kwargs)
1220-        except error, e:
1221-            self.assertEqual(message, str(e))
1222-
1223     def test_no_urls_exception(self):
1224         """
1225         RegexURLResolver should raise an exception when no urlpatterns exist.
1226         """
1227         resolver = RegexURLResolver(r'^$', self.urls)
1228 
1229-        self.assertRaisesErrorWithMessage(ImproperlyConfigured,
1230+        self.assertRaisesRegexp(ImproperlyConfigured,
1231             "The included urlconf regressiontests.urlpatterns_reverse.no_urls "\
1232             "doesn't have any patterns in it", getattr, resolver, 'url_patterns')
1233 
1234diff --git a/tests/regressiontests/utils/datastructures.py b/tests/regressiontests/utils/datastructures.py
1235--- a/tests/regressiontests/utils/datastructures.py
1236+++ b/tests/regressiontests/utils/datastructures.py
1237@@ -2,22 +2,12 @@
1238 Tests for stuff in django.utils.datastructures.
1239 """
1240 import pickle
1241-import unittest
1242 
1243+from django.test import TestCase
1244 from django.utils.datastructures import *
1245 
1246 
1247-class DatastructuresTestCase(unittest.TestCase):
1248-    def assertRaisesErrorWithMessage(self, error, message, callable,
1249-        *args, **kwargs):
1250-        self.assertRaises(error, callable, *args, **kwargs)
1251-        try:
1252-            callable(*args, **kwargs)
1253-        except error, e:
1254-            self.assertEqual(message, str(e))
1255-
1256-
1257-class SortedDictTests(DatastructuresTestCase):
1258+class SortedDictTests(TestCase):
1259     def setUp(self):
1260         self.d1 = SortedDict()
1261         self.d1[7] = 'seven'
1262@@ -123,7 +113,7 @@
1263         self.assertEquals(self.d1, {})
1264         self.assertEquals(self.d1.keyOrder, [])
1265 
1266-class MergeDictTests(DatastructuresTestCase):
1267+class MergeDictTests(TestCase):
1268 
1269     def test_simple_mergedict(self):
1270         d1 = {'chris':'cool', 'camri':'cute', 'cotton':'adorable',
1271@@ -177,7 +167,7 @@
1272                            ('key2', ['value2', 'value3']),
1273                            ('key4', ['value5', 'value6'])])
1274 
1275-class MultiValueDictTests(DatastructuresTestCase):
1276+class MultiValueDictTests(TestCase):
1277 
1278     def test_multivaluedict(self):
1279         d = MultiValueDict({'name': ['Adrian', 'Simon'],
1280@@ -196,9 +186,9 @@
1281         # MultiValueDictKeyError: "Key 'lastname' not found in
1282         # <MultiValueDict: {'position': ['Developer'],
1283         #                   'name': ['Adrian', 'Simon']}>"
1284-        self.assertRaisesErrorWithMessage(MultiValueDictKeyError,
1285-            '"Key \'lastname\' not found in <MultiValueDict: {\'position\':'\
1286-            ' [\'Developer\'], \'name\': [\'Adrian\', \'Simon\']}>"',
1287+        self.assertRaisesRegexp(MultiValueDictKeyError,
1288+            '"Key \'lastname\' not found in <MultiValueDict: \{\'position\':'\
1289+            ' \[\'Developer\'\], \'name\': \[\'Adrian\', \'Simon\'\]\}>"',
1290             d.__getitem__, 'lastname')
1291 
1292         self.assertEquals(d.get('lastname'), None)
1293@@ -212,7 +202,7 @@
1294                           ['Developer', 'Simon', 'Willison'])
1295 
1296 
1297-class DotExpandedDictTests(DatastructuresTestCase):
1298+class DotExpandedDictTests(TestCase):
1299 
1300     def test_dotexpandeddict(self):
1301 
1302@@ -226,13 +216,13 @@
1303         self.assertEquals(d['person']['2']['firstname'], ['Adrian'])
1304 
1305 
1306-class ImmutableListTests(DatastructuresTestCase):
1307+class ImmutableListTests(TestCase):
1308 
1309     def test_sort(self):
1310         d = ImmutableList(range(10))
1311 
1312         # AttributeError: ImmutableList object is immutable.
1313-        self.assertRaisesErrorWithMessage(AttributeError,
1314+        self.assertRaisesRegexp(AttributeError,
1315             'ImmutableList object is immutable.', d.sort)
1316 
1317         self.assertEquals(repr(d), '(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)')
1318@@ -243,11 +233,11 @@
1319         self.assertEquals(d[1], 1)
1320 
1321         # AttributeError: Object is immutable!
1322-        self.assertRaisesErrorWithMessage(AttributeError,
1323+        self.assertRaisesRegexp(AttributeError,
1324             'Object is immutable!', d.__setitem__, 1, 'test')
1325 
1326 
1327-class DictWrapperTests(DatastructuresTestCase):
1328+class DictWrapperTests(TestCase):
1329 
1330     def test_dictwrapper(self):
1331         f = lambda x: "*%s" % x