Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge branch 'master' of git://github.com/django/django

  • Loading branch information...
commit 9e190e1c82a287c88636f8fffea125224526f0e5 2 parents 9ce5890 + 292322f
Nick Martini authored September 07, 2012

Showing 29 changed files with 213 additions and 196 deletions. Show diff stats Hide diff stats

  1. 11  django/contrib/auth/tests/models.py
  2. 2  django/test/testcases.py
  3. 7  django/utils/six.py
  4. 28  tests/modeltests/basic/tests.py
  5. 7  tests/modeltests/empty/tests.py
  6. 34  tests/modeltests/fixtures/tests.py
  7. 3  tests/modeltests/many_to_many/tests.py
  8. 2  tests/modeltests/many_to_one/tests.py
  9. 3  tests/modeltests/update_only_fields/tests.py
  10. 3  tests/modeltests/validation/test_error_messages.py
  11. 7  tests/regressiontests/admin_filters/tests.py
  12. 6  tests/regressiontests/admin_scripts/tests.py
  13. 2  tests/regressiontests/backends/tests.py
  14. 7  tests/regressiontests/cache/tests.py
  15. 2  tests/regressiontests/file_storage/tests.py
  16. 17  tests/regressiontests/fixtures_regress/tests.py
  17. 6  tests/regressiontests/forms/tests/fields.py
  18. 2  tests/regressiontests/i18n/commands/compilation.py
  19. 4  tests/regressiontests/inline_formsets/tests.py
  20. 32  tests/regressiontests/localflavor/tr/tests.py
  21. 5  tests/regressiontests/m2m_regress/tests.py
  22. 5  tests/regressiontests/many_to_one_regress/tests.py
  23. 128  tests/regressiontests/modeladmin/tests.py
  24. 2  tests/regressiontests/staticfiles_tests/tests.py
  25. 51  tests/regressiontests/templates/custom.py
  26. 12  tests/regressiontests/templates/loaders.py
  27. 6  tests/regressiontests/test_utils/tests.py
  28. 8  tests/regressiontests/urlpatterns_reverse/tests.py
  29. 7  tests/regressiontests/wsgi/tests.py
11  django/contrib/auth/tests/models.py
... ...
@@ -1,8 +1,9 @@
1 1
 from django.conf import settings
  2
+from django.contrib.auth.models import (Group, User, SiteProfileNotAvailable,
  3
+    UserManager)
2 4
 from django.test import TestCase
3 5
 from django.test.utils import override_settings
4  
-from django.contrib.auth.models import (Group, User,
5  
-    SiteProfileNotAvailable, UserManager)
  6
+from django.utils import six
6 7
 
7 8
 
8 9
 @override_settings(USE_TZ=False, AUTH_PROFILE_MODULE='')
@@ -13,19 +14,19 @@ def test_site_profile_not_available(self):
13 14
 
14 15
         # calling get_profile without AUTH_PROFILE_MODULE set
15 16
         del settings.AUTH_PROFILE_MODULE
16  
-        with self.assertRaisesRegexp(SiteProfileNotAvailable,
  17
+        with six.assertRaisesRegex(self, SiteProfileNotAvailable,
17 18
                 "You need to set AUTH_PROFILE_MODULE in your project"):
18 19
             user.get_profile()
19 20
 
20 21
         # Bad syntax in AUTH_PROFILE_MODULE:
21 22
         settings.AUTH_PROFILE_MODULE = 'foobar'
22  
-        with self.assertRaisesRegexp(SiteProfileNotAvailable,
  23
+        with six.assertRaisesRegex(self, SiteProfileNotAvailable,
23 24
                 "app_label and model_name should be separated by a dot"):
24 25
             user.get_profile()
25 26
 
26 27
         # module that doesn't exist
27 28
         settings.AUTH_PROFILE_MODULE = 'foo.bar'
28  
-        with self.assertRaisesRegexp(SiteProfileNotAvailable,
  29
+        with six.assertRaisesRegex(self, SiteProfileNotAvailable,
29 30
                 "Unable to load the profile model"):
30 31
             user.get_profile()
31 32
 
2  django/test/testcases.py
@@ -358,7 +358,7 @@ def assertRaisesMessage(self, expected_exception, expected_message,
358 358
             args: Extra args.
359 359
             kwargs: Extra kwargs.
360 360
         """
361  
-        return self.assertRaisesRegexp(expected_exception,
  361
+        return six.assertRaisesRegex(self, expected_exception,
362 362
                 re.escape(expected_message), callable_obj, *args, **kwargs)
363 363
 
364 364
     def assertFieldOutput(self, fieldclass, valid, invalid, field_args=None,
7  django/utils/six.py
@@ -370,13 +370,20 @@ def with_metaclass(meta, base=object):
370 370
 
371 371
 if PY3:
372 372
     _iterlists = "lists"
  373
+    _assertRaisesRegex = "assertRaisesRegex"
373 374
 else:
374 375
     _iterlists = "iterlists"
  376
+    _assertRaisesRegex = "assertRaisesRegexp"
  377
+
375 378
 
376 379
 def iterlists(d):
377 380
     """Return an iterator over the values of a MultiValueDict."""
378 381
     return getattr(d, _iterlists)()
379 382
 
380 383
 
  384
+def assertRaisesRegex(self, *args, **kwargs):
  385
+    return getattr(self, _assertRaisesRegex)(*args, **kwargs)
  386
+
  387
+
381 388
 add_move(MovedModule("_dummy_thread", "dummy_thread"))
382 389
 add_move(MovedModule("_thread", "thread"))
28  tests/modeltests/basic/tests.py
@@ -5,7 +5,7 @@
5 5
 from django.core.exceptions import ObjectDoesNotExist
6 6
 from django.db.models.fields import Field, FieldDoesNotExist
7 7
 from django.test import TestCase, skipIfDBFeature, skipUnlessDBFeature
8  
-from django.utils.six import PY3
  8
+from django.utils import six
9 9
 from django.utils.translation import ugettext_lazy
10 10
 
11 11
 from .models import Article
@@ -82,7 +82,7 @@ def test_lookup(self):
82 82
 
83 83
         # Django raises an Article.DoesNotExist exception for get() if the
84 84
         # parameters don't match any object.
85  
-        self.assertRaisesRegexp(
  85
+        six.assertRaisesRegex(self,
86 86
             ObjectDoesNotExist,
87 87
             "Article matching query does not exist. Lookup parameters were "
88 88
             "{'id__exact': 2000}",
@@ -91,14 +91,14 @@ def test_lookup(self):
91 91
         )
92 92
         # To avoid dict-ordering related errors check only one lookup
93 93
         # in single assert.
94  
-        self.assertRaisesRegexp(
  94
+        six.assertRaisesRegex(self,
95 95
             ObjectDoesNotExist,
96 96
             ".*'pub_date__year': 2005.*",
97 97
             Article.objects.get,
98 98
             pub_date__year=2005,
99 99
             pub_date__month=8,
100 100
         )
101  
-        self.assertRaisesRegexp(
  101
+        six.assertRaisesRegex(self,
102 102
             ObjectDoesNotExist,
103 103
             ".*'pub_date__month': 8.*",
104 104
             Article.objects.get,
@@ -106,7 +106,7 @@ def test_lookup(self):
106 106
             pub_date__month=8,
107 107
         )
108 108
 
109  
-        self.assertRaisesRegexp(
  109
+        six.assertRaisesRegex(self,
110 110
             ObjectDoesNotExist,
111 111
             "Article matching query does not exist. Lookup parameters were "
112 112
             "{'pub_date__week_day': 6}",
@@ -168,7 +168,7 @@ def test_object_creation(self):
168 168
         self.assertEqual(a4.headline, 'Fourth article')
169 169
 
170 170
         # Don't use invalid keyword arguments.
171  
-        self.assertRaisesRegexp(
  171
+        six.assertRaisesRegex(self,
172 172
             TypeError,
173 173
             "'foo' is an invalid keyword argument for this function",
174 174
             Article,
@@ -259,13 +259,13 @@ def test_object_creation(self):
259 259
              "datetime.datetime(2005, 7, 28, 0, 0)"])
260 260
 
261 261
         # dates() requires valid arguments.
262  
-        self.assertRaisesRegexp(
  262
+        six.assertRaisesRegex(self,
263 263
             TypeError,
264 264
             "dates\(\) takes at least 3 arguments \(1 given\)",
265 265
             Article.objects.dates,
266 266
         )
267 267
 
268  
-        self.assertRaisesRegexp(
  268
+        six.assertRaisesRegex(self,
269 269
             FieldDoesNotExist,
270 270
             "Article has no field named 'invalid_field'",
271 271
             Article.objects.dates,
@@ -273,7 +273,7 @@ def test_object_creation(self):
273 273
             "year",
274 274
         )
275 275
 
276  
-        self.assertRaisesRegexp(
  276
+        six.assertRaisesRegex(self,
277 277
             AssertionError,
278 278
             "'kind' must be one of 'year', 'month' or 'day'.",
279 279
             Article.objects.dates,
@@ -281,7 +281,7 @@ def test_object_creation(self):
281 281
             "bad_kind",
282 282
         )
283 283
 
284  
-        self.assertRaisesRegexp(
  284
+        six.assertRaisesRegex(self,
285 285
             AssertionError,
286 286
             "'order' must be either 'ASC' or 'DESC'.",
287 287
             Article.objects.dates,
@@ -323,7 +323,7 @@ def test_object_creation(self):
323 323
              "<Article: Third article>"])
324 324
 
325 325
         # Slicing works with longs (Python 2 only -- Python 3 doesn't have longs).
326  
-        if not PY3:
  326
+        if not six.PY3:
327 327
             self.assertEqual(Article.objects.all()[long(0)], a)
328 328
             self.assertQuerysetEqual(Article.objects.all()[long(1):long(3)],
329 329
                 ["<Article: Second article>", "<Article: Third article>"])
@@ -369,14 +369,14 @@ def test_object_creation(self):
369 369
              "<Article: Updated article 8>"])
370 370
 
371 371
         # Also, once you have sliced you can't filter, re-order or combine
372  
-        self.assertRaisesRegexp(
  372
+        six.assertRaisesRegex(self,
373 373
             AssertionError,
374 374
             "Cannot filter a query once a slice has been taken.",
375 375
             Article.objects.all()[0:5].filter,
376 376
             id=a.id,
377 377
         )
378 378
 
379  
-        self.assertRaisesRegexp(
  379
+        six.assertRaisesRegex(self,
380 380
             AssertionError,
381 381
             "Cannot reorder a query once a slice has been taken.",
382 382
             Article.objects.all()[0:5].order_by,
@@ -411,7 +411,7 @@ def test_object_creation(self):
411 411
 
412 412
         # An Article instance doesn't have access to the "objects" attribute.
413 413
         # That's only available on the class.
414  
-        self.assertRaisesRegexp(
  414
+        six.assertRaisesRegex(self,
415 415
             AttributeError,
416 416
             "Manager isn't accessible via Article instances",
417 417
             getattr,
7  tests/modeltests/empty/tests.py
... ...
@@ -1,10 +1,10 @@
1 1
 from __future__ import absolute_import
2 2
 
3  
-from django.conf import settings
4 3
 from django.core.exceptions import ImproperlyConfigured
5 4
 from django.db.models.loading import get_app
6 5
 from django.test import TestCase
7 6
 from django.test.utils import override_settings
  7
+from django.utils import six
8 8
 
9 9
 from .models import Empty
10 10
 
@@ -14,12 +14,13 @@ def test_empty(self):
14 14
         m = Empty()
15 15
         self.assertEqual(m.id, None)
16 16
         m.save()
17  
-        m2 = Empty.objects.create()
  17
+        Empty.objects.create()
18 18
         self.assertEqual(len(Empty.objects.all()), 2)
19 19
         self.assertTrue(m.id is not None)
20 20
         existing = Empty(m.id)
21 21
         existing.save()
22 22
 
  23
+
23 24
 class NoModelTests(TestCase):
24 25
     """
25 26
     Test for #7198 to ensure that the proper error message is raised
@@ -32,6 +33,6 @@ class NoModelTests(TestCase):
32 33
     """
33 34
     @override_settings(INSTALLED_APPS=("modeltests.empty.no_models",))
34 35
     def test_no_models(self):
35  
-        with self.assertRaisesRegexp(ImproperlyConfigured,
  36
+        with six.assertRaisesRegex(self, ImproperlyConfigured,
36 37
                     'App with label no_models is missing a models.py module.'):
37 38
             get_app('no_models')
34  tests/modeltests/fixtures/tests.py
@@ -4,7 +4,7 @@
4 4
 from django.core import management
5 5
 from django.db import connection, IntegrityError
6 6
 from django.test import TestCase, TransactionTestCase, skipUnlessDBFeature
7  
-from django.utils.six import StringIO
  7
+from django.utils import six
8 8
 
9 9
 from .models import Article, Book, Spy, Tag, Visa
10 10
 
@@ -21,16 +21,17 @@ def testClassFixtures(self):
21 21
             '<Article: Poker has no place on ESPN>',
22 22
         ])
23 23
 
  24
+
24 25
 class FixtureLoadingTests(TestCase):
25 26
 
26 27
     def _dumpdata_assert(self, args, output, format='json', natural_keys=False,
27 28
                          use_base_manager=False, exclude_list=[]):
28  
-        new_io = StringIO()
29  
-        management.call_command('dumpdata', *args, **{'format':format,
30  
-                                                      'stdout':new_io,
31  
-                                                      'stderr':new_io,
32  
-                                                      'use_natural_keys':natural_keys,
33  
-                                                      'use_base_manager':use_base_manager,
  29
+        new_io = six.StringIO()
  30
+        management.call_command('dumpdata', *args, **{'format': format,
  31
+                                                      'stdout': new_io,
  32
+                                                      'stderr': new_io,
  33
+                                                      'use_natural_keys': natural_keys,
  34
+                                                      'use_base_manager': use_base_manager,
34 35
                                                       'exclude': exclude_list})
35 36
         command_output = new_io.getvalue().strip()
36 37
         self.assertEqual(command_output, output)
@@ -42,8 +43,6 @@ def test_initial_data(self):
42 43
         ])
43 44
 
44 45
     def test_loading_and_dumping(self):
45  
-        new_io = StringIO()
46  
-
47 46
         Site.objects.all().delete()
48 47
         # Load fixture 1. Single JSON file, with two objects.
49 48
         management.call_command('loaddata', 'fixture1.json', verbosity=0, commit=False)
@@ -184,12 +183,12 @@ def test_dumpdata_with_excludes(self):
184 183
             exclude_list=['fixtures.Article', 'fixtures.Book', 'sites'])
185 184
 
186 185
         # Excluding a bogus app should throw an error
187  
-        with self.assertRaisesRegexp(management.CommandError,
  186
+        with six.assertRaisesRegex(self, management.CommandError,
188 187
                 "Unknown app in excludes: foo_app"):
189 188
             self._dumpdata_assert(['fixtures', 'sites'], '', exclude_list=['foo_app'])
190 189
 
191 190
         # Excluding a bogus model should throw an error
192  
-        with self.assertRaisesRegexp(management.CommandError,
  191
+        with six.assertRaisesRegex(self, management.CommandError,
193 192
                 "Unknown model in excludes: fixtures.FooModel"):
194 193
             self._dumpdata_assert(['fixtures', 'sites'], '', exclude_list=['fixtures.FooModel'])
195 194
 
@@ -199,7 +198,7 @@ def test_dumpdata_with_filtering_manager(self):
199 198
         self.assertQuerysetEqual(Spy.objects.all(),
200 199
                                  ['<Spy: Paul>'])
201 200
         # Use the default manager
202  
-        self._dumpdata_assert(['fixtures.Spy'],'[{"pk": %d, "model": "fixtures.spy", "fields": {"cover_blown": false}}]' % spy1.pk)
  201
+        self._dumpdata_assert(['fixtures.Spy'], '[{"pk": %d, "model": "fixtures.spy", "fields": {"cover_blown": false}}]' % spy1.pk)
203 202
         # Dump using Django's base manager. Should return all objects,
204 203
         # even those normally filtered by the manager
205 204
         self._dumpdata_assert(['fixtures.Spy'], '[{"pk": %d, "model": "fixtures.spy", "fields": {"cover_blown": true}}, {"pk": %d, "model": "fixtures.spy", "fields": {"cover_blown": false}}]' % (spy2.pk, spy1.pk), use_base_manager=True)
@@ -227,7 +226,7 @@ def test_compressed_loading(self):
227 226
 
228 227
     def test_ambiguous_compressed_fixture(self):
229 228
         # The name "fixture5" is ambigous, so loading it will raise an error
230  
-        with self.assertRaisesRegexp(management.CommandError,
  229
+        with six.assertRaisesRegex(self, management.CommandError,
231 230
                 "Multiple fixtures named 'fixture5'"):
232 231
             management.call_command('loaddata', 'fixture5', verbosity=0, commit=False)
233 232
 
@@ -251,7 +250,7 @@ def test_loaddata_error_message(self):
251 250
         # is closed at the end of each test.
252 251
         if connection.vendor == 'mysql':
253 252
             connection.cursor().execute("SET sql_mode = 'TRADITIONAL'")
254  
-        with self.assertRaisesRegexp(IntegrityError,
  253
+        with six.assertRaisesRegex(self, IntegrityError,
255 254
                 "Could not load fixtures.Article\(pk=1\): .*$"):
256 255
             management.call_command('loaddata', 'invalid.json', verbosity=0, commit=False)
257 256
 
@@ -290,10 +289,11 @@ def test_output_formats(self):
290 289
         self._dumpdata_assert(['fixtures'], """<?xml version="1.0" encoding="utf-8"?>
291 290
 <django-objects version="1.0"><object pk="1" model="fixtures.category"><field type="CharField" name="title">News Stories</field><field type="TextField" name="description">Latest news stories</field></object><object pk="2" model="fixtures.article"><field type="CharField" name="headline">Poker has no place on ESPN</field><field type="DateTimeField" name="pub_date">2006-06-16T12:00:00</field></object><object pk="3" model="fixtures.article"><field type="CharField" name="headline">Time to reform copyright</field><field type="DateTimeField" name="pub_date">2006-06-16T13:00:00</field></object><object pk="1" model="fixtures.tag"><field type="CharField" name="name">copyright</field><field to="contenttypes.contenttype" name="tagged_type" rel="ManyToOneRel"><natural>fixtures</natural><natural>article</natural></field><field type="PositiveIntegerField" name="tagged_id">3</field></object><object pk="2" model="fixtures.tag"><field type="CharField" name="name">law</field><field to="contenttypes.contenttype" name="tagged_type" rel="ManyToOneRel"><natural>fixtures</natural><natural>article</natural></field><field type="PositiveIntegerField" name="tagged_id">3</field></object><object pk="1" model="fixtures.person"><field type="CharField" name="name">Django Reinhardt</field></object><object pk="2" model="fixtures.person"><field type="CharField" name="name">Stephane Grappelli</field></object><object pk="3" model="fixtures.person"><field type="CharField" name="name">Prince</field></object><object pk="10" model="fixtures.book"><field type="CharField" name="name">Achieving self-awareness of Python programs</field><field to="fixtures.person" name="authors" rel="ManyToManyRel"></field></object></django-objects>""", format='xml', natural_keys=True)
292 291
 
  292
+
293 293
 class FixtureTransactionTests(TransactionTestCase):
294 294
     def _dumpdata_assert(self, args, output, format='json'):
295  
-        new_io = StringIO()
296  
-        management.call_command('dumpdata', *args, **{'format':format, 'stdout':new_io})
  295
+        new_io = six.StringIO()
  296
+        management.call_command('dumpdata', *args, **{'format': format, 'stdout': new_io})
297 297
         command_output = new_io.getvalue().strip()
298 298
         self.assertEqual(command_output, output)
299 299
 
@@ -308,7 +308,7 @@ def test_format_discovery(self):
308 308
 
309 309
         # Try to load fixture 2 using format discovery; this will fail
310 310
         # because there are two fixture2's in the fixtures directory
311  
-        with self.assertRaisesRegexp(management.CommandError,
  311
+        with six.assertRaisesRegex(self, management.CommandError,
312 312
                 "Multiple fixtures named 'fixture2'"):
313 313
             management.call_command('loaddata', 'fixture2', verbosity=0)
314 314
 
3  tests/modeltests/many_to_many/tests.py
... ...
@@ -1,6 +1,7 @@
1 1
 from __future__ import absolute_import
2 2
 
3 3
 from django.test import TestCase
  4
+from django.utils import six
4 5
 
5 6
 from .models import Article, Publication
6 7
 
@@ -52,7 +53,7 @@ def test_add(self):
52 53
             ])
53 54
 
54 55
         # Adding an object of the wrong type raises TypeError
55  
-        with self.assertRaisesRegexp(TypeError, "'Publication' instance expected, got <Article.*"):
  56
+        with six.assertRaisesRegex(self, TypeError, "'Publication' instance expected, got <Article.*"):
56 57
             a6.publications.add(a5)
57 58
         # Add a Publication directly via publications.add by using keyword arguments.
58 59
         p4 = a6.publications.create(title='Highlights for Adults')
2  tests/modeltests/many_to_one/tests.py
@@ -70,7 +70,7 @@ def test_add(self):
70 70
         self.assertQuerysetEqual(self.r2.article_set.all(), ["<Article: Paul's story>"])
71 71
 
72 72
         # Adding an object of the wrong type raises TypeError.
73  
-        with self.assertRaisesRegexp(TypeError, "'Article' instance expected, got <Reporter.*"):
  73
+        with six.assertRaisesRegex(self, TypeError, "'Article' instance expected, got <Reporter.*"):
74 74
             self.r.article_set.add(self.r2)
75 75
         self.assertQuerysetEqual(self.r.article_set.all(),
76 76
             [
3  tests/modeltests/update_only_fields/tests.py
... ...
@@ -1,7 +1,8 @@
1 1
 from __future__ import absolute_import
2 2
 
3  
-from django.test import TestCase
4 3
 from django.db.models.signals import pre_save, post_save
  4
+from django.test import TestCase
  5
+
5 6
 from .models import Person, Employee, ProxyEmployee, Profile, Account
6 7
 
7 8
 
3  tests/modeltests/validation/test_error_messages.py
@@ -3,6 +3,7 @@
3 3
 
4 4
 from django.core.exceptions import ValidationError
5 5
 from django.db import models
  6
+from django.utils import six
6 7
 from django.utils.unittest import TestCase
7 8
 
8 9
 
@@ -18,7 +19,7 @@ def test_autofield_field_raises_error_message(self):
18 19
         self._test_validation_messages(f, 'fõo',
19 20
             ["'fõo' value must be an integer."])
20 21
         # primary_key must be True. Refs #12467.
21  
-        with self.assertRaisesRegexp(AssertionError,
  22
+        with six.assertRaisesRegex(self, AssertionError,
22 23
                 "AutoFields must have primary_key=True."):
23 24
             models.AutoField(primary_key=False)
24 25
 
7  tests/regressiontests/admin_filters/tests.py
@@ -9,7 +9,7 @@
9 9
 from django.contrib.auth.models import User
10 10
 from django.core.exceptions import ImproperlyConfigured
11 11
 from django.test import TestCase, RequestFactory
12  
-from django.test.utils import override_settings
  12
+from django.test.utils import override_settings, six
13 13
 from django.utils.encoding import force_text
14 14
 
15 15
 from .models import Book, Department, Employee
@@ -18,6 +18,7 @@
18 18
 def select_by(dictlist, key, value):
19 19
     return [x for x in dictlist if x[key] == value][0]
20 20
 
  21
+
21 22
 class DecadeListFilter(SimpleListFilter):
22 23
 
23 24
     def lookups(self, request, model_admin):
@@ -520,7 +521,7 @@ def test_listfilter_without_title(self):
520 521
         """
521 522
         modeladmin = DecadeFilterBookAdminWithoutTitle(Book, site)
522 523
         request = self.request_factory.get('/', {})
523  
-        self.assertRaisesRegexp(ImproperlyConfigured,
  524
+        six.assertRaisesRegex(self, ImproperlyConfigured,
524 525
             "The list filter 'DecadeListFilterWithoutTitle' does not specify a 'title'.",
525 526
             self.get_changelist, request, Book, modeladmin)
526 527
 
@@ -530,7 +531,7 @@ def test_simplelistfilter_without_parameter(self):
530 531
         """
531 532
         modeladmin = DecadeFilterBookAdminWithoutParameter(Book, site)
532 533
         request = self.request_factory.get('/', {})
533  
-        self.assertRaisesRegexp(ImproperlyConfigured,
  534
+        six.assertRaisesRegex(self, ImproperlyConfigured,
534 535
             "The list filter 'DecadeListFilterWithoutParameter' does not specify a 'parameter_name'.",
535 536
             self.get_changelist, request, Book, modeladmin)
536 537
 
6  tests/regressiontests/admin_scripts/tests.py
@@ -1576,7 +1576,6 @@ def test_custom_project_destination_missing(self):
1576 1576
         self.assertOutput(err, "Destination directory '%s' does not exist, please create it first." % testproject_dir)
1577 1577
         self.assertFalse(os.path.exists(testproject_dir))
1578 1578
 
1579  
-
1580 1579
     def test_custom_project_template_with_non_ascii_templates(self):
1581 1580
         "Ticket 18091: Make sure the startproject management command is able to render templates with non-ASCII content"
1582 1581
         template_path = os.path.join(test_dir, 'admin_scripts', 'custom_templates', 'project_template')
@@ -1588,5 +1587,6 @@ def test_custom_project_template_with_non_ascii_templates(self):
1588 1587
         self.assertNoOutput(err)
1589 1588
         self.assertTrue(os.path.isdir(testproject_dir))
1590 1589
         path = os.path.join(testproject_dir, 'ticket-18091-non-ascii-template.txt')
1591  
-        self.assertEqual(codecs.open(path, 'r', 'utf-8').read(),
1592  
-                         'Some non-ASCII text for testing ticket #18091:\nüäö €\n')
  1590
+        with codecs.open(path, 'r', 'utf-8') as f:
  1591
+            self.assertEqual(f.read(),
  1592
+                'Some non-ASCII text for testing ticket #18091:\nüäö €\n')
2  tests/regressiontests/backends/tests.py
@@ -655,7 +655,7 @@ def runner2(other_thread_connection):
655 655
 
656 656
 class BackendLoadingTests(TestCase):
657 657
     def test_old_style_backends_raise_useful_exception(self):
658  
-        self.assertRaisesRegexp(ImproperlyConfigured,
  658
+        six.assertRaisesRegex(self, ImproperlyConfigured,
659 659
             "Try using django.db.backends.sqlite3 instead",
660 660
             load_backend, 'sqlite3')
661 661
 
7  tests/regressiontests/cache/tests.py
@@ -15,7 +15,7 @@
15 15
 
16 16
 from django.conf import settings
17 17
 from django.core import management
18  
-from django.core.cache import get_cache, DEFAULT_CACHE_ALIAS
  18
+from django.core.cache import get_cache
19 19
 from django.core.cache.backends.base import (CacheKeyWarning,
20 20
     InvalidCacheBackendError)
21 21
 from django.db import router
@@ -25,8 +25,7 @@
25 25
 from django.template import Template
26 26
 from django.template.response import TemplateResponse
27 27
 from django.test import TestCase, TransactionTestCase, RequestFactory
28  
-from django.test.utils import (get_warnings_state, restore_warnings_state,
29  
-    override_settings)
  28
+from django.test.utils import override_settings, six
30 29
 from django.utils import timezone, translation, unittest
31 30
 from django.utils.cache import (patch_vary_headers, get_cache_key,
32 31
     learn_cache_key, patch_cache_control, patch_response_headers)
@@ -821,7 +820,7 @@ def test_old_initialization(self):
821 820
         self.perform_cull_test(50, 18)
822 821
 
823 822
     def test_second_call_doesnt_crash(self):
824  
-        with self.assertRaisesRegexp(management.CommandError,
  823
+        with six.assertRaisesRegex(self, management.CommandError,
825 824
                 "Cache table 'test cache table' could not be created"):
826 825
             management.call_command(
827 826
                'createcachetable',
2  tests/regressiontests/file_storage/tests.py
@@ -73,7 +73,7 @@ def test_get_nonexisting_storage_module(self):
73 73
         get_storage_class raises an error if the requested module don't exist.
74 74
         """
75 75
         # Error message may or may not be the fully qualified path.
76  
-        self.assertRaisesRegexp(
  76
+        six.assertRaisesRegex(self,
77 77
             ImproperlyConfigured,
78 78
             ('Error importing storage module django.core.files.non_existing_'
79 79
                 'storage: "No module named .*non_existing_storage"'),
17  tests/regressiontests/fixtures_regress/tests.py
@@ -13,6 +13,7 @@
13 13
 from django.test import (TestCase, TransactionTestCase, skipIfDBFeature,
14 14
     skipUnlessDBFeature)
15 15
 from django.test.utils import override_settings
  16
+from django.utils import six
16 17
 from django.utils.six import PY3, StringIO
17 18
 
18 19
 from .models import (Animal, Stuff, Absolute, Parent, Child, Article, Widget,
@@ -116,7 +117,7 @@ def test_unknown_format(self):
116 117
         Test for ticket #4371 -- Loading data of an unknown format should fail
117 118
         Validate that error conditions are caught correctly
118 119
         """
119  
-        with self.assertRaisesRegexp(management.CommandError,
  120
+        with six.assertRaisesRegex(self, management.CommandError,
120 121
                 "Problem installing fixture 'bad_fixture1': "
121 122
                 "unkn is not a known serialization format."):
122 123
             management.call_command(
@@ -131,7 +132,7 @@ def test_unimportable_serializer(self):
131 132
         """
132 133
         Test that failing serializer import raises the proper error
133 134
         """
134  
-        with self.assertRaisesRegexp(ImportError,
  135
+        with six.assertRaisesRegex(self, ImportError,
135 136
                 "No module named unexistent.path"):
136 137
             management.call_command(
137 138
                 'loaddata',
@@ -146,7 +147,7 @@ def test_invalid_data(self):
146 147
         using explicit filename.
147 148
         Validate that error conditions are caught correctly
148 149
         """
149  
-        with self.assertRaisesRegexp(management.CommandError,
  150
+        with six.assertRaisesRegex(self, management.CommandError,
150 151
                 "No fixture data found for 'bad_fixture2'. \(File format may be invalid.\)"):
151 152
             management.call_command(
152 153
                 'loaddata',
@@ -161,7 +162,7 @@ def test_invalid_data_no_ext(self):
161 162
         without file extension.
162 163
         Validate that error conditions are caught correctly
163 164
         """
164  
-        with self.assertRaisesRegexp(management.CommandError,
  165
+        with six.assertRaisesRegex(self, management.CommandError,
165 166
                 "No fixture data found for 'bad_fixture2'. \(File format may be invalid.\)"):
166 167
             management.call_command(
167 168
                 'loaddata',
@@ -175,7 +176,7 @@ def test_empty(self):
175 176
         Test for ticket #4371 -- Loading a fixture file with no data returns an error.
176 177
         Validate that error conditions are caught correctly
177 178
         """
178  
-        with self.assertRaisesRegexp(management.CommandError,
  179
+        with six.assertRaisesRegex(self, management.CommandError,
179 180
                 "No fixture data found for 'empty'. \(File format may be invalid.\)"):
180 181
             management.call_command(
181 182
                 'loaddata',
@@ -188,7 +189,7 @@ def test_error_message(self):
188 189
         """
189 190
         (Regression for #9011 - error message is correct)
190 191
         """
191  
-        with self.assertRaisesRegexp(management.CommandError,
  192
+        with six.assertRaisesRegex(self, management.CommandError,
192 193
                 "^No fixture data found for 'bad_fixture2'. \(File format may be invalid.\)$"):
193 194
             management.call_command(
194 195
                 'loaddata',
@@ -353,7 +354,7 @@ def test_loaddata_raises_error_when_fixture_has_invalid_foreign_key(self):
353 354
         """
354 355
         Regression for #3615 - Ensure data with nonexistent child key references raises error
355 356
         """
356  
-        with self.assertRaisesRegexp(IntegrityError,
  357
+        with six.assertRaisesRegex(self, IntegrityError,
357 358
                 "Problem installing fixture"):
358 359
             management.call_command(
359 360
                 'loaddata',
@@ -385,7 +386,7 @@ def test_loaddata_no_fixture_specified(self):
385 386
         """
386 387
         Regression for #7043 - Error is quickly reported when no fixtures is provided in the command line.
387 388
         """
388  
-        with self.assertRaisesRegexp(management.CommandError,
  389
+        with six.assertRaisesRegex(self, management.CommandError,
389 390
                 "No database fixture specified. Please provide the path of "
390 391
                 "at least one fixture in the command line."):
391 392
             management.call_command(
6  tests/regressiontests/forms/tests/fields.py
@@ -475,7 +475,7 @@ def test_regexfield_4(self):
475 475
     def test_regexfield_5(self):
476 476
         f = RegexField('^\d+$', min_length=5, max_length=10)
477 477
         self.assertRaisesMessage(ValidationError, "'Ensure this value has at least 5 characters (it has 3).'", f.clean, '123')
478  
-        self.assertRaisesRegexp(ValidationError, "'Ensure this value has at least 5 characters \(it has 3\)\.', u?'Enter a valid value\.'", f.clean, 'abc')
  478
+        six.assertRaisesRegex(self, ValidationError, "'Ensure this value has at least 5 characters \(it has 3\)\.', u?'Enter a valid value\.'", f.clean, 'abc')
479 479
         self.assertEqual('12345', f.clean('12345'))
480 480
         self.assertEqual('1234567890', f.clean('1234567890'))
481 481
         self.assertRaisesMessage(ValidationError, "'Ensure this value has at most 10 characters (it has 11).'", f.clean, '12345678901')
@@ -1036,7 +1036,7 @@ def test_splitdatetimefield_1(self):
1036 1036
         self.assertRaisesMessage(ValidationError, "'This field is required.'", f.clean, None)
1037 1037
         self.assertRaisesMessage(ValidationError, "'This field is required.'", f.clean, '')
1038 1038
         self.assertRaisesMessage(ValidationError, "'Enter a list of values.'", f.clean, 'hello')
1039  
-        self.assertRaisesRegexp(ValidationError, "'Enter a valid date\.', u?'Enter a valid time\.'", f.clean, ['hello', 'there'])
  1039
+        six.assertRaisesRegex(self, ValidationError, "'Enter a valid date\.', u?'Enter a valid time\.'", f.clean, ['hello', 'there'])
1040 1040
         self.assertRaisesMessage(ValidationError, "'Enter a valid time.'", f.clean, ['2006-01-10', 'there'])
1041 1041
         self.assertRaisesMessage(ValidationError, "'Enter a valid date.'", f.clean, ['hello', '07:30'])
1042 1042
 
@@ -1049,7 +1049,7 @@ def test_splitdatetimefield_2(self):
1049 1049
         self.assertEqual(None, f.clean(['']))
1050 1050
         self.assertEqual(None, f.clean(['', '']))
1051 1051
         self.assertRaisesMessage(ValidationError, "'Enter a list of values.'", f.clean, 'hello')
1052  
-        self.assertRaisesRegexp(ValidationError, "'Enter a valid date\.', u?'Enter a valid time\.'", f.clean, ['hello', 'there'])
  1052
+        six.assertRaisesRegex(self, ValidationError, "'Enter a valid date\.', u?'Enter a valid time\.'", f.clean, ['hello', 'there'])
1053 1053
         self.assertRaisesMessage(ValidationError, "'Enter a valid time.'", f.clean, ['2006-01-10', 'there'])
1054 1054
         self.assertRaisesMessage(ValidationError, "'Enter a valid date.'", f.clean, ['hello', '07:30'])
1055 1055
         self.assertRaisesMessage(ValidationError, "'Enter a valid time.'", f.clean, ['2006-01-10', ''])
2  tests/regressiontests/i18n/commands/compilation.py
@@ -24,7 +24,7 @@ class PoFileTests(MessageCompilationTests):
24 24
 
25 25
     def test_bom_rejection(self):
26 26
         os.chdir(test_dir)
27  
-        with self.assertRaisesRegexp(CommandError,
  27
+        with six.assertRaisesRegex(self, CommandError,
28 28
                 "file has a BOM \(Byte Order Mark\)"):
29 29
             call_command('compilemessages', locale=self.LOCALE, stderr=StringIO())
30 30
         self.assertFalse(os.path.exists(self.MO_FILE))
4  tests/regressiontests/inline_formsets/tests.py
@@ -123,7 +123,7 @@ def test_exception_on_unspecified_foreign_key(self):
123 123
         Child has two ForeignKeys to Parent, so if we don't specify which one
124 124
         to use for the inline formset, we should get an exception.
125 125
         """
126  
-        self.assertRaisesRegexp(Exception,
  126
+        six.assertRaisesRegex(self, Exception,
127 127
             "<class 'regressiontests.inline_formsets.models.Child'> has more than 1 ForeignKey to <class 'regressiontests.inline_formsets.models.Parent'>",
128 128
             inlineformset_factory, Parent, Child
129 129
         )
@@ -143,7 +143,7 @@ def test_non_foreign_key_field(self):
143 143
         If the field specified in fk_name is not a ForeignKey, we should get an
144 144
         exception.
145 145
         """
146  
-        self.assertRaisesRegexp(Exception,
  146
+        six.assertRaisesRegex(self, Exception,
147 147
             "<class 'regressiontests.inline_formsets.models.Child'> has no field named 'test'",
148 148
             inlineformset_factory, Parent, Child, fk_name='test'
149 149
         )
32  tests/regressiontests/localflavor/tr/tests.py
@@ -2,29 +2,31 @@
2 2
 
3 3
 from django.contrib.localflavor.tr import forms as trforms
4 4
 from django.core.exceptions import ValidationError
  5
+from django.utils import six
5 6
 from django.utils.unittest import TestCase
6 7
 
  8
+
7 9
 class TRLocalFlavorTests(TestCase):
8 10
     def test_TRPostalCodeField(self):
9 11
         f = trforms.TRPostalCodeField()
10 12
         self.assertEqual(f.clean("06531"), "06531")
11 13
         self.assertEqual(f.clean("12345"), "12345")
12  
-        self.assertRaisesRegexp(ValidationError,
  14
+        six.assertRaisesRegex(self, ValidationError,
13 15
             "Enter a postal code in the format XXXXX.",
14 16
             f.clean, "a1234")
15  
-        self.assertRaisesRegexp(ValidationError,
  17
+        six.assertRaisesRegex(self, ValidationError,
16 18
             "Enter a postal code in the format XXXXX.",
17 19
             f.clean, "1234")
18  
-        self.assertRaisesRegexp(ValidationError,
  20
+        six.assertRaisesRegex(self, ValidationError,
19 21
             "Enter a postal code in the format XXXXX.",
20 22
             f.clean, "82123")
21  
-        self.assertRaisesRegexp(ValidationError,
  23
+        six.assertRaisesRegex(self, ValidationError,
22 24
             "Enter a postal code in the format XXXXX.",
23 25
             f.clean, "00123")
24  
-        self.assertRaisesRegexp(ValidationError,
  26
+        six.assertRaisesRegex(self, ValidationError,
25 27
             "Enter a postal code in the format XXXXX.",
26 28
             f.clean, "123456")
27  
-        self.assertRaisesRegexp(ValidationError,
  29
+        six.assertRaisesRegex(self, ValidationError,
28 30
             "Enter a postal code in the format XXXXX.",
29 31
             f.clean, "12 34")
30 32
         self.assertRaises(ValidationError, f.clean, None)
@@ -40,34 +42,34 @@ def test_TRPhoneNumberField(self):
40 42
         self.assertEqual(f.clean("+90 312 455 4567"), "3124554567")
41 43
         self.assertEqual(f.clean("+90 312 455 45 67"), "3124554567")
42 44
         self.assertEqual(f.clean("+90 (312) 4554567"), "3124554567")
43  
-        self.assertRaisesRegexp(ValidationError,
  45
+        six.assertRaisesRegex(self, ValidationError,
44 46
             'Phone numbers must be in 0XXX XXX XXXX format.',
45 47
             f.clean, "1234 233 1234")
46  
-        self.assertRaisesRegexp(ValidationError,
  48
+        six.assertRaisesRegex(self, ValidationError,
47 49
             'Phone numbers must be in 0XXX XXX XXXX format.',
48 50
             f.clean, "0312 233 12345")
49  
-        self.assertRaisesRegexp(ValidationError,
  51
+        six.assertRaisesRegex(self, ValidationError,
50 52
             'Phone numbers must be in 0XXX XXX XXXX format.',
51 53
             f.clean, "0312 233 123")
52  
-        self.assertRaisesRegexp(ValidationError,
  54
+        six.assertRaisesRegex(self, ValidationError,
53 55
             'Phone numbers must be in 0XXX XXX XXXX format.',
54 56
             f.clean, "0312 233 xxxx")
55 57
 
56 58
     def test_TRIdentificationNumberField(self):
57 59
         f = trforms.TRIdentificationNumberField()
58 60
         self.assertEqual(f.clean("10000000146"), "10000000146")
59  
-        self.assertRaisesRegexp(ValidationError,
  61
+        six.assertRaisesRegex(self, ValidationError,
60 62
             'Enter a valid Turkish Identification number.',
61 63
             f.clean, "10000000136")
62  
-        self.assertRaisesRegexp(ValidationError,
  64
+        six.assertRaisesRegex(self, ValidationError,
63 65
             'Enter a valid Turkish Identification number.',
64 66
             f.clean, "10000000147")
65  
-        self.assertRaisesRegexp(ValidationError,
  67
+        six.assertRaisesRegex(self, ValidationError,
66 68
             'Turkish Identification number must be 11 digits.',
67 69
             f.clean, "123456789")
68  
-        self.assertRaisesRegexp(ValidationError,
  70
+        six.assertRaisesRegex(self, ValidationError,
69 71
             'Enter a valid Turkish Identification number.',
70 72
             f.clean, "1000000014x")
71  
-        self.assertRaisesRegexp(ValidationError,
  73
+        six.assertRaisesRegex(self, ValidationError,
72 74
             'Enter a valid Turkish Identification number.',
73 75
             f.clean, "x0000000146")
5  tests/regressiontests/m2m_regress/tests.py
@@ -2,6 +2,7 @@
2 2
 
3 3
 from django.core.exceptions import FieldError
4 4
 from django.test import TestCase
  5
+from django.utils import six
5 6
 
6 7
 from .models import (SelfRefer, Tag, TagCollection, Entry, SelfReferChild,
7 8
     SelfReferChildSibling, Worksheet)
@@ -35,7 +36,7 @@ def test_internal_related_name_not_in_error_msg(self):
35 36
         # The secret internal related names for self-referential many-to-many
36 37
         # fields shouldn't appear in the list when an error is made.
37 38
 
38  
-        self.assertRaisesRegexp(FieldError,
  39
+        six.assertRaisesRegex(self, FieldError,
39 40
             "Choices are: id, name, references, related, selfreferchild, selfreferchildsibling$",
40 41
             lambda: SelfRefer.objects.filter(porcupine='fred')
41 42
         )
@@ -70,7 +71,7 @@ def test_add_m2m_with_base_class(self):
70 71
         t2 = Tag.objects.create(name='t2')
71 72
 
72 73
         c1 = TagCollection.objects.create(name='c1')
73  
-        c1.tags = [t1,t2]
  74
+        c1.tags = [t1, t2]
74 75
         c1 = TagCollection.objects.get(name='c1')
75 76
 
76 77
         self.assertQuerysetEqual(c1.tags.all(), ["<Tag: t1>", "<Tag: t2>"])
5  tests/regressiontests/many_to_one_regress/tests.py
@@ -2,8 +2,9 @@
2 2
 
3 3
 from django.db import models
4 4
 from django.test import TestCase
  5
+from django.utils import six
5 6
 
6  
-from .models import First, Second, Third, Parent, Child, Category, Record, Relation
  7
+from .models import First, Third, Parent, Child, Category, Record, Relation
7 8
 
8 9
 
9 10
 class ManyToOneRegressionTests(TestCase):
@@ -59,7 +60,7 @@ def test_fk_assignment_and_related_object_cache(self):
59 60
         self.assertRaises(ValueError, Child.objects.create, name='xyzzy', parent=None)
60 61
 
61 62
         # Trying to assign to unbound attribute raises AttributeError
62  
-        self.assertRaisesRegexp(AttributeError, "must be accessed via instance",
  63
+        six.assertRaisesRegex(self, AttributeError, "must be accessed via instance",
63 64
             Child.parent.__set__, None, p)
64 65
 
65 66
         # Creation using keyword argument should cache the related object.
128  tests/regressiontests/modeladmin/tests.py
@@ -16,7 +16,7 @@
16 16
 from django.forms.widgets import Select
17 17
 from django.test import TestCase
18 18
 from django.test.utils import str_prefix
19  
-from django.utils import unittest
  19
+from django.utils import unittest, six
20 20
 
21 21
 from .models import Band, Concert, ValidationTestModel, ValidationTestInlineModel
22 22
 
@@ -506,7 +506,7 @@ class ValidationTestModelAdmin(ModelAdmin):
506 506
 
507 507
             site = AdminSite()
508 508
 
509  
-            self.assertRaisesRegexp(
  509
+            six.assertRaisesRegex(self,
510 510
                 ImproperlyConfigured,
511 511
                 "'ValidationTestModelAdmin.raw_id_fields' must be a list or tuple.",
512 512
                 site.register,
@@ -524,7 +524,7 @@ def test_raw_id_fields_validation(self):
524 524
         class ValidationTestModelAdmin(ModelAdmin):
525 525
             raw_id_fields = 10
526 526
 
527  
-        self.assertRaisesRegexp(
  527
+        six.assertRaisesRegex(self,
528 528
             ImproperlyConfigured,
529 529
             "'ValidationTestModelAdmin.raw_id_fields' must be a list or tuple.",
530 530
             validate,
@@ -535,7 +535,7 @@ class ValidationTestModelAdmin(ModelAdmin):
535 535
         class ValidationTestModelAdmin(ModelAdmin):
536 536
             raw_id_fields = ('non_existent_field',)
537 537
 
538  
-        self.assertRaisesRegexp(
  538
+        six.assertRaisesRegex(self,
539 539
             ImproperlyConfigured,
540 540
             "'ValidationTestModelAdmin.raw_id_fields' refers to field 'non_existent_field' that is missing from model 'modeladmin.ValidationTestModel'.",
541 541
             validate,
@@ -546,7 +546,7 @@ class ValidationTestModelAdmin(ModelAdmin):
546 546
         class ValidationTestModelAdmin(ModelAdmin):
547 547
             raw_id_fields = ('name',)
548 548
 
549  
-        self.assertRaisesRegexp(
  549
+        six.assertRaisesRegex(self,
550 550
             ImproperlyConfigured,
551 551
             "'ValidationTestModelAdmin.raw_id_fields\[0\]', 'name' must be either a ForeignKey or ManyToManyField.",
552 552
             validate,
@@ -564,7 +564,7 @@ def test_fieldsets_validation(self):
564 564
         class ValidationTestModelAdmin(ModelAdmin):
565 565
             fieldsets = 10
566 566
 
567  
-        self.assertRaisesRegexp(
  567
+        six.assertRaisesRegex(self,
568 568
             ImproperlyConfigured,
569 569
             "'ValidationTestModelAdmin.fieldsets' must be a list or tuple.",
570 570
             validate,
@@ -575,7 +575,7 @@ class ValidationTestModelAdmin(ModelAdmin):
575 575
         class ValidationTestModelAdmin(ModelAdmin):
576 576
             fieldsets = ({},)
577 577
 
578  
-        self.assertRaisesRegexp(
  578
+        six.assertRaisesRegex(self,
579 579
             ImproperlyConfigured,
580 580
             "'ValidationTestModelAdmin.fieldsets\[0\]' must be a list or tuple.",
581 581
             validate,
@@ -586,7 +586,7 @@ class ValidationTestModelAdmin(ModelAdmin):
586 586
         class ValidationTestModelAdmin(ModelAdmin):
587 587
             fieldsets = ((),)
588 588
 
589  
-        self.assertRaisesRegexp(
  589
+        six.assertRaisesRegex(self,
590 590
             ImproperlyConfigured,
591 591
             "'ValidationTestModelAdmin.fieldsets\[0\]' does not have exactly two elements.",
592 592
             validate,
@@ -597,7 +597,7 @@ class ValidationTestModelAdmin(ModelAdmin):
597 597
         class ValidationTestModelAdmin(ModelAdmin):
598 598
             fieldsets = (("General", ()),)
599 599
 
600  
-        self.assertRaisesRegexp(
  600
+        six.assertRaisesRegex(self,
601 601
             ImproperlyConfigured,
602 602
             "'ValidationTestModelAdmin.fieldsets\[0\]\[1\]' must be a dictionary.",
603 603
             validate,
@@ -608,7 +608,7 @@ class ValidationTestModelAdmin(ModelAdmin):
608 608
         class ValidationTestModelAdmin(ModelAdmin):
609 609
             fieldsets = (("General", {}),)
610 610
 
611  
-        self.assertRaisesRegexp(
  611
+        six.assertRaisesRegex(self,
612 612
             ImproperlyConfigured,
613 613
             "'fields' key is required in ValidationTestModelAdmin.fieldsets\[0\]\[1\] field options dict.",
614 614
             validate,
@@ -619,7 +619,7 @@ class ValidationTestModelAdmin(ModelAdmin):
619 619
         class ValidationTestModelAdmin(ModelAdmin):
620 620
             fieldsets = (("General", {"fields": ("non_existent_field",)}),)
621 621
 
622  
-        self.assertRaisesRegexp(
  622
+        six.assertRaisesRegex(self,
623 623
             ImproperlyConfigured,
624 624
             "'ValidationTestModelAdmin.fieldsets\[0\]\[1\]\['fields'\]' refers to field 'non_existent_field' that is missing from the form.",
625 625
             validate,
@@ -636,7 +636,7 @@ class ValidationTestModelAdmin(ModelAdmin):
636 636
             fieldsets = (("General", {"fields": ("name",)}),)
637 637
             fields = ["name",]
638 638
 
639  
-        self.assertRaisesRegexp(
  639
+        six.assertRaisesRegex(self,
640 640
             ImproperlyConfigured,
641 641
             "Both fieldsets and fields are specified in ValidationTestModelAdmin.",
642 642
             validate,
@@ -647,7 +647,7 @@ class ValidationTestModelAdmin(ModelAdmin):
647 647
         class ValidationTestModelAdmin(ModelAdmin):
648 648
             fieldsets = [(None, {'fields': ['name', 'name']})]
649 649
 
650  
-        self.assertRaisesRegexp(
  650
+        six.assertRaisesRegex(self,
651 651
             ImproperlyConfigured,
652 652
             "There are duplicate field\(s\) in ValidationTestModelAdmin.fieldsets",
653 653
             validate,
@@ -658,7 +658,7 @@ class ValidationTestModelAdmin(ModelAdmin):
658 658
         class ValidationTestModelAdmin(ModelAdmin):
659 659
             fields = ["name", "name"]
660 660
 
661  
-        self.assertRaisesRegexp(
  661
+        six.assertRaisesRegex(self,
662 662
             ImproperlyConfigured,
663 663
             "There are duplicate field\(s\) in ValidationTestModelAdmin.fields",
664 664
             validate,
@@ -674,7 +674,7 @@ class FakeForm(object):
674 674
         class ValidationTestModelAdmin(ModelAdmin):
675 675
             form = FakeForm
676 676
 
677  
-        self.assertRaisesRegexp(
  677
+        six.assertRaisesRegex(self,
678 678
             ImproperlyConfigured,
679 679
             "ValidationTestModelAdmin.form does not inherit from BaseModelForm.",
680 680
             validate,
@@ -692,7 +692,7 @@ class BandAdmin(ModelAdmin):
692 692
                 }),
693 693
             )
694 694
 
695  
-        self.assertRaisesRegexp(
  695
+        six.assertRaisesRegex(self,
696 696
             ImproperlyConfigured,
697 697
             "'BandAdmin.fieldsets\[0\]\[1\]\['fields'\]' refers to field 'non_existent_field' that is missing from the form.",
698 698
             validate,
@@ -722,7 +722,7 @@ class BandAdmin(ModelAdmin):
722 722
                 }),
723 723
             )
724 724
 
725  
-        self.assertRaisesRegexp(
  725
+        six.assertRaisesRegex(self,
726 726
             ImproperlyConfigured,
727 727
             "'BandAdmin.fieldsets\[0]\[1\]\['fields'\]' refers to field 'non_existent_field' that is missing from the form.",
728 728
             validate,
@@ -752,7 +752,7 @@ def test_filter_vertical_validation(self):
752 752
         class ValidationTestModelAdmin(ModelAdmin):
753 753
             filter_vertical = 10
754 754
 
755  
-        self.assertRaisesRegexp(
  755
+        six.assertRaisesRegex(self,
756 756
             ImproperlyConfigured,
757 757
             "'ValidationTestModelAdmin.filter_vertical' must be a list or tuple.",
758 758
             validate,
@@ -763,7 +763,7 @@ class ValidationTestModelAdmin(ModelAdmin):
763 763
         class ValidationTestModelAdmin(ModelAdmin):
764 764
             filter_vertical = ("non_existent_field",)
765 765
 
766  
-        self.assertRaisesRegexp(
  766
+        six.assertRaisesRegex(self,
767 767
             ImproperlyConfigured,
768 768
             "'ValidationTestModelAdmin.filter_vertical' refers to field 'non_existent_field' that is missing from model 'modeladmin.ValidationTestModel'.",
769 769
             validate,
@@ -774,7 +774,7 @@ class ValidationTestModelAdmin(ModelAdmin):
774 774
         class ValidationTestModelAdmin(ModelAdmin):
775 775
             filter_vertical = ("name",)
776 776
 
777  
-        self.assertRaisesRegexp(
  777
+        six.assertRaisesRegex(self,
778 778
             ImproperlyConfigured,
779 779
             "'ValidationTestModelAdmin.filter_vertical\[0\]' must be a ManyToManyField.",
780 780
             validate,
@@ -792,7 +792,7 @@ def test_filter_horizontal_validation(self):
792 792
         class ValidationTestModelAdmin(ModelAdmin):
793 793
             filter_horizontal = 10
794 794
 
795  
-        self.assertRaisesRegexp(
  795
+        six.assertRaisesRegex(self,
796 796
             ImproperlyConfigured,
797 797
             "'ValidationTestModelAdmin.filter_horizontal' must be a list or tuple.",
798 798
             validate,
@@ -803,7 +803,7 @@ class ValidationTestModelAdmin(ModelAdmin):
803 803
         class ValidationTestModelAdmin(ModelAdmin):
804 804
             filter_horizontal = ("non_existent_field",)
805 805
 
806  
-        self.assertRaisesRegexp(
  806
+        six.assertRaisesRegex(self,
807 807
             ImproperlyConfigured,
808 808
             "'ValidationTestModelAdmin.filter_horizontal' refers to field 'non_existent_field' that is missing from model 'modeladmin.ValidationTestModel'.",
809 809
             validate,
@@ -814,7 +814,7 @@ class ValidationTestModelAdmin(ModelAdmin):
814 814
         class ValidationTestModelAdmin(ModelAdmin):
815 815
             filter_horizontal = ("name",)
816 816
 
817  
-        self.assertRaisesRegexp(
  817
+        six.assertRaisesRegex(self,
818 818
             ImproperlyConfigured,
819 819
             "'ValidationTestModelAdmin.filter_horizontal\[0\]' must be a ManyToManyField.",
820 820
             validate,
@@ -832,7 +832,7 @@ def test_radio_fields_validation(self):
832 832
         class ValidationTestModelAdmin(ModelAdmin):
833 833
             radio_fields = ()
834 834
 
835  
-        self.assertRaisesRegexp(
  835
+        six.assertRaisesRegex(self,
836 836
             ImproperlyConfigured,
837 837
             "'ValidationTestModelAdmin.radio_fields' must be a dictionary.",
838 838
             validate,
@@ -843,7 +843,7 @@ class ValidationTestModelAdmin(ModelAdmin):
843 843
         class ValidationTestModelAdmin(ModelAdmin):
844 844
             radio_fields = {"non_existent_field": None}
845 845
 
846  
-        self.assertRaisesRegexp(
  846
+        six.assertRaisesRegex(self,
847 847
             ImproperlyConfigured,
848 848
             "'ValidationTestModelAdmin.radio_fields' refers to field 'non_existent_field' that is missing from model 'modeladmin.ValidationTestModel'.",
849 849
             validate,
@@ -854,7 +854,7 @@ class ValidationTestModelAdmin(ModelAdmin):
854 854
         class ValidationTestModelAdmin(ModelAdmin):
855 855
             radio_fields = {"name": None}
856 856
 
857  
-        self.assertRaisesRegexp(
  857
+        six.assertRaisesRegex(self,
858 858
             ImproperlyConfigured,
859 859
             "'ValidationTestModelAdmin.radio_fields\['name'\]' is neither an instance of ForeignKey nor does have choices set.",
860 860
             validate,
@@ -865,7 +865,7 @@ class ValidationTestModelAdmin(ModelAdmin):
865 865
         class ValidationTestModelAdmin(ModelAdmin):
866 866
             radio_fields = {"state": None}
867 867
 
868  
-        self.assertRaisesRegexp(
  868
+        six.assertRaisesRegex(self,
869 869
             ImproperlyConfigured,
870 870
             "'ValidationTestModelAdmin.radio_fields\['state'\]' is neither admin.HORIZONTAL nor admin.VERTICAL.",
871 871
             validate,
@@ -883,7 +883,7 @@ def test_prepopulated_fields_validation(self):
883 883
         class ValidationTestModelAdmin(ModelAdmin):
884 884
             prepopulated_fields = ()
885 885
 
886  
-        self.assertRaisesRegexp(
  886
+        six.assertRaisesRegex(self,
887 887
             ImproperlyConfigured,
888 888
             "'ValidationTestModelAdmin.prepopulated_fields' must be a dictionary.",
889 889
             validate,
@@ -894,7 +894,7 @@ class ValidationTestModelAdmin(ModelAdmin):
894 894
         class ValidationTestModelAdmin(ModelAdmin):
895 895
             prepopulated_fields = {"non_existent_field": None}
896 896
 
897  
-        self.assertRaisesRegexp(
  897
+        six.assertRaisesRegex(self,
898 898
             ImproperlyConfigured,
899 899
             "'ValidationTestModelAdmin.prepopulated_fields' refers to field 'non_existent_field' that is missing from model 'modeladmin.ValidationTestModel'.",
900 900
             validate,
@@ -905,7 +905,7 @@ class ValidationTestModelAdmin(ModelAdmin):
905 905
         class ValidationTestModelAdmin(ModelAdmin):
906 906
             prepopulated_fields = {"slug": ("non_existent_field",)}
907 907
 
908  
-        self.assertRaisesRegexp(
  908
+        six.assertRaisesRegex(self,
909 909
             ImproperlyConfigured,
910 910
             "'ValidationTestModelAdmin.prepopulated_fields\['slug'\]\[0\]' refers to field 'non_existent_field' that is missing from model 'modeladmin.ValidationTestModel'.",
911 911
             validate,
@@ -916,7 +916,7 @@ class ValidationTestModelAdmin(ModelAdmin):
916 916
         class ValidationTestModelAdmin(ModelAdmin):
917 917
             prepopulated_fields = {"users": ("name",)}
918 918
 
919  
-        self.assertRaisesRegexp(
  919
+        six.assertRaisesRegex(self,
920 920
             ImproperlyConfigured,
921 921
             "'ValidationTestModelAdmin.prepopulated_fields\['users'\]' is either a DateTimeField, ForeignKey or ManyToManyField. This isn't allowed.",
922 922
             validate,
@@ -934,7 +934,7 @@ def test_list_display_validation(self):
934 934
         class ValidationTestModelAdmin(ModelAdmin):
935 935
             list_display = 10
936 936
 
937  
-        self.assertRaisesRegexp(
  937
+        six.assertRaisesRegex(self,