Code

Ticket #14503: 14503-assertraisesregex-r14981.diff

File 14503-assertraisesregex-r14981.diff, 79.7 KB (added by ramiro, 3 years ago)

Updated patch for trunk as of now

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,8 +33,8 @@
19         # Regression test for #8027: custom ModelForms with fields/fieldsets
20         """
21         validate(ValidFields, Song)
22-        self.assertRaisesMessage(ImproperlyConfigured,
23-            "'InvalidFields.fields' refers to field 'spam' that is missing from the form.",
24+        self.assertRaisesRegexp(ImproperlyConfigured,
25+            "'InvalidFields\.fields' refers to field 'spam' that is missing from the form\.",
26             validate,
27             InvalidFields, Song)
28 
29@@ -51,16 +44,16 @@
30         """
31         class ExcludedFields1(admin.ModelAdmin):
32             exclude = ('foo')
33-        self.assertRaisesMessage(ImproperlyConfigured,
34-            "'ExcludedFields1.exclude' must be a list or tuple.",
35+        self.assertRaisesRegexp(ImproperlyConfigured,
36+            "'ExcludedFields1\.exclude' must be a list or tuple\.",
37             validate,
38             ExcludedFields1, Book)
39 
40     def test_exclude_duplicate_values(self):
41         class ExcludedFields2(admin.ModelAdmin):
42             exclude = ('name', 'name')
43-        self.assertRaisesMessage(ImproperlyConfigured,
44-            "There are duplicate field(s) in ExcludedFields2.exclude",
45+        self.assertRaisesRegexp(ImproperlyConfigured,
46+            "There are duplicate field\(s\) in ExcludedFields2\.exclude",
47             validate,
48             ExcludedFields2, Book)
49 
50@@ -73,8 +66,8 @@
51             model = Album
52             inlines = [ExcludedFieldsInline]
53 
54-        self.assertRaisesMessage(ImproperlyConfigured,
55-            "'ExcludedFieldsInline.exclude' must be a list or tuple.",
56+        self.assertRaisesRegexp(ImproperlyConfigured,
57+            "'ExcludedFieldsInline\.exclude' must be a list or tuple\.",
58             validate,
59             ExcludedFieldsAlbumAdmin, Album)
60 
61@@ -91,8 +84,8 @@
62             model = Album
63             inlines = [SongInline]
64 
65-        self.assertRaisesMessage(ImproperlyConfigured,
66-            "SongInline cannot exclude the field 'album' - this is the foreign key to the parent model Album.",
67+        self.assertRaisesRegexp(ImproperlyConfigured,
68+            "SongInline cannot exclude the field 'album' - this is the foreign key to the parent model Album\.",
69             validate,
70             AlbumAdmin, Album)
71 
72@@ -112,8 +105,8 @@
73         class TwoAlbumFKAndAnEInline(admin.TabularInline):
74             model = TwoAlbumFKAndAnE
75 
76-        self.assertRaisesMessage(Exception,
77-            "<class 'regressiontests.admin_validation.models.TwoAlbumFKAndAnE'> has more than 1 ForeignKey to <class 'regressiontests.admin_validation.models.Album'>",
78+        self.assertRaisesRegexp(Exception,
79+            "<class 'regressiontests.admin_validation\.models\.TwoAlbumFKAndAnE'> has more than 1 ForeignKey to <class 'regressiontests\.admin_validation\.models\.Album'>",
80             validate_inline,
81             TwoAlbumFKAndAnEInline, None, Album)
82 
83@@ -157,8 +150,8 @@
84         class SongAdmin(admin.ModelAdmin):
85             readonly_fields = ("title", "nonexistant")
86 
87-        self.assertRaisesMessage(ImproperlyConfigured,
88-            "SongAdmin.readonly_fields[1], 'nonexistant' is not a callable or an attribute of 'SongAdmin' or found in the model 'Song'.",
89+        self.assertRaisesRegexp(ImproperlyConfigured,
90+            "SongAdmin.readonly_fields\[1\], 'nonexistant' is not a callable or an attribute of 'SongAdmin' or found in the model 'Song'\.",
91             validate,
92             SongAdmin, Song)
93 
94@@ -186,8 +179,8 @@
95         class BookAdmin(admin.ModelAdmin):
96             fields = ['authors']
97 
98-        self.assertRaisesMessage(ImproperlyConfigured,
99-            "'BookAdmin.fields' can't include the ManyToManyField field 'authors' because 'authors' manually specifies a 'through' model.",
100+        self.assertRaisesRegexp(ImproperlyConfigured,
101+            "'BookAdmin\.fields' can't include the ManyToManyField field 'authors' because 'authors' manually specifies a 'through' model\.",
102             validate,
103             BookAdmin, Book)
104 
105@@ -197,8 +190,8 @@
106                 ('Header 1', {'fields': ('name',)}),
107                 ('Header 2', {'fields': ('authors',)}),
108             )
109-        self.assertRaisesMessage(ImproperlyConfigured,
110-            "'FieldsetBookAdmin.fieldsets[1][1]['fields']' can't include the ManyToManyField field 'authors' because 'authors' manually specifies a 'through' model.",
111+        self.assertRaisesRegexp(ImproperlyConfigured,
112+            "'FieldsetBookAdmin\.fieldsets\[1\]\[1\]\['fields'\]' can't include the ManyToManyField field 'authors' because 'authors' manually specifies a 'through' model\.",
113             validate,
114             FieldsetBookAdmin, Book)
115 
116diff --git a/tests/regressiontests/custom_columns_regress/tests.py b/tests/regressiontests/custom_columns_regress/tests.py
117--- a/tests/regressiontests/custom_columns_regress/tests.py
118+++ b/tests/regressiontests/custom_columns_regress/tests.py
119@@ -9,13 +9,6 @@
120 
121 class CustomColumnRegression(TestCase):
122 
123-    def assertRaisesMessage(self, exc, msg, func, *args, **kwargs):
124-        try:
125-            func(*args, **kwargs)
126-        except Exception, e:
127-            self.assertEqual(msg, str(e))
128-            self.assertTrue(isinstance(e, exc), "Expected %s, got %s" % (exc, type(e)))
129-
130     def setUp(self):
131         self.a1 = Author.objects.create(first_name='John', last_name='Smith')
132         self.a2 = Author.objects.create(first_name='Peter', last_name='Jones')
133@@ -42,9 +35,9 @@
134         self.assertEqual(self.a1, Author.objects.get(first_name__exact='John'))
135 
136     def test_filter_on_nonexistant_field(self):
137-        self.assertRaisesMessage(
138+        self.assertRaisesRegexp(
139             FieldError,
140-            "Cannot resolve keyword 'firstname' into field. Choices are: Author_ID, article, first_name, last_name, primary_set",
141+            "Cannot resolve keyword 'firstname' into field\. Choices are: Author_ID, article, first_name, last_name, primary_set",
142             Author.objects.filter,
143             firstname__exact='John'
144         )
145@@ -53,14 +46,14 @@
146         a = Author.objects.get(last_name__exact='Smith')
147         self.assertEqual('John', a.first_name)
148         self.assertEqual('Smith', a.last_name)
149-        self.assertRaisesMessage(
150+        self.assertRaisesRegexp(
151             AttributeError,
152             "'Author' object has no attribute 'firstname'",
153             getattr,
154             a, 'firstname'
155         )
156 
157-        self.assertRaisesMessage(
158+        self.assertRaisesRegexp(
159             AttributeError,
160             "'Author' object has no attribute 'last'",
161             getattr,
162diff --git a/tests/regressiontests/file_storage/tests.py b/tests/regressiontests/file_storage/tests.py
163--- a/tests/regressiontests/file_storage/tests.py
164+++ b/tests/regressiontests/file_storage/tests.py
165@@ -36,14 +36,6 @@
166 
167 
168 class GetStorageClassTests(unittest.TestCase):
169-    def assertRaisesErrorWithMessage(self, error, message, callable,
170-        *args, **kwargs):
171-        self.assertRaises(error, callable, *args, **kwargs)
172-        try:
173-            callable(*args, **kwargs)
174-        except error, e:
175-            self.assertEqual(message, str(e))
176-
177     def test_get_filesystem_storage(self):
178         """
179         get_storage_class returns the class for a storage backend name/path.
180@@ -56,9 +48,9 @@
181         """
182         get_storage_class raises an error if the requested import don't exist.
183         """
184-        self.assertRaisesErrorWithMessage(
185+        self.assertRaisesRegexp(
186             ImproperlyConfigured,
187-            "NonExistingStorage isn't a storage module.",
188+            "NonExistingStorage isn't a storage module\.",
189             get_storage_class,
190             'NonExistingStorage')
191 
192@@ -66,10 +58,10 @@
193         """
194         get_storage_class raises an error if the requested class don't exist.
195         """
196-        self.assertRaisesErrorWithMessage(
197+        self.assertRaisesRegexp(
198             ImproperlyConfigured,
199-            'Storage module "django.core.files.storage" does not define a '\
200-                '"NonExistingStorage" class.',
201+            'Storage module "django\.core\.files\.storage" does not define a '\
202+                '"NonExistingStorage" class\.',
203             get_storage_class,
204             'django.core.files.storage.NonExistingStorage')
205 
206diff --git a/tests/regressiontests/fixtures_regress/tests.py b/tests/regressiontests/fixtures_regress/tests.py
207--- a/tests/regressiontests/fixtures_regress/tests.py
208+++ b/tests/regressiontests/fixtures_regress/tests.py
209@@ -364,13 +364,6 @@
210 
211 
212 class NaturalKeyFixtureTests(TestCase):
213-    def assertRaisesMessage(self, exc, msg, func, *args, **kwargs):
214-        try:
215-            func(*args, **kwargs)
216-        except Exception, e:
217-            self.assertEqual(msg, str(e))
218-            self.assertTrue(isinstance(e, exc), "Expected %s, got %s" % (exc, type(e)))
219-
220     def test_nk_deserialize(self):
221         """
222         Test for ticket #13030 - Python based parser version
223@@ -528,33 +521,33 @@
224         )
225 
226     def test_dependency_sorting_tight_circular(self):
227-        self.assertRaisesMessage(
228+        self.assertRaisesRegexp(
229             CommandError,
230-            """Can't resolve dependencies for fixtures_regress.Circle1, fixtures_regress.Circle2 in serialized app list.""",
231+            """Can't resolve dependencies for fixtures_regress\.Circle1, fixtures_regress\.Circle2 in serialized app list\.""",
232             sort_dependencies,
233             [('fixtures_regress', [Person, Circle2, Circle1, Store, Book])],
234         )
235 
236     def test_dependency_sorting_tight_circular_2(self):
237-        self.assertRaisesMessage(
238+        self.assertRaisesRegexp(
239             CommandError,
240-            """Can't resolve dependencies for fixtures_regress.Circle1, fixtures_regress.Circle2 in serialized app list.""",
241+            """Can't resolve dependencies for fixtures_regress\.Circle1, fixtures_regress\.Circle2 in serialized app list\.""",
242             sort_dependencies,
243             [('fixtures_regress', [Circle1, Book, Circle2])],
244         )
245 
246     def test_dependency_self_referential(self):
247-        self.assertRaisesMessage(
248+        self.assertRaisesRegexp(
249             CommandError,
250-            """Can't resolve dependencies for fixtures_regress.Circle3 in serialized app list.""",
251+            """Can't resolve dependencies for fixtures_regress\.Circle3 in serialized app list\.""",
252             sort_dependencies,
253             [('fixtures_regress', [Book, Circle3])],
254         )
255 
256     def test_dependency_sorting_long(self):
257-        self.assertRaisesMessage(
258+        self.assertRaisesRegexp(
259             CommandError,
260-            """Can't resolve dependencies for fixtures_regress.Circle1, fixtures_regress.Circle2, fixtures_regress.Circle3 in serialized app list.""",
261+            """Can't resolve dependencies for fixtures_regress\.Circle1, fixtures_regress\.Circle2, fixtures_regress\.Circle3 in serialized app list\.""",
262             sort_dependencies,
263             [('fixtures_regress', [Person, Circle2, Circle1, Circle3, Store, Book])],
264         )
265diff --git a/tests/regressiontests/forms/tests/fields.py b/tests/regressiontests/forms/tests/fields.py
266--- a/tests/regressiontests/forms/tests/fields.py
267+++ b/tests/regressiontests/forms/tests/fields.py
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.assertTrue(Field(required=True).widget.is_required)
281         self.assertFalse(Field(required=False).widget.is_required)
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_2(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_4(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_5(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_1(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_2(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_3(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_4(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_5(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_1(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_2(self):
413         f = FloatField(required=False)
414@@ -185,8 +178,8 @@
415 
416     def test_floatfield_3(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_1(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_2(self):
474         f = DecimalField(max_digits=4, decimal_places=2, required=False)
475@@ -231,8 +224,8 @@
476 
477     def test_decimalfield_3(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_4(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_5(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_6(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_2(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_2(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_2(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_3(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_2(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_3(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, "\[u'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_4(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_5(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_1(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_3(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_1(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_2(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_1(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,17 +475,17 @@
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         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'))
768@@ -500,11 +493,11 @@
769     def test_url_regex_ticket11198(self):
770         f = URLField()
771         # hangs "forever" if catastrophic backtracking in ticket:#11198 not fixed
772-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://%s' % ("X"*200,))
773+        self.assertRaisesRegexp(ValidationError, "\[u'Enter a valid URL\.'\]", f.clean, 'http://%s' % ("X"*200,))
774 
775         # a second test, to make sure the problem is really addressed, even on
776         # domains that don't fail the domain label length check in the regex
777-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://%s' % ("X"*60,))
778+        self.assertRaisesRegexp(ValidationError, "\[u'Enter a valid URL\.'\]", f.clean, 'http://%s' % ("X"*60,))
779 
780     def test_urlfield_2(self):
781         f = URLField(required=False)
782@@ -512,16 +505,16 @@
783         self.assertEqual(u'', f.clean(None))
784         self.assertEqual(u'http://example.com/', f.clean('http://example.com'))
785         self.assertEqual(u'http://www.example.com/', f.clean('http://www.example.com'))
786-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'foo')
787-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://')
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://example.')
790-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://.com')
791+        self.assertRaisesRegexp(ValidationError, "\[u'Enter a valid URL\.'\]", f.clean, 'foo')
792+        self.assertRaisesRegexp(ValidationError, "\[u'Enter a valid URL\.'\]", f.clean, 'http://')
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://example.')
795+        self.assertRaisesRegexp(ValidationError, "\[u'Enter a valid URL\.'\]", f.clean, 'http://.com')
796 
797     def test_urlfield_3(self):
798         f = URLField(verify_exists=True)
799         self.assertEqual(u'http://www.google.com/', f.clean('http://www.google.com')) # This will fail if there's no Internet connection
800-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://example')
801+        self.assertRaisesRegexp(ValidationError, "\[u'Enter a valid URL\.'\]", f.clean, 'http://example')
802         self.assertRaises(ValidationError, f.clean, 'http://www.broken.djangoproject.com') # bad domain
803         try:
804             f.clean('http://www.broken.djangoproject.com') # bad domain
805@@ -547,9 +540,9 @@
806 
807     def test_urlfield_5(self):
808         f = URLField(min_length=15, max_length=20)
809-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value has at least 15 characters (it has 13).']", f.clean, 'http://f.com')
810+        self.assertRaisesRegexp(ValidationError, "\[u'Ensure this value has at least 15 characters \(it has 13\)\.'\]", f.clean, 'http://f.com')
811         self.assertEqual(u'http://example.com/', f.clean('http://example.com'))
812-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value has at most 20 characters (it has 38).']", f.clean, 'http://abcdefghijklmnopqrstuvwxyz.com')
813+        self.assertRaisesRegexp(ValidationError, "\[u'Ensure this value has at most 20 characters \(it has 38\)\.'\]", f.clean, 'http://abcdefghijklmnopqrstuvwxyz.com')
814 
815     def test_urlfield_6(self):
816         f = URLField(required=False)
817@@ -570,15 +563,15 @@
818 
819     def test_booleanfield_1(self):
820         f = BooleanField()
821-        self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
822-        self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
823+        self.assertRaisesRegexp(ValidationError, "\[u'This field is required\.'\]", f.clean, '')
824+        self.assertRaisesRegexp(ValidationError, "\[u'This field is required\.'\]", f.clean, None)
825         self.assertEqual(True, f.clean(True))
826-        self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, False)
827+        self.assertRaisesRegexp(ValidationError, "\[u'This field is required\.'\]", f.clean, False)
828         self.assertEqual(True, f.clean(1))
829-        self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, 0)
830+        self.assertRaisesRegexp(ValidationError, "\[u'This field is required\.'\]", f.clean, 0)
831         self.assertEqual(True, f.clean('Django rocks'))
832         self.assertEqual(True, f.clean('True'))
833-        self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, 'False')
834+        self.assertRaisesRegexp(ValidationError, "\[u'This field is required\.'\]", f.clean, 'False')
835 
836     def test_booleanfield_2(self):
837         f = BooleanField(required=False)
838@@ -597,11 +590,11 @@
839 
840     def test_choicefield_1(self):
841         f = ChoiceField(choices=[('1', 'One'), ('2', 'Two')])
842-        self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
843-        self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
844+        self.assertRaisesRegexp(ValidationError, "\[u'This field is required\.'\]", f.clean, '')
845+        self.assertRaisesRegexp(ValidationError, "\[u'This field is required\.'\]", f.clean, None)
846         self.assertEqual(u'1', f.clean(1))
847         self.assertEqual(u'1', f.clean('1'))
848-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. 3 is not one of the available choices.']", f.clean, '3')
849+        self.assertRaisesRegexp(ValidationError, "\[u'Select a valid choice\. 3 is not one of the available choices\.'\]", f.clean, '3')
850 
851     def test_choicefield_2(self):
852         f = ChoiceField(choices=[('1', 'One'), ('2', 'Two')], required=False)
853@@ -609,12 +602,12 @@
854         self.assertEqual(u'', f.clean(None))
855         self.assertEqual(u'1', f.clean(1))
856         self.assertEqual(u'1', f.clean('1'))
857-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. 3 is not one of the available choices.']", f.clean, '3')
858+        self.assertRaisesRegexp(ValidationError, "\[u'Select a valid choice\. 3 is not one of the available choices\.'\]", f.clean, '3')
859 
860     def test_choicefield_3(self):
861         f = ChoiceField(choices=[('J', 'John'), ('P', 'Paul')])
862         self.assertEqual(u'J', f.clean('J'))
863-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. John is not one of the available choices.']", f.clean, 'John')
864+        self.assertRaisesRegexp(ValidationError, "\[u'Select a valid choice\. John is not one of the available choices\.'\]", f.clean, 'John')
865 
866     def test_choicefield_4(self):
867         f = ChoiceField(choices=[('Numbers', (('1', 'One'), ('2', 'Two'))), ('Letters', (('3','A'),('4','B'))), ('5','Other')])
868@@ -624,7 +617,7 @@
869         self.assertEqual(u'3', f.clean('3'))
870         self.assertEqual(u'5', f.clean(5))
871         self.assertEqual(u'5', f.clean('5'))
872-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. 6 is not one of the available choices.']", f.clean, '6')
873+        self.assertRaisesRegexp(ValidationError, "\[u'Select a valid choice\. 6 is not one of the available choices\.'\]", f.clean, '6')
874 
875     # TypedChoiceField ############################################################
876     # TypedChoiceField is just like ChoiceField, except that coerced types will
877@@ -633,7 +626,7 @@
878     def test_typedchoicefield_1(self):
879         f = TypedChoiceField(choices=[(1, "+1"), (-1, "-1")], coerce=int)
880         self.assertEqual(1, f.clean('1'))
881-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. 2 is not one of the available choices.']", f.clean, '2')
882+        self.assertRaisesRegexp(ValidationError, "\[u'Select a valid choice\. 2 is not one of the available choices\.'\]", f.clean, '2')
883 
884     def test_typedchoicefield_2(self):
885         # Different coercion, same validation.
886@@ -649,9 +642,9 @@
887         # Even more weirdness: if you have a valid choice but your coercion function
888         # can't coerce, you'll still get a validation error. Don't do this!
889         f = TypedChoiceField(choices=[('A', 'A'), ('B', 'B')], coerce=int)
890-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. B is not one of the available choices.']", f.clean, 'B')
891+        self.assertRaisesRegexp(ValidationError, "\[u'Select a valid choice\. B is not one of the available choices\.'\]", f.clean, 'B')
892         # Required fields require values
893-        self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
894+        self.assertRaisesRegexp(ValidationError, "\[u'This field is required\.'\]", f.clean, '')
895 
896     def test_typedchoicefield_5(self):
897         # Non-required fields aren't required
898@@ -713,17 +706,17 @@
899 
900     def test_multiplechoicefield_1(self):
901         f = MultipleChoiceField(choices=[('1', 'One'), ('2', 'Two')])
902-        self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
903-        self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
904+        self.assertRaisesRegexp(ValidationError, "\[u'This field is required\.'\]", f.clean, '')
905+        self.assertRaisesRegexp(ValidationError, "\[u'This field is required\.'\]", f.clean, None)
906         self.assertEqual([u'1'], f.clean([1]))
907         self.assertEqual([u'1'], f.clean(['1']))
908         self.assertEqual([u'1', u'2'], f.clean(['1', '2']))
909         self.assertEqual([u'1', u'2'], f.clean([1, '2']))
910         self.assertEqual([u'1', u'2'], f.clean((1, '2')))
911-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a list of values.']", f.clean, 'hello')
912-        self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, [])
913-        self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, ())
914-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. 3 is not one of the available choices.']", f.clean, ['3'])
915+        self.assertRaisesRegexp(ValidationError, "\[u'Enter a list of values\.'\]", f.clean, 'hello')
916+        self.assertRaisesRegexp(ValidationError, "\[u'This field is required\.'\]", f.clean, [])
917+        self.assertRaisesRegexp(ValidationError, "\[u'This field is required\.'\]", f.clean, ())
918+        self.assertRaisesRegexp(ValidationError, "\[u'Select a valid choice\. 3 is not one of the available choices\.'\]", f.clean, ['3'])
919 
920     def test_multiplechoicefield_2(self):
921         f = MultipleChoiceField(choices=[('1', 'One'), ('2', 'Two')], required=False)
922@@ -734,10 +727,10 @@
923         self.assertEqual([u'1', u'2'], f.clean(['1', '2']))
924         self.assertEqual([u'1', u'2'], f.clean([1, '2']))
925         self.assertEqual([u'1', u'2'], f.clean((1, '2')))
926-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a list of values.']", f.clean, 'hello')
927+        self.assertRaisesRegexp(ValidationError, "\[u'Enter a list of values\.'\]", f.clean, 'hello')
928         self.assertEqual([], f.clean([]))
929         self.assertEqual([], f.clean(()))
930-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. 3 is not one of the available choices.']", f.clean, ['3'])
931+        self.assertRaisesRegexp(ValidationError, "\[u'Select a valid choice\. 3 is not one of the available choices\.'\]", f.clean, ['3'])
932 
933     def test_multiplechoicefield_3(self):
934         f = MultipleChoiceField(choices=[('Numbers', (('1', 'One'), ('2', 'Two'))), ('Letters', (('3','A'),('4','B'))), ('5','Other')])
935@@ -747,8 +740,8 @@
936         self.assertEqual([u'1', u'5'], f.clean([1, '5']))
937         self.assertEqual([u'1', u'5'], f.clean(['1', 5]))
938         self.assertEqual([u'1', u'5'], f.clean(['1', '5']))
939-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. 6 is not one of the available choices.']", f.clean, ['6'])
940-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. 6 is not one of the available choices.']", f.clean, ['1','6'])
941+        self.assertRaisesRegexp(ValidationError, "\[u'Select a valid choice\. 6 is not one of the available choices\.'\]", f.clean, ['6'])
942+        self.assertRaisesRegexp(ValidationError, "\[u'Select a valid choice\. 6 is not one of the available choices\.'\]", f.clean, ['1','6'])
943 
944     # TypedMultipleChoiceField ############################################################
945     # TypedMultipleChoiceField is just like MultipleChoiceField, except that coerced types
946@@ -757,7 +750,7 @@
947     def test_typedmultiplechoicefield_1(self):
948         f = TypedMultipleChoiceField(choices=[(1, "+1"), (-1, "-1")], coerce=int)
949         self.assertEqual([1], f.clean(['1']))
950-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. 2 is not one of the available choices.']", f.clean, ['2'])
951+        self.assertRaisesRegexp(ValidationError, "\[u'Select a valid choice\. 2 is not one of the available choices\.'\]", f.clean, ['2'])
952 
953     def test_typedmultiplechoicefield_2(self):
954         # Different coercion, same validation.
955@@ -772,15 +765,15 @@
956     def test_typedmultiplechoicefield_4(self):
957         f = TypedMultipleChoiceField(choices=[(1, "+1"), (-1, "-1")], coerce=int)
958         self.assertEqual([1, -1], f.clean(['1','-1']))
959-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. 2 is not one of the available choices.']", f.clean, ['1','2'])
960+        self.assertRaisesRegexp(ValidationError, "\[u'Select a valid choice\. 2 is not one of the available choices\.'\]", f.clean, ['1','2'])
961 
962     def test_typedmultiplechoicefield_5(self):
963         # Even more weirdness: if you have a valid choice but your coercion function
964         # can't coerce, you'll still get a validation error. Don't do this!
965         f = TypedMultipleChoiceField(choices=[('A', 'A'), ('B', 'B')], coerce=int)
966-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. B is not one of the available choices.']", f.clean, ['B'])
967+        self.assertRaisesRegexp(ValidationError, "\[u'Select a valid choice\. B is not one of the available choices\.'\]", f.clean, ['B'])
968         # Required fields require values
969-        self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, [])
970+        self.assertRaisesRegexp(ValidationError, "\[u'This field is required\.'\]", f.clean, [])
971 
972     def test_typedmultiplechoicefield_6(self):
973         # Non-required fields aren't required
974@@ -797,16 +790,16 @@
975     def test_combofield_1(self):
976         f = ComboField(fields=[CharField(max_length=20), EmailField()])
977         self.assertEqual(u'test@example.com', f.clean('test@example.com'))
978-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value has at most 20 characters (it has 28).']", f.clean, 'longemailaddress@example.com')
979-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'not an e-mail')
980-        self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
981-        self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
982+        self.assertRaisesRegexp(ValidationError, "\[u'Ensure this value has at most 20 characters \(it has 28\)\.'\]", f.clean, 'longemailaddress@example.com')
983+        self.assertRaisesRegexp(ValidationError, "\[u'Enter a valid e-mail address\.'\]", f.clean, 'not an e-mail')
984+        self.assertRaisesRegexp(ValidationError, "\[u'This field is required\.'\]", f.clean, '')
985+        self.assertRaisesRegexp(ValidationError, "\[u'This field is required\.'\]", f.clean, None)
986 
987     def test_combofield_2(self):
988         f = ComboField(fields=[CharField(max_length=20), EmailField()], required=False)
989         self.assertEqual(u'test@example.com', f.clean('test@example.com'))
990-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Ensure this value has at most 20 characters (it has 28).']", f.clean, 'longemailaddress@example.com')
991-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'not an e-mail')
992+        self.assertRaisesRegexp(ValidationError, "\[u'Ensure this value has at most 20 characters \(it has 28\)\.'\]", f.clean, 'longemailaddress@example.com')
993+        self.assertRaisesRegexp(ValidationError, "\[u'Enter a valid e-mail address\.'\]", f.clean, 'not an e-mail')
994         self.assertEqual(u'', f.clean(''))
995         self.assertEqual(u'', f.clean(None))
996 
997@@ -835,7 +828,7 @@
998         for exp, got in zip(expected, fix_os_paths(f.choices)):
999             self.assertEqual(exp[1], got[1])
1000             self.assertTrue(got[0].endswith(exp[0]))
1001-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Select a valid choice. fields.py is not one of the available choices.']", f.clean, 'fields.py')
1002+        self.assertRaisesRegexp(ValidationError, "\[u'Select a valid choice\. fields\.py is not one of the available choices\.'\]", f.clean, 'fields.py')
1003         assert fix_os_paths(f.clean(path + 'fields.py')).endswith('/django/forms/fields.py')
1004 
1005     def test_filepathfield_3(self):
1006@@ -883,12 +876,12 @@
1007         f = SplitDateTimeField()
1008         assert isinstance(f.widget, SplitDateTimeWidget)
1009         self.assertEqual(datetime.datetime(2006, 1, 10, 7, 30), f.clean([datetime.date(2006, 1, 10), datetime.time(7, 30)]))
1010-        self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, None)
1011-        self.assertRaisesErrorWithMessage(ValidationError, "[u'This field is required.']", f.clean, '')
1012-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a list of values.']", f.clean, 'hello')
1013-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid date.', u'Enter a valid time.']", f.clean, ['hello', 'there'])
1014-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid time.']", f.clean, ['2006-01-10', 'there'])
1015-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid date.']", f.clean, ['hello', '07:30'])
1016+        self.assertRaisesRegexp(ValidationError, "\[u'This field is required\.'\]", f.clean, None)
1017+        self.assertRaisesRegexp(ValidationError, "\[u'This field is required\.'\]", f.clean, '')
1018+        self.assertRaisesRegexp(ValidationError, "\[u'Enter a list of values\.'\]", f.clean, 'hello')
1019+        self.assertRaisesRegexp(ValidationError, "\[u'Enter a valid date\.', u'Enter a valid time\.'\]", f.clean, ['hello', 'there'])
1020+        self.assertRaisesRegexp(ValidationError, "\[u'Enter a valid time\.'\]", f.clean, ['2006-01-10', 'there'])
1021+        self.assertRaisesRegexp(ValidationError, "\[u'Enter a valid date\.'\]", f.clean, ['hello', '07:30'])
1022 
1023     def test_splitdatetimefield_2(self):
1024         f = SplitDateTimeField(required=False)
1025@@ -898,10 +891,10 @@
1026         self.assertEqual(None, f.clean(''))
1027         self.assertEqual(None, f.clean(['']))
1028         self.assertEqual(None, f.clean(['', '']))
1029-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a list of values.']", f.clean, 'hello')
1030-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid date.', u'Enter a valid time.']", f.clean, ['hello', 'there'])
1031-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid time.']", f.clean, ['2006-01-10', 'there'])
1032-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid date.']", f.clean, ['hello', '07:30'])
1033-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid time.']", f.clean, ['2006-01-10', ''])
1034-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid time.']", f.clean, ['2006-01-10'])
1035-        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid date.']", f.clean, ['', '07:30'])
1036+        self.assertRaisesRegexp(ValidationError, "\[u'Enter a list of values\.'\]", f.clean, 'hello')
1037+        self.assertRaisesRegexp(ValidationError, "\[u'Enter a valid date\.', u'Enter a valid time\.'\]", f.clean, ['hello', 'there'])
1038+        self.assertRaisesRegexp(ValidationError, "\[u'Enter a valid time\.'\]", f.clean, ['2006-01-10', 'there'])
1039+        self.assertRaisesRegexp(ValidationError, "\[u'Enter a valid date\.'\]", f.clean, ['hello', '07:30'])
1040+        self.assertRaisesRegexp(ValidationError, "\[u'Enter a valid time\.'\]", f.clean, ['2006-01-10', ''])
1041+        self.assertRaisesRegexp(ValidationError, "\[u'Enter a valid time\.'\]", f.clean, ['2006-01-10'])
1042+        self.assertRaisesRegexp(ValidationError, "\[u'Enter a valid date\.'\]", f.clean, ['', '07:30'])
1043diff --git a/tests/regressiontests/queries/tests.py b/tests/regressiontests/queries/tests.py
1044--- a/tests/regressiontests/queries/tests.py
1045+++ b/tests/regressiontests/queries/tests.py
1046@@ -21,19 +21,6 @@
1047     def assertValueQuerysetEqual(self, qs, values):
1048         return self.assertQuerysetEqual(qs, values, transform=lambda x: x)
1049 
1050-    def assertRaisesMessage(self, exc, msg, func, *args, **kwargs):
1051-        try:
1052-            func(*args, **kwargs)
1053-        except Exception, e:
1054-            self.assertEqual(msg, str(e))
1055-            self.assertTrue(isinstance(e, exc), "Expected %s, got %s" % (exc, type(e)))
1056-        else:
1057-            if hasattr(exc, '__name__'):
1058-                excName = exc.__name__
1059-            else:
1060-                excName = str(exc)
1061-            raise AssertionError, "%s not raised" % excName
1062-
1063 
1064 class Queries1Tests(BaseQuerysetTest):
1065     def setUp(self):
1066@@ -362,14 +349,14 @@
1067     def test_heterogeneous_qs_combination(self):
1068         # Combining querysets built on different models should behave in a well-defined
1069         # fashion. We raise an error.
1070-        self.assertRaisesMessage(
1071+        self.assertRaisesRegexp(
1072             AssertionError,
1073-            'Cannot combine queries on two different base models.',
1074+            'Cannot combine queries on two different base models\.',
1075             lambda: Author.objects.all() & Tag.objects.all()
1076         )
1077-        self.assertRaisesMessage(
1078+        self.assertRaisesRegexp(
1079             AssertionError,
1080-            'Cannot combine queries on two different base models.',
1081+            'Cannot combine queries on two different base models\.',
1082             lambda: Author.objects.all() | Tag.objects.all()
1083         )
1084 
1085@@ -676,7 +663,7 @@
1086             []
1087         )
1088         q.query.low_mark = 1
1089-        self.assertRaisesMessage(
1090+        self.assertRaisesRegexp(
1091             AssertionError,
1092             'Cannot change a query once a slice has been taken',
1093             q.extra, select={'is_recent': "pub_date > '2006-01-01'"}
1094@@ -707,14 +694,14 @@
1095         )
1096 
1097         # Multi-valued values() and values_list() querysets should raise errors.
1098-        self.assertRaisesMessage(
1099+        self.assertRaisesRegexp(
1100             TypeError,
1101-            'Cannot use a multi-field ValuesQuerySet as a filter value.',
1102+            'Cannot use a multi-field ValuesQuerySet as a filter value\.',
1103             lambda: Tag.objects.filter(name__in=Tag.objects.filter(parent=self.t1).values('name', 'id'))
1104         )
1105-        self.assertRaisesMessage(
1106+        self.assertRaisesRegexp(
1107             TypeError,
1108-            'Cannot use a multi-field ValuesListQuerySet as a filter value.',
1109+            'Cannot use a multi-field ValuesListQuerySet as a filter value\.',
1110             lambda: Tag.objects.filter(name__in=Tag.objects.filter(parent=self.t1).values_list('name', 'id'))
1111         )
1112 
1113@@ -954,9 +941,9 @@
1114     def test_ticket8683(self):
1115         # Raise proper error when a DateQuerySet gets passed a wrong type of
1116         # field
1117-        self.assertRaisesMessage(
1118+        self.assertRaisesRegexp(
1119             AssertionError,
1120-            "'name' isn't a DateField.",
1121+            "'name' isn't a DateField\.",
1122             Item.objects.dates, 'name', 'month'
1123         )
1124 
1125@@ -1484,9 +1471,9 @@
1126         self.assertQuerysetEqual(Article.objects.all()[0:0], [])
1127         self.assertQuerysetEqual(Article.objects.all()[0:0][:10], [])
1128         self.assertEqual(Article.objects.all()[:0].count(), 0)
1129-        self.assertRaisesMessage(
1130+        self.assertRaisesRegexp(
1131             AssertionError,
1132-            'Cannot change a query once a slice has been taken.',
1133+            'Cannot change a query once a slice has been taken\.',
1134             Article.objects.all()[:0].latest, 'created'
1135         )
1136 
1137@@ -1531,14 +1518,14 @@
1138     def test_infinite_loop(self):
1139         # If you're not careful, it's possible to introduce infinite loops via
1140         # default ordering on foreign keys in a cycle. We detect that.
1141-        self.assertRaisesMessage(
1142+        self.assertRaisesRegexp(
1143             FieldError,
1144-            'Infinite loop caused by ordering.',
1145+            'Infinite loop caused by ordering\.',
1146             lambda: list(LoopX.objects.all()) # Force queryset evaluation with list()
1147         )
1148-        self.assertRaisesMessage(
1149+        self.assertRaisesRegexp(
1150             FieldError,
1151-            'Infinite loop caused by ordering.',
1152+            'Infinite loop caused by ordering\.',
1153             lambda: list(LoopZ.objects.all()) # Force queryset evaluation with list()
1154         )
1155 
1156diff --git a/tests/regressiontests/urlpatterns_reverse/tests.py b/tests/regressiontests/urlpatterns_reverse/tests.py
1157--- a/tests/regressiontests/urlpatterns_reverse/tests.py
1158+++ b/tests/regressiontests/urlpatterns_reverse/tests.py
1159@@ -133,22 +133,14 @@
1160 class NoURLPatternsTests(TestCase):
1161     urls = 'regressiontests.urlpatterns_reverse.no_urls'
1162 
1163-    def assertRaisesErrorWithMessage(self, error, message, callable,
1164-        *args, **kwargs):
1165-        self.assertRaises(error, callable, *args, **kwargs)
1166-        try:
1167-            callable(*args, **kwargs)
1168-        except error, e:
1169-            self.assertEqual(message, str(e))
1170-
1171     def test_no_urls_exception(self):
1172         """
1173         RegexURLResolver should raise an exception when no urlpatterns exist.
1174         """
1175         resolver = RegexURLResolver(r'^$', self.urls)
1176 
1177-        self.assertRaisesErrorWithMessage(ImproperlyConfigured,
1178-            "The included urlconf regressiontests.urlpatterns_reverse.no_urls "\
1179+        self.assertRaisesRegexp(ImproperlyConfigured,
1180+            "The included urlconf regressiontests\.urlpatterns_reverse\.no_urls "\
1181             "doesn't have any patterns in it", getattr, resolver, 'url_patterns')
1182 
1183 class URLPatternReverse(TestCase):
1184diff --git a/tests/regressiontests/utils/datastructures.py b/tests/regressiontests/utils/datastructures.py
1185--- a/tests/regressiontests/utils/datastructures.py
1186+++ b/tests/regressiontests/utils/datastructures.py
1187@@ -2,23 +2,13 @@
1188 Tests for stuff in django.utils.datastructures.
1189 """
1190 import pickle
1191-import unittest
1192 
1193 from django.utils.copycompat import copy
1194 from django.utils.datastructures import *
1195+from django.utils.unittest import TestCase
1196 
1197 
1198-class DatastructuresTestCase(unittest.TestCase):
1199-    def assertRaisesErrorWithMessage(self, error, message, callable,
1200-        *args, **kwargs):
1201-        self.assertRaises(error, callable, *args, **kwargs)
1202-        try:
1203-            callable(*args, **kwargs)
1204-        except error, e:
1205-            self.assertEqual(message, str(e))
1206-
1207-
1208-class SortedDictTests(DatastructuresTestCase):
1209+class SortedDictTests(TestCase):
1210     def setUp(self):
1211         self.d1 = SortedDict()
1212         self.d1[7] = 'seven'
1213@@ -124,7 +114,7 @@
1214         self.assertEquals(self.d1, {})
1215         self.assertEquals(self.d1.keyOrder, [])
1216 
1217-class MergeDictTests(DatastructuresTestCase):
1218+class MergeDictTests(TestCase):
1219 
1220     def test_simple_mergedict(self):
1221         d1 = {'chris':'cool', 'camri':'cute', 'cotton':'adorable',
1222@@ -178,7 +168,7 @@
1223                            ('key2', ['value2', 'value3']),
1224                            ('key4', ['value5', 'value6'])])
1225 
1226-class MultiValueDictTests(DatastructuresTestCase):
1227+class MultiValueDictTests(TestCase):
1228 
1229     def test_multivaluedict(self):
1230         d = MultiValueDict({'name': ['Adrian', 'Simon'],
1231@@ -197,9 +187,9 @@
1232         # MultiValueDictKeyError: "Key 'lastname' not found in
1233         # <MultiValueDict: {'position': ['Developer'],
1234         #                   'name': ['Adrian', 'Simon']}>"
1235-        self.assertRaisesErrorWithMessage(MultiValueDictKeyError,
1236-            '"Key \'lastname\' not found in <MultiValueDict: {\'position\':'\
1237-            ' [\'Developer\'], \'name\': [\'Adrian\', \'Simon\']}>"',
1238+        self.assertRaisesRegexp(MultiValueDictKeyError,
1239+            '"Key \'lastname\' not found in \<MultiValueDict: \{\'position\':'\
1240+            ' \[\'Developer\'\], \'name\': \[\'Adrian\', \'Simon\'\]\}\>"',
1241             d.__getitem__, 'lastname')
1242 
1243         self.assertEquals(d.get('lastname'), None)
1244@@ -233,7 +223,7 @@
1245             self.assertEqual(d2["key"], ["Penguin"])
1246 
1247 
1248-class DotExpandedDictTests(DatastructuresTestCase):
1249+class DotExpandedDictTests(TestCase):
1250 
1251     def test_dotexpandeddict(self):
1252 
1253@@ -247,14 +237,14 @@
1254         self.assertEquals(d['person']['2']['firstname'], ['Adrian'])
1255 
1256 
1257-class ImmutableListTests(DatastructuresTestCase):
1258+class ImmutableListTests(TestCase):
1259 
1260     def test_sort(self):
1261         d = ImmutableList(range(10))
1262 
1263         # AttributeError: ImmutableList object is immutable.
1264-        self.assertRaisesErrorWithMessage(AttributeError,
1265-            'ImmutableList object is immutable.', d.sort)
1266+        self.assertRaisesRegexp(AttributeError,
1267+            'ImmutableList object is immutable\.', d.sort)
1268 
1269         self.assertEquals(repr(d), '(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)')
1270 
1271@@ -264,11 +254,11 @@
1272         self.assertEquals(d[1], 1)
1273 
1274         # AttributeError: Object is immutable!
1275-        self.assertRaisesErrorWithMessage(AttributeError,
1276+        self.assertRaisesRegexp(AttributeError,
1277             'Object is immutable!', d.__setitem__, 1, 'test')
1278 
1279 
1280-class DictWrapperTests(DatastructuresTestCase):
1281+class DictWrapperTests(TestCase):
1282 
1283     def test_dictwrapper(self):
1284         f = lambda x: "*%s" % x