Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit 9e190e1c82a287c88636f8fffea125224526f0e5 2 parents 9ce5890 + 292322f
Nick Martini nmartini authored
Showing with 213 additions and 196 deletions.
  1. +6 −5 django/contrib/auth/tests/models.py
  2. +1 −1  django/test/testcases.py
  3. +7 −0 django/utils/six.py
  4. +14 −14 tests/modeltests/basic/tests.py
  5. +4 −3 tests/modeltests/empty/tests.py
  6. +17 −17 tests/modeltests/fixtures/tests.py
  7. +2 −1  tests/modeltests/many_to_many/tests.py
  8. +1 −1  tests/modeltests/many_to_one/tests.py
  9. +2 −1  tests/modeltests/update_only_fields/tests.py
  10. +2 −1  tests/modeltests/validation/test_error_messages.py
  11. +4 −3 tests/regressiontests/admin_filters/tests.py
  12. +3 −3 tests/regressiontests/admin_scripts/tests.py
  13. +1 −1  tests/regressiontests/backends/tests.py
  14. +3 −4 tests/regressiontests/cache/tests.py
  15. +1 −1  tests/regressiontests/file_storage/tests.py
  16. +9 −8 tests/regressiontests/fixtures_regress/tests.py
  17. +3 −3 tests/regressiontests/forms/tests/fields.py
  18. +1 −1  tests/regressiontests/i18n/commands/compilation.py
  19. +2 −2 tests/regressiontests/inline_formsets/tests.py
  20. +17 −15 tests/regressiontests/localflavor/tr/tests.py
  21. +3 −2 tests/regressiontests/m2m_regress/tests.py
  22. +3 −2 tests/regressiontests/many_to_one_regress/tests.py
  23. +64 −64 tests/regressiontests/modeladmin/tests.py
  24. +1 −1  tests/regressiontests/staticfiles_tests/tests.py
  25. +26 −25 tests/regressiontests/templates/custom.py
  26. +6 −6 tests/regressiontests/templates/loaders.py
  27. +3 −3 tests/regressiontests/test_utils/tests.py
  28. +4 −4 tests/regressiontests/urlpatterns_reverse/tests.py
  29. +3 −4 tests/regressiontests/wsgi/tests.py
11 django/contrib/auth/tests/models.py
View
@@ -1,8 +1,9 @@
from django.conf import settings
+from django.contrib.auth.models import (Group, User, SiteProfileNotAvailable,
+ UserManager)
from django.test import TestCase
from django.test.utils import override_settings
-from django.contrib.auth.models import (Group, User,
- SiteProfileNotAvailable, UserManager)
+from django.utils import six
@override_settings(USE_TZ=False, AUTH_PROFILE_MODULE='')
@@ -13,19 +14,19 @@ def test_site_profile_not_available(self):
# calling get_profile without AUTH_PROFILE_MODULE set
del settings.AUTH_PROFILE_MODULE
- with self.assertRaisesRegexp(SiteProfileNotAvailable,
+ with six.assertRaisesRegex(self, SiteProfileNotAvailable,
"You need to set AUTH_PROFILE_MODULE in your project"):
user.get_profile()
# Bad syntax in AUTH_PROFILE_MODULE:
settings.AUTH_PROFILE_MODULE = 'foobar'
- with self.assertRaisesRegexp(SiteProfileNotAvailable,
+ with six.assertRaisesRegex(self, SiteProfileNotAvailable,
"app_label and model_name should be separated by a dot"):
user.get_profile()
# module that doesn't exist
settings.AUTH_PROFILE_MODULE = 'foo.bar'
- with self.assertRaisesRegexp(SiteProfileNotAvailable,
+ with six.assertRaisesRegex(self, SiteProfileNotAvailable,
"Unable to load the profile model"):
user.get_profile()
2  django/test/testcases.py
View
@@ -358,7 +358,7 @@ def assertRaisesMessage(self, expected_exception, expected_message,
args: Extra args.
kwargs: Extra kwargs.
"""
- return self.assertRaisesRegexp(expected_exception,
+ return six.assertRaisesRegex(self, expected_exception,
re.escape(expected_message), callable_obj, *args, **kwargs)
def assertFieldOutput(self, fieldclass, valid, invalid, field_args=None,
7 django/utils/six.py
View
@@ -370,13 +370,20 @@ def with_metaclass(meta, base=object):
if PY3:
_iterlists = "lists"
+ _assertRaisesRegex = "assertRaisesRegex"
else:
_iterlists = "iterlists"
+ _assertRaisesRegex = "assertRaisesRegexp"
+
def iterlists(d):
"""Return an iterator over the values of a MultiValueDict."""
return getattr(d, _iterlists)()
+def assertRaisesRegex(self, *args, **kwargs):
+ return getattr(self, _assertRaisesRegex)(*args, **kwargs)
+
+
add_move(MovedModule("_dummy_thread", "dummy_thread"))
add_move(MovedModule("_thread", "thread"))
28 tests/modeltests/basic/tests.py
View
@@ -5,7 +5,7 @@
from django.core.exceptions import ObjectDoesNotExist
from django.db.models.fields import Field, FieldDoesNotExist
from django.test import TestCase, skipIfDBFeature, skipUnlessDBFeature
-from django.utils.six import PY3
+from django.utils import six
from django.utils.translation import ugettext_lazy
from .models import Article
@@ -82,7 +82,7 @@ def test_lookup(self):
# Django raises an Article.DoesNotExist exception for get() if the
# parameters don't match any object.
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ObjectDoesNotExist,
"Article matching query does not exist. Lookup parameters were "
"{'id__exact': 2000}",
@@ -91,14 +91,14 @@ def test_lookup(self):
)
# To avoid dict-ordering related errors check only one lookup
# in single assert.
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ObjectDoesNotExist,
".*'pub_date__year': 2005.*",
Article.objects.get,
pub_date__year=2005,
pub_date__month=8,
)
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ObjectDoesNotExist,
".*'pub_date__month': 8.*",
Article.objects.get,
@@ -106,7 +106,7 @@ def test_lookup(self):
pub_date__month=8,
)
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ObjectDoesNotExist,
"Article matching query does not exist. Lookup parameters were "
"{'pub_date__week_day': 6}",
@@ -168,7 +168,7 @@ def test_object_creation(self):
self.assertEqual(a4.headline, 'Fourth article')
# Don't use invalid keyword arguments.
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
TypeError,
"'foo' is an invalid keyword argument for this function",
Article,
@@ -259,13 +259,13 @@ def test_object_creation(self):
"datetime.datetime(2005, 7, 28, 0, 0)"])
# dates() requires valid arguments.
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
TypeError,
"dates\(\) takes at least 3 arguments \(1 given\)",
Article.objects.dates,
)
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
FieldDoesNotExist,
"Article has no field named 'invalid_field'",
Article.objects.dates,
@@ -273,7 +273,7 @@ def test_object_creation(self):
"year",
)
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
AssertionError,
"'kind' must be one of 'year', 'month' or 'day'.",
Article.objects.dates,
@@ -281,7 +281,7 @@ def test_object_creation(self):
"bad_kind",
)
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
AssertionError,
"'order' must be either 'ASC' or 'DESC'.",
Article.objects.dates,
@@ -323,7 +323,7 @@ def test_object_creation(self):
"<Article: Third article>"])
# Slicing works with longs (Python 2 only -- Python 3 doesn't have longs).
- if not PY3:
+ if not six.PY3:
self.assertEqual(Article.objects.all()[long(0)], a)
self.assertQuerysetEqual(Article.objects.all()[long(1):long(3)],
["<Article: Second article>", "<Article: Third article>"])
@@ -369,14 +369,14 @@ def test_object_creation(self):
"<Article: Updated article 8>"])
# Also, once you have sliced you can't filter, re-order or combine
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
AssertionError,
"Cannot filter a query once a slice has been taken.",
Article.objects.all()[0:5].filter,
id=a.id,
)
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
AssertionError,
"Cannot reorder a query once a slice has been taken.",
Article.objects.all()[0:5].order_by,
@@ -411,7 +411,7 @@ def test_object_creation(self):
# An Article instance doesn't have access to the "objects" attribute.
# That's only available on the class.
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
AttributeError,
"Manager isn't accessible via Article instances",
getattr,
7 tests/modeltests/empty/tests.py
View
@@ -1,10 +1,10 @@
from __future__ import absolute_import
-from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.db.models.loading import get_app
from django.test import TestCase
from django.test.utils import override_settings
+from django.utils import six
from .models import Empty
@@ -14,12 +14,13 @@ def test_empty(self):
m = Empty()
self.assertEqual(m.id, None)
m.save()
- m2 = Empty.objects.create()
+ Empty.objects.create()
self.assertEqual(len(Empty.objects.all()), 2)
self.assertTrue(m.id is not None)
existing = Empty(m.id)
existing.save()
+
class NoModelTests(TestCase):
"""
Test for #7198 to ensure that the proper error message is raised
@@ -32,6 +33,6 @@ class NoModelTests(TestCase):
"""
@override_settings(INSTALLED_APPS=("modeltests.empty.no_models",))
def test_no_models(self):
- with self.assertRaisesRegexp(ImproperlyConfigured,
+ with six.assertRaisesRegex(self, ImproperlyConfigured,
'App with label no_models is missing a models.py module.'):
get_app('no_models')
34 tests/modeltests/fixtures/tests.py
View
@@ -4,7 +4,7 @@
from django.core import management
from django.db import connection, IntegrityError
from django.test import TestCase, TransactionTestCase, skipUnlessDBFeature
-from django.utils.six import StringIO
+from django.utils import six
from .models import Article, Book, Spy, Tag, Visa
@@ -21,16 +21,17 @@ def testClassFixtures(self):
'<Article: Poker has no place on ESPN>',
])
+
class FixtureLoadingTests(TestCase):
def _dumpdata_assert(self, args, output, format='json', natural_keys=False,
use_base_manager=False, exclude_list=[]):
- new_io = StringIO()
- management.call_command('dumpdata', *args, **{'format':format,
- 'stdout':new_io,
- 'stderr':new_io,
- 'use_natural_keys':natural_keys,
- 'use_base_manager':use_base_manager,
+ new_io = six.StringIO()
+ management.call_command('dumpdata', *args, **{'format': format,
+ 'stdout': new_io,
+ 'stderr': new_io,
+ 'use_natural_keys': natural_keys,
+ 'use_base_manager': use_base_manager,
'exclude': exclude_list})
command_output = new_io.getvalue().strip()
self.assertEqual(command_output, output)
@@ -42,8 +43,6 @@ def test_initial_data(self):
])
def test_loading_and_dumping(self):
- new_io = StringIO()
-
Site.objects.all().delete()
# Load fixture 1. Single JSON file, with two objects.
management.call_command('loaddata', 'fixture1.json', verbosity=0, commit=False)
@@ -184,12 +183,12 @@ def test_dumpdata_with_excludes(self):
exclude_list=['fixtures.Article', 'fixtures.Book', 'sites'])
# Excluding a bogus app should throw an error
- with self.assertRaisesRegexp(management.CommandError,
+ with six.assertRaisesRegex(self, management.CommandError,
"Unknown app in excludes: foo_app"):
self._dumpdata_assert(['fixtures', 'sites'], '', exclude_list=['foo_app'])
# Excluding a bogus model should throw an error
- with self.assertRaisesRegexp(management.CommandError,
+ with six.assertRaisesRegex(self, management.CommandError,
"Unknown model in excludes: fixtures.FooModel"):
self._dumpdata_assert(['fixtures', 'sites'], '', exclude_list=['fixtures.FooModel'])
@@ -199,7 +198,7 @@ def test_dumpdata_with_filtering_manager(self):
self.assertQuerysetEqual(Spy.objects.all(),
['<Spy: Paul>'])
# Use the default manager
- self._dumpdata_assert(['fixtures.Spy'],'[{"pk": %d, "model": "fixtures.spy", "fields": {"cover_blown": false}}]' % spy1.pk)
+ self._dumpdata_assert(['fixtures.Spy'], '[{"pk": %d, "model": "fixtures.spy", "fields": {"cover_blown": false}}]' % spy1.pk)
# Dump using Django's base manager. Should return all objects,
# even those normally filtered by the manager
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):
def test_ambiguous_compressed_fixture(self):
# The name "fixture5" is ambigous, so loading it will raise an error
- with self.assertRaisesRegexp(management.CommandError,
+ with six.assertRaisesRegex(self, management.CommandError,
"Multiple fixtures named 'fixture5'"):
management.call_command('loaddata', 'fixture5', verbosity=0, commit=False)
@@ -251,7 +250,7 @@ def test_loaddata_error_message(self):
# is closed at the end of each test.
if connection.vendor == 'mysql':
connection.cursor().execute("SET sql_mode = 'TRADITIONAL'")
- with self.assertRaisesRegexp(IntegrityError,
+ with six.assertRaisesRegex(self, IntegrityError,
"Could not load fixtures.Article\(pk=1\): .*$"):
management.call_command('loaddata', 'invalid.json', verbosity=0, commit=False)
@@ -290,10 +289,11 @@ def test_output_formats(self):
self._dumpdata_assert(['fixtures'], """<?xml version="1.0" encoding="utf-8"?>
<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)
+
class FixtureTransactionTests(TransactionTestCase):
def _dumpdata_assert(self, args, output, format='json'):
- new_io = StringIO()
- management.call_command('dumpdata', *args, **{'format':format, 'stdout':new_io})
+ new_io = six.StringIO()
+ management.call_command('dumpdata', *args, **{'format': format, 'stdout': new_io})
command_output = new_io.getvalue().strip()
self.assertEqual(command_output, output)
@@ -308,7 +308,7 @@ def test_format_discovery(self):
# Try to load fixture 2 using format discovery; this will fail
# because there are two fixture2's in the fixtures directory
- with self.assertRaisesRegexp(management.CommandError,
+ with six.assertRaisesRegex(self, management.CommandError,
"Multiple fixtures named 'fixture2'"):
management.call_command('loaddata', 'fixture2', verbosity=0)
3  tests/modeltests/many_to_many/tests.py
View
@@ -1,6 +1,7 @@
from __future__ import absolute_import
from django.test import TestCase
+from django.utils import six
from .models import Article, Publication
@@ -52,7 +53,7 @@ def test_add(self):
])
# Adding an object of the wrong type raises TypeError
- with self.assertRaisesRegexp(TypeError, "'Publication' instance expected, got <Article.*"):
+ with six.assertRaisesRegex(self, TypeError, "'Publication' instance expected, got <Article.*"):
a6.publications.add(a5)
# Add a Publication directly via publications.add by using keyword arguments.
p4 = a6.publications.create(title='Highlights for Adults')
2  tests/modeltests/many_to_one/tests.py
View
@@ -70,7 +70,7 @@ def test_add(self):
self.assertQuerysetEqual(self.r2.article_set.all(), ["<Article: Paul's story>"])
# Adding an object of the wrong type raises TypeError.
- with self.assertRaisesRegexp(TypeError, "'Article' instance expected, got <Reporter.*"):
+ with six.assertRaisesRegex(self, TypeError, "'Article' instance expected, got <Reporter.*"):
self.r.article_set.add(self.r2)
self.assertQuerysetEqual(self.r.article_set.all(),
[
3  tests/modeltests/update_only_fields/tests.py
View
@@ -1,7 +1,8 @@
from __future__ import absolute_import
-from django.test import TestCase
from django.db.models.signals import pre_save, post_save
+from django.test import TestCase
+
from .models import Person, Employee, ProxyEmployee, Profile, Account
3  tests/modeltests/validation/test_error_messages.py
View
@@ -3,6 +3,7 @@
from django.core.exceptions import ValidationError
from django.db import models
+from django.utils import six
from django.utils.unittest import TestCase
@@ -18,7 +19,7 @@ def test_autofield_field_raises_error_message(self):
self._test_validation_messages(f, 'fõo',
["'fõo' value must be an integer."])
# primary_key must be True. Refs #12467.
- with self.assertRaisesRegexp(AssertionError,
+ with six.assertRaisesRegex(self, AssertionError,
"AutoFields must have primary_key=True."):
models.AutoField(primary_key=False)
7 tests/regressiontests/admin_filters/tests.py
View
@@ -9,7 +9,7 @@
from django.contrib.auth.models import User
from django.core.exceptions import ImproperlyConfigured
from django.test import TestCase, RequestFactory
-from django.test.utils import override_settings
+from django.test.utils import override_settings, six
from django.utils.encoding import force_text
from .models import Book, Department, Employee
@@ -18,6 +18,7 @@
def select_by(dictlist, key, value):
return [x for x in dictlist if x[key] == value][0]
+
class DecadeListFilter(SimpleListFilter):
def lookups(self, request, model_admin):
@@ -520,7 +521,7 @@ def test_listfilter_without_title(self):
"""
modeladmin = DecadeFilterBookAdminWithoutTitle(Book, site)
request = self.request_factory.get('/', {})
- self.assertRaisesRegexp(ImproperlyConfigured,
+ six.assertRaisesRegex(self, ImproperlyConfigured,
"The list filter 'DecadeListFilterWithoutTitle' does not specify a 'title'.",
self.get_changelist, request, Book, modeladmin)
@@ -530,7 +531,7 @@ def test_simplelistfilter_without_parameter(self):
"""
modeladmin = DecadeFilterBookAdminWithoutParameter(Book, site)
request = self.request_factory.get('/', {})
- self.assertRaisesRegexp(ImproperlyConfigured,
+ six.assertRaisesRegex(self, ImproperlyConfigured,
"The list filter 'DecadeListFilterWithoutParameter' does not specify a 'parameter_name'.",
self.get_changelist, request, Book, modeladmin)
6 tests/regressiontests/admin_scripts/tests.py
View
@@ -1576,7 +1576,6 @@ def test_custom_project_destination_missing(self):
self.assertOutput(err, "Destination directory '%s' does not exist, please create it first." % testproject_dir)
self.assertFalse(os.path.exists(testproject_dir))
-
def test_custom_project_template_with_non_ascii_templates(self):
"Ticket 18091: Make sure the startproject management command is able to render templates with non-ASCII content"
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):
self.assertNoOutput(err)
self.assertTrue(os.path.isdir(testproject_dir))
path = os.path.join(testproject_dir, 'ticket-18091-non-ascii-template.txt')
- self.assertEqual(codecs.open(path, 'r', 'utf-8').read(),
- 'Some non-ASCII text for testing ticket #18091:\nüäö €\n')
+ with codecs.open(path, 'r', 'utf-8') as f:
+ self.assertEqual(f.read(),
+ 'Some non-ASCII text for testing ticket #18091:\nüäö €\n')
2  tests/regressiontests/backends/tests.py
View
@@ -655,7 +655,7 @@ def runner2(other_thread_connection):
class BackendLoadingTests(TestCase):
def test_old_style_backends_raise_useful_exception(self):
- self.assertRaisesRegexp(ImproperlyConfigured,
+ six.assertRaisesRegex(self, ImproperlyConfigured,
"Try using django.db.backends.sqlite3 instead",
load_backend, 'sqlite3')
7 tests/regressiontests/cache/tests.py
View
@@ -15,7 +15,7 @@
from django.conf import settings
from django.core import management
-from django.core.cache import get_cache, DEFAULT_CACHE_ALIAS
+from django.core.cache import get_cache
from django.core.cache.backends.base import (CacheKeyWarning,
InvalidCacheBackendError)
from django.db import router
@@ -25,8 +25,7 @@
from django.template import Template
from django.template.response import TemplateResponse
from django.test import TestCase, TransactionTestCase, RequestFactory
-from django.test.utils import (get_warnings_state, restore_warnings_state,
- override_settings)
+from django.test.utils import override_settings, six
from django.utils import timezone, translation, unittest
from django.utils.cache import (patch_vary_headers, get_cache_key,
learn_cache_key, patch_cache_control, patch_response_headers)
@@ -821,7 +820,7 @@ def test_old_initialization(self):
self.perform_cull_test(50, 18)
def test_second_call_doesnt_crash(self):
- with self.assertRaisesRegexp(management.CommandError,
+ with six.assertRaisesRegex(self, management.CommandError,
"Cache table 'test cache table' could not be created"):
management.call_command(
'createcachetable',
2  tests/regressiontests/file_storage/tests.py
View
@@ -73,7 +73,7 @@ def test_get_nonexisting_storage_module(self):
get_storage_class raises an error if the requested module don't exist.
"""
# Error message may or may not be the fully qualified path.
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
('Error importing storage module django.core.files.non_existing_'
'storage: "No module named .*non_existing_storage"'),
17 tests/regressiontests/fixtures_regress/tests.py
View
@@ -13,6 +13,7 @@
from django.test import (TestCase, TransactionTestCase, skipIfDBFeature,
skipUnlessDBFeature)
from django.test.utils import override_settings
+from django.utils import six
from django.utils.six import PY3, StringIO
from .models import (Animal, Stuff, Absolute, Parent, Child, Article, Widget,
@@ -116,7 +117,7 @@ def test_unknown_format(self):
Test for ticket #4371 -- Loading data of an unknown format should fail
Validate that error conditions are caught correctly
"""
- with self.assertRaisesRegexp(management.CommandError,
+ with six.assertRaisesRegex(self, management.CommandError,
"Problem installing fixture 'bad_fixture1': "
"unkn is not a known serialization format."):
management.call_command(
@@ -131,7 +132,7 @@ def test_unimportable_serializer(self):
"""
Test that failing serializer import raises the proper error
"""
- with self.assertRaisesRegexp(ImportError,
+ with six.assertRaisesRegex(self, ImportError,
"No module named unexistent.path"):
management.call_command(
'loaddata',
@@ -146,7 +147,7 @@ def test_invalid_data(self):
using explicit filename.
Validate that error conditions are caught correctly
"""
- with self.assertRaisesRegexp(management.CommandError,
+ with six.assertRaisesRegex(self, management.CommandError,
"No fixture data found for 'bad_fixture2'. \(File format may be invalid.\)"):
management.call_command(
'loaddata',
@@ -161,7 +162,7 @@ def test_invalid_data_no_ext(self):
without file extension.
Validate that error conditions are caught correctly
"""
- with self.assertRaisesRegexp(management.CommandError,
+ with six.assertRaisesRegex(self, management.CommandError,
"No fixture data found for 'bad_fixture2'. \(File format may be invalid.\)"):
management.call_command(
'loaddata',
@@ -175,7 +176,7 @@ def test_empty(self):
Test for ticket #4371 -- Loading a fixture file with no data returns an error.
Validate that error conditions are caught correctly
"""
- with self.assertRaisesRegexp(management.CommandError,
+ with six.assertRaisesRegex(self, management.CommandError,
"No fixture data found for 'empty'. \(File format may be invalid.\)"):
management.call_command(
'loaddata',
@@ -188,7 +189,7 @@ def test_error_message(self):
"""
(Regression for #9011 - error message is correct)
"""
- with self.assertRaisesRegexp(management.CommandError,
+ with six.assertRaisesRegex(self, management.CommandError,
"^No fixture data found for 'bad_fixture2'. \(File format may be invalid.\)$"):
management.call_command(
'loaddata',
@@ -353,7 +354,7 @@ def test_loaddata_raises_error_when_fixture_has_invalid_foreign_key(self):
"""
Regression for #3615 - Ensure data with nonexistent child key references raises error
"""
- with self.assertRaisesRegexp(IntegrityError,
+ with six.assertRaisesRegex(self, IntegrityError,
"Problem installing fixture"):
management.call_command(
'loaddata',
@@ -385,7 +386,7 @@ def test_loaddata_no_fixture_specified(self):
"""
Regression for #7043 - Error is quickly reported when no fixtures is provided in the command line.
"""
- with self.assertRaisesRegexp(management.CommandError,
+ with six.assertRaisesRegex(self, management.CommandError,
"No database fixture specified. Please provide the path of "
"at least one fixture in the command line."):
management.call_command(
6 tests/regressiontests/forms/tests/fields.py
View
@@ -475,7 +475,7 @@ def test_regexfield_4(self):
def test_regexfield_5(self):
f = RegexField('^\d+$', min_length=5, max_length=10)
self.assertRaisesMessage(ValidationError, "'Ensure this value has at least 5 characters (it has 3).'", f.clean, '123')
- self.assertRaisesRegexp(ValidationError, "'Ensure this value has at least 5 characters \(it has 3\)\.', u?'Enter a valid value\.'", f.clean, 'abc')
+ six.assertRaisesRegex(self, ValidationError, "'Ensure this value has at least 5 characters \(it has 3\)\.', u?'Enter a valid value\.'", f.clean, 'abc')
self.assertEqual('12345', f.clean('12345'))
self.assertEqual('1234567890', f.clean('1234567890'))
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):
self.assertRaisesMessage(ValidationError, "'This field is required.'", f.clean, None)
self.assertRaisesMessage(ValidationError, "'This field is required.'", f.clean, '')
self.assertRaisesMessage(ValidationError, "'Enter a list of values.'", f.clean, 'hello')
- self.assertRaisesRegexp(ValidationError, "'Enter a valid date\.', u?'Enter a valid time\.'", f.clean, ['hello', 'there'])
+ six.assertRaisesRegex(self, ValidationError, "'Enter a valid date\.', u?'Enter a valid time\.'", f.clean, ['hello', 'there'])
self.assertRaisesMessage(ValidationError, "'Enter a valid time.'", f.clean, ['2006-01-10', 'there'])
self.assertRaisesMessage(ValidationError, "'Enter a valid date.'", f.clean, ['hello', '07:30'])
@@ -1049,7 +1049,7 @@ def test_splitdatetimefield_2(self):
self.assertEqual(None, f.clean(['']))
self.assertEqual(None, f.clean(['', '']))
self.assertRaisesMessage(ValidationError, "'Enter a list of values.'", f.clean, 'hello')
- self.assertRaisesRegexp(ValidationError, "'Enter a valid date\.', u?'Enter a valid time\.'", f.clean, ['hello', 'there'])
+ six.assertRaisesRegex(self, ValidationError, "'Enter a valid date\.', u?'Enter a valid time\.'", f.clean, ['hello', 'there'])
self.assertRaisesMessage(ValidationError, "'Enter a valid time.'", f.clean, ['2006-01-10', 'there'])
self.assertRaisesMessage(ValidationError, "'Enter a valid date.'", f.clean, ['hello', '07:30'])
self.assertRaisesMessage(ValidationError, "'Enter a valid time.'", f.clean, ['2006-01-10', ''])
2  tests/regressiontests/i18n/commands/compilation.py
View
@@ -24,7 +24,7 @@ class PoFileTests(MessageCompilationTests):
def test_bom_rejection(self):
os.chdir(test_dir)
- with self.assertRaisesRegexp(CommandError,
+ with six.assertRaisesRegex(self, CommandError,
"file has a BOM \(Byte Order Mark\)"):
call_command('compilemessages', locale=self.LOCALE, stderr=StringIO())
self.assertFalse(os.path.exists(self.MO_FILE))
4 tests/regressiontests/inline_formsets/tests.py
View
@@ -123,7 +123,7 @@ def test_exception_on_unspecified_foreign_key(self):
Child has two ForeignKeys to Parent, so if we don't specify which one
to use for the inline formset, we should get an exception.
"""
- self.assertRaisesRegexp(Exception,
+ six.assertRaisesRegex(self, Exception,
"<class 'regressiontests.inline_formsets.models.Child'> has more than 1 ForeignKey to <class 'regressiontests.inline_formsets.models.Parent'>",
inlineformset_factory, Parent, Child
)
@@ -143,7 +143,7 @@ def test_non_foreign_key_field(self):
If the field specified in fk_name is not a ForeignKey, we should get an
exception.
"""
- self.assertRaisesRegexp(Exception,
+ six.assertRaisesRegex(self, Exception,
"<class 'regressiontests.inline_formsets.models.Child'> has no field named 'test'",
inlineformset_factory, Parent, Child, fk_name='test'
)
32 tests/regressiontests/localflavor/tr/tests.py
View
@@ -2,29 +2,31 @@
from django.contrib.localflavor.tr import forms as trforms
from django.core.exceptions import ValidationError
+from django.utils import six
from django.utils.unittest import TestCase
+
class TRLocalFlavorTests(TestCase):
def test_TRPostalCodeField(self):
f = trforms.TRPostalCodeField()
self.assertEqual(f.clean("06531"), "06531")
self.assertEqual(f.clean("12345"), "12345")
- self.assertRaisesRegexp(ValidationError,
+ six.assertRaisesRegex(self, ValidationError,
"Enter a postal code in the format XXXXX.",
f.clean, "a1234")
- self.assertRaisesRegexp(ValidationError,
+ six.assertRaisesRegex(self, ValidationError,
"Enter a postal code in the format XXXXX.",
f.clean, "1234")
- self.assertRaisesRegexp(ValidationError,
+ six.assertRaisesRegex(self, ValidationError,
"Enter a postal code in the format XXXXX.",
f.clean, "82123")
- self.assertRaisesRegexp(ValidationError,
+ six.assertRaisesRegex(self, ValidationError,
"Enter a postal code in the format XXXXX.",
f.clean, "00123")
- self.assertRaisesRegexp(ValidationError,
+ six.assertRaisesRegex(self, ValidationError,
"Enter a postal code in the format XXXXX.",
f.clean, "123456")
- self.assertRaisesRegexp(ValidationError,
+ six.assertRaisesRegex(self, ValidationError,
"Enter a postal code in the format XXXXX.",
f.clean, "12 34")
self.assertRaises(ValidationError, f.clean, None)
@@ -40,34 +42,34 @@ def test_TRPhoneNumberField(self):
self.assertEqual(f.clean("+90 312 455 4567"), "3124554567")
self.assertEqual(f.clean("+90 312 455 45 67"), "3124554567")
self.assertEqual(f.clean("+90 (312) 4554567"), "3124554567")
- self.assertRaisesRegexp(ValidationError,
+ six.assertRaisesRegex(self, ValidationError,
'Phone numbers must be in 0XXX XXX XXXX format.',
f.clean, "1234 233 1234")
- self.assertRaisesRegexp(ValidationError,
+ six.assertRaisesRegex(self, ValidationError,
'Phone numbers must be in 0XXX XXX XXXX format.',
f.clean, "0312 233 12345")
- self.assertRaisesRegexp(ValidationError,
+ six.assertRaisesRegex(self, ValidationError,
'Phone numbers must be in 0XXX XXX XXXX format.',
f.clean, "0312 233 123")
- self.assertRaisesRegexp(ValidationError,
+ six.assertRaisesRegex(self, ValidationError,
'Phone numbers must be in 0XXX XXX XXXX format.',
f.clean, "0312 233 xxxx")
def test_TRIdentificationNumberField(self):
f = trforms.TRIdentificationNumberField()
self.assertEqual(f.clean("10000000146"), "10000000146")
- self.assertRaisesRegexp(ValidationError,
+ six.assertRaisesRegex(self, ValidationError,
'Enter a valid Turkish Identification number.',
f.clean, "10000000136")
- self.assertRaisesRegexp(ValidationError,
+ six.assertRaisesRegex(self, ValidationError,
'Enter a valid Turkish Identification number.',
f.clean, "10000000147")
- self.assertRaisesRegexp(ValidationError,
+ six.assertRaisesRegex(self, ValidationError,
'Turkish Identification number must be 11 digits.',
f.clean, "123456789")
- self.assertRaisesRegexp(ValidationError,
+ six.assertRaisesRegex(self, ValidationError,
'Enter a valid Turkish Identification number.',
f.clean, "1000000014x")
- self.assertRaisesRegexp(ValidationError,
+ six.assertRaisesRegex(self, ValidationError,
'Enter a valid Turkish Identification number.',
f.clean, "x0000000146")
5 tests/regressiontests/m2m_regress/tests.py
View
@@ -2,6 +2,7 @@
from django.core.exceptions import FieldError
from django.test import TestCase
+from django.utils import six
from .models import (SelfRefer, Tag, TagCollection, Entry, SelfReferChild,
SelfReferChildSibling, Worksheet)
@@ -35,7 +36,7 @@ def test_internal_related_name_not_in_error_msg(self):
# The secret internal related names for self-referential many-to-many
# fields shouldn't appear in the list when an error is made.
- self.assertRaisesRegexp(FieldError,
+ six.assertRaisesRegex(self, FieldError,
"Choices are: id, name, references, related, selfreferchild, selfreferchildsibling$",
lambda: SelfRefer.objects.filter(porcupine='fred')
)
@@ -70,7 +71,7 @@ def test_add_m2m_with_base_class(self):
t2 = Tag.objects.create(name='t2')
c1 = TagCollection.objects.create(name='c1')
- c1.tags = [t1,t2]
+ c1.tags = [t1, t2]
c1 = TagCollection.objects.get(name='c1')
self.assertQuerysetEqual(c1.tags.all(), ["<Tag: t1>", "<Tag: t2>"])
5 tests/regressiontests/many_to_one_regress/tests.py
View
@@ -2,8 +2,9 @@
from django.db import models
from django.test import TestCase
+from django.utils import six
-from .models import First, Second, Third, Parent, Child, Category, Record, Relation
+from .models import First, Third, Parent, Child, Category, Record, Relation
class ManyToOneRegressionTests(TestCase):
@@ -59,7 +60,7 @@ def test_fk_assignment_and_related_object_cache(self):
self.assertRaises(ValueError, Child.objects.create, name='xyzzy', parent=None)
# Trying to assign to unbound attribute raises AttributeError
- self.assertRaisesRegexp(AttributeError, "must be accessed via instance",
+ six.assertRaisesRegex(self, AttributeError, "must be accessed via instance",
Child.parent.__set__, None, p)
# Creation using keyword argument should cache the related object.
128 tests/regressiontests/modeladmin/tests.py
View
@@ -16,7 +16,7 @@
from django.forms.widgets import Select
from django.test import TestCase
from django.test.utils import str_prefix
-from django.utils import unittest
+from django.utils import unittest, six
from .models import Band, Concert, ValidationTestModel, ValidationTestInlineModel
@@ -506,7 +506,7 @@ class ValidationTestModelAdmin(ModelAdmin):
site = AdminSite()
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'ValidationTestModelAdmin.raw_id_fields' must be a list or tuple.",
site.register,
@@ -524,7 +524,7 @@ def test_raw_id_fields_validation(self):
class ValidationTestModelAdmin(ModelAdmin):
raw_id_fields = 10
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'ValidationTestModelAdmin.raw_id_fields' must be a list or tuple.",
validate,
@@ -535,7 +535,7 @@ class ValidationTestModelAdmin(ModelAdmin):
class ValidationTestModelAdmin(ModelAdmin):
raw_id_fields = ('non_existent_field',)
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'ValidationTestModelAdmin.raw_id_fields' refers to field 'non_existent_field' that is missing from model 'modeladmin.ValidationTestModel'.",
validate,
@@ -546,7 +546,7 @@ class ValidationTestModelAdmin(ModelAdmin):
class ValidationTestModelAdmin(ModelAdmin):
raw_id_fields = ('name',)
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'ValidationTestModelAdmin.raw_id_fields\[0\]', 'name' must be either a ForeignKey or ManyToManyField.",
validate,
@@ -564,7 +564,7 @@ def test_fieldsets_validation(self):
class ValidationTestModelAdmin(ModelAdmin):
fieldsets = 10
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'ValidationTestModelAdmin.fieldsets' must be a list or tuple.",
validate,
@@ -575,7 +575,7 @@ class ValidationTestModelAdmin(ModelAdmin):
class ValidationTestModelAdmin(ModelAdmin):
fieldsets = ({},)
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'ValidationTestModelAdmin.fieldsets\[0\]' must be a list or tuple.",
validate,
@@ -586,7 +586,7 @@ class ValidationTestModelAdmin(ModelAdmin):
class ValidationTestModelAdmin(ModelAdmin):
fieldsets = ((),)
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'ValidationTestModelAdmin.fieldsets\[0\]' does not have exactly two elements.",
validate,
@@ -597,7 +597,7 @@ class ValidationTestModelAdmin(ModelAdmin):
class ValidationTestModelAdmin(ModelAdmin):
fieldsets = (("General", ()),)
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'ValidationTestModelAdmin.fieldsets\[0\]\[1\]' must be a dictionary.",
validate,
@@ -608,7 +608,7 @@ class ValidationTestModelAdmin(ModelAdmin):
class ValidationTestModelAdmin(ModelAdmin):
fieldsets = (("General", {}),)
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'fields' key is required in ValidationTestModelAdmin.fieldsets\[0\]\[1\] field options dict.",
validate,
@@ -619,7 +619,7 @@ class ValidationTestModelAdmin(ModelAdmin):
class ValidationTestModelAdmin(ModelAdmin):
fieldsets = (("General", {"fields": ("non_existent_field",)}),)
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'ValidationTestModelAdmin.fieldsets\[0\]\[1\]\['fields'\]' refers to field 'non_existent_field' that is missing from the form.",
validate,
@@ -636,7 +636,7 @@ class ValidationTestModelAdmin(ModelAdmin):
fieldsets = (("General", {"fields": ("name",)}),)
fields = ["name",]
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"Both fieldsets and fields are specified in ValidationTestModelAdmin.",
validate,
@@ -647,7 +647,7 @@ class ValidationTestModelAdmin(ModelAdmin):
class ValidationTestModelAdmin(ModelAdmin):
fieldsets = [(None, {'fields': ['name', 'name']})]
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"There are duplicate field\(s\) in ValidationTestModelAdmin.fieldsets",
validate,
@@ -658,7 +658,7 @@ class ValidationTestModelAdmin(ModelAdmin):
class ValidationTestModelAdmin(ModelAdmin):
fields = ["name", "name"]
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"There are duplicate field\(s\) in ValidationTestModelAdmin.fields",
validate,
@@ -674,7 +674,7 @@ class FakeForm(object):
class ValidationTestModelAdmin(ModelAdmin):
form = FakeForm
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"ValidationTestModelAdmin.form does not inherit from BaseModelForm.",
validate,
@@ -692,7 +692,7 @@ class BandAdmin(ModelAdmin):
}),
)
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'BandAdmin.fieldsets\[0\]\[1\]\['fields'\]' refers to field 'non_existent_field' that is missing from the form.",
validate,
@@ -722,7 +722,7 @@ class BandAdmin(ModelAdmin):
}),
)
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'BandAdmin.fieldsets\[0]\[1\]\['fields'\]' refers to field 'non_existent_field' that is missing from the form.",
validate,
@@ -752,7 +752,7 @@ def test_filter_vertical_validation(self):
class ValidationTestModelAdmin(ModelAdmin):
filter_vertical = 10
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'ValidationTestModelAdmin.filter_vertical' must be a list or tuple.",
validate,
@@ -763,7 +763,7 @@ class ValidationTestModelAdmin(ModelAdmin):
class ValidationTestModelAdmin(ModelAdmin):
filter_vertical = ("non_existent_field",)
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'ValidationTestModelAdmin.filter_vertical' refers to field 'non_existent_field' that is missing from model 'modeladmin.ValidationTestModel'.",
validate,
@@ -774,7 +774,7 @@ class ValidationTestModelAdmin(ModelAdmin):
class ValidationTestModelAdmin(ModelAdmin):
filter_vertical = ("name",)
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'ValidationTestModelAdmin.filter_vertical\[0\]' must be a ManyToManyField.",
validate,
@@ -792,7 +792,7 @@ def test_filter_horizontal_validation(self):
class ValidationTestModelAdmin(ModelAdmin):
filter_horizontal = 10
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'ValidationTestModelAdmin.filter_horizontal' must be a list or tuple.",
validate,
@@ -803,7 +803,7 @@ class ValidationTestModelAdmin(ModelAdmin):
class ValidationTestModelAdmin(ModelAdmin):
filter_horizontal = ("non_existent_field",)
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'ValidationTestModelAdmin.filter_horizontal' refers to field 'non_existent_field' that is missing from model 'modeladmin.ValidationTestModel'.",
validate,
@@ -814,7 +814,7 @@ class ValidationTestModelAdmin(ModelAdmin):
class ValidationTestModelAdmin(ModelAdmin):
filter_horizontal = ("name",)
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'ValidationTestModelAdmin.filter_horizontal\[0\]' must be a ManyToManyField.",
validate,
@@ -832,7 +832,7 @@ def test_radio_fields_validation(self):
class ValidationTestModelAdmin(ModelAdmin):
radio_fields = ()
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'ValidationTestModelAdmin.radio_fields' must be a dictionary.",
validate,
@@ -843,7 +843,7 @@ class ValidationTestModelAdmin(ModelAdmin):
class ValidationTestModelAdmin(ModelAdmin):
radio_fields = {"non_existent_field": None}
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'ValidationTestModelAdmin.radio_fields' refers to field 'non_existent_field' that is missing from model 'modeladmin.ValidationTestModel'.",
validate,
@@ -854,7 +854,7 @@ class ValidationTestModelAdmin(ModelAdmin):
class ValidationTestModelAdmin(ModelAdmin):
radio_fields = {"name": None}
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'ValidationTestModelAdmin.radio_fields\['name'\]' is neither an instance of ForeignKey nor does have choices set.",
validate,
@@ -865,7 +865,7 @@ class ValidationTestModelAdmin(ModelAdmin):
class ValidationTestModelAdmin(ModelAdmin):
radio_fields = {"state": None}
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'ValidationTestModelAdmin.radio_fields\['state'\]' is neither admin.HORIZONTAL nor admin.VERTICAL.",
validate,
@@ -883,7 +883,7 @@ def test_prepopulated_fields_validation(self):
class ValidationTestModelAdmin(ModelAdmin):
prepopulated_fields = ()
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'ValidationTestModelAdmin.prepopulated_fields' must be a dictionary.",
validate,
@@ -894,7 +894,7 @@ class ValidationTestModelAdmin(ModelAdmin):
class ValidationTestModelAdmin(ModelAdmin):
prepopulated_fields = {"non_existent_field": None}
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'ValidationTestModelAdmin.prepopulated_fields' refers to field 'non_existent_field' that is missing from model 'modeladmin.ValidationTestModel'.",
validate,
@@ -905,7 +905,7 @@ class ValidationTestModelAdmin(ModelAdmin):
class ValidationTestModelAdmin(ModelAdmin):
prepopulated_fields = {"slug": ("non_existent_field",)}
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'ValidationTestModelAdmin.prepopulated_fields\['slug'\]\[0\]' refers to field 'non_existent_field' that is missing from model 'modeladmin.ValidationTestModel'.",
validate,
@@ -916,7 +916,7 @@ class ValidationTestModelAdmin(ModelAdmin):
class ValidationTestModelAdmin(ModelAdmin):
prepopulated_fields = {"users": ("name",)}
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'ValidationTestModelAdmin.prepopulated_fields\['users'\]' is either a DateTimeField, ForeignKey or ManyToManyField. This isn't allowed.",
validate,
@@ -934,7 +934,7 @@ def test_list_display_validation(self):
class ValidationTestModelAdmin(ModelAdmin):
list_display = 10
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'ValidationTestModelAdmin.list_display' must be a list or tuple.",
validate,
@@ -945,7 +945,7 @@ class ValidationTestModelAdmin(ModelAdmin):
class ValidationTestModelAdmin(ModelAdmin):
list_display = ('non_existent_field',)
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
str_prefix("ValidationTestModelAdmin.list_display\[0\], %(_)s'non_existent_field' is not a callable or an attribute of 'ValidationTestModelAdmin' or found in the model 'ValidationTestModel'."),
validate,
@@ -956,7 +956,7 @@ class ValidationTestModelAdmin(ModelAdmin):
class ValidationTestModelAdmin(ModelAdmin):
list_display = ('users',)
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'ValidationTestModelAdmin.list_display\[0\]', 'users' is a ManyToManyField which is not supported.",
validate,
@@ -979,7 +979,7 @@ def test_list_display_links_validation(self):
class ValidationTestModelAdmin(ModelAdmin):
list_display_links = 10
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'ValidationTestModelAdmin.list_display_links' must be a list or tuple.",
validate,
@@ -990,7 +990,7 @@ class ValidationTestModelAdmin(ModelAdmin):
class ValidationTestModelAdmin(ModelAdmin):
list_display_links = ('non_existent_field',)
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'ValidationTestModelAdmin.list_display_links\[0\]' refers to 'non_existent_field' which is not defined in 'list_display'.",
validate,
@@ -1001,7 +1001,7 @@ class ValidationTestModelAdmin(ModelAdmin):
class ValidationTestModelAdmin(ModelAdmin):
list_display_links = ('name',)
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'ValidationTestModelAdmin.list_display_links\[0\]' refers to 'name' which is not defined in 'list_display'.",
validate,
@@ -1025,7 +1025,7 @@ def test_list_filter_validation(self):
class ValidationTestModelAdmin(ModelAdmin):
list_filter = 10
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'ValidationTestModelAdmin.list_filter' must be a list or tuple.",
validate,
@@ -1036,7 +1036,7 @@ class ValidationTestModelAdmin(ModelAdmin):
class ValidationTestModelAdmin(ModelAdmin):
list_filter = ('non_existent_field',)
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'ValidationTestModelAdmin.list_filter\[0\]' refers to 'non_existent_field' which does not refer to a Field.",
validate,
@@ -1050,7 +1050,7 @@ class RandomClass(object):
class ValidationTestModelAdmin(ModelAdmin):
list_filter = (RandomClass,)
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'ValidationTestModelAdmin.list_filter\[0\]' is 'RandomClass' which is not a descendant of ListFilter.",
validate,
@@ -1061,7 +1061,7 @@ class ValidationTestModelAdmin(ModelAdmin):
class ValidationTestModelAdmin(ModelAdmin):
list_filter = (('is_active', RandomClass),)
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'ValidationTestModelAdmin.list_filter\[0\]\[1\]' is 'RandomClass' which is not of type FieldListFilter.",
validate,
@@ -1080,7 +1080,7 @@ def get_query_set(self, cl, qs):
class ValidationTestModelAdmin(ModelAdmin):
list_filter = (('is_active', AwesomeFilter),)
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'ValidationTestModelAdmin.list_filter\[0\]\[1\]' is 'AwesomeFilter' which is not of type FieldListFilter.",
validate,
@@ -1091,7 +1091,7 @@ class ValidationTestModelAdmin(ModelAdmin):
class ValidationTestModelAdmin(ModelAdmin):
list_filter = (BooleanFieldListFilter,)
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'ValidationTestModelAdmin.list_filter\[0\]' is 'BooleanFieldListFilter' which is of type FieldListFilter but is not associated with a field name.",
validate,
@@ -1111,7 +1111,7 @@ def test_list_per_page_validation(self):
class ValidationTestModelAdmin(ModelAdmin):
list_per_page = 'hello'
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'ValidationTestModelAdmin.list_per_page' should be a integer.",
validate,
@@ -1129,7 +1129,7 @@ def test_max_show_all_allowed_validation(self):
class ValidationTestModelAdmin(ModelAdmin):
list_max_show_all = 'hello'
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'ValidationTestModelAdmin.list_max_show_all' should be an integer.",
validate,
@@ -1147,7 +1147,7 @@ def test_search_fields_validation(self):
class ValidationTestModelAdmin(ModelAdmin):
search_fields = 10
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'ValidationTestModelAdmin.search_fields' must be a list or tuple.",
validate,
@@ -1160,7 +1160,7 @@ def test_date_hierarchy_validation(self):
class ValidationTestModelAdmin(ModelAdmin):
date_hierarchy = 'non_existent_field'
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'ValidationTestModelAdmin.date_hierarchy' refers to field 'non_existent_field' that is missing from model 'modeladmin.ValidationTestModel'.",
validate,
@@ -1171,7 +1171,7 @@ class ValidationTestModelAdmin(ModelAdmin):
class ValidationTestModelAdmin(ModelAdmin):
date_hierarchy = 'name'
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'ValidationTestModelAdmin.date_hierarchy is neither an instance of DateField nor DateTimeField.",
validate,
@@ -1189,7 +1189,7 @@ def test_ordering_validation(self):
class ValidationTestModelAdmin(ModelAdmin):
ordering = 10
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'ValidationTestModelAdmin.ordering' must be a list or tuple.",
validate,
@@ -1200,7 +1200,7 @@ class ValidationTestModelAdmin(ModelAdmin):
class ValidationTestModelAdmin(ModelAdmin):
ordering = ('non_existent_field',)
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'ValidationTestModelAdmin.ordering\[0\]' refers to field 'non_existent_field' that is missing from model 'modeladmin.ValidationTestModel'.",
validate,
@@ -1211,7 +1211,7 @@ class ValidationTestModelAdmin(ModelAdmin):
class ValidationTestModelAdmin(ModelAdmin):
ordering = ('?', 'name')
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'ValidationTestModelAdmin.ordering' has the random ordering marker '\?', but contains other fields as well. Please either remove '\?' or the other fields.",
validate,
@@ -1239,7 +1239,7 @@ def test_list_select_related_validation(self):
class ValidationTestModelAdmin(ModelAdmin):
list_select_related = 1
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'ValidationTestModelAdmin.list_select_related' should be a boolean.",
validate,
@@ -1257,7 +1257,7 @@ def test_save_as_validation(self):
class ValidationTestModelAdmin(ModelAdmin):
save_as = 1
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'ValidationTestModelAdmin.save_as' should be a boolean.",
validate,
@@ -1275,7 +1275,7 @@ def test_save_on_top_validation(self):
class ValidationTestModelAdmin(ModelAdmin):
save_on_top = 1
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'ValidationTestModelAdmin.save_on_top' should be a boolean.",
validate,
@@ -1293,7 +1293,7 @@ def test_inlines_validation(self):
class ValidationTestModelAdmin(ModelAdmin):
inlines = 10
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'ValidationTestModelAdmin.inlines' must be a list or tuple.",
validate,
@@ -1307,7 +1307,7 @@ class ValidationTestInline(object):
class ValidationTestModelAdmin(ModelAdmin):
inlines = [ValidationTestInline]
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'ValidationTestModelAdmin.inlines\[0\]' does not inherit from BaseModelAdmin.",
validate,
@@ -1321,7 +1321,7 @@ class ValidationTestInline(TabularInline):
class ValidationTestModelAdmin(ModelAdmin):
inlines = [ValidationTestInline]
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'model' is a required attribute of 'ValidationTestModelAdmin.inlines\[0\]'.",
validate,
@@ -1338,7 +1338,7 @@ class ValidationTestInline(TabularInline):
class ValidationTestModelAdmin(ModelAdmin):
inlines = [ValidationTestInline]
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'ValidationTestModelAdmin.inlines\[0\].model' does not inherit from models.Model.",
validate,
@@ -1363,7 +1363,7 @@ class ValidationTestInline(TabularInline):
class ValidationTestModelAdmin(ModelAdmin):
inlines = [ValidationTestInline]
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'ValidationTestInline.fields' must be a list or tuple.",
validate,
@@ -1378,7 +1378,7 @@ class ValidationTestInline(TabularInline):
class ValidationTestModelAdmin(ModelAdmin):
inlines = [ValidationTestInline]
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'ValidationTestInline.fields' refers to field 'non_existent_field' that is missing from the form.",
validate,
@@ -1395,7 +1395,7 @@ class ValidationTestInline(TabularInline):
class ValidationTestModelAdmin(ModelAdmin):
inlines = [ValidationTestInline]
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'ValidationTestInline.fk_name' refers to field 'non_existent_field' that is missing from model 'modeladmin.ValidationTestInlineModel'.",
validate,
@@ -1421,7 +1421,7 @@ class ValidationTestInline(TabularInline):
class ValidationTestModelAdmin(ModelAdmin):
inlines = [ValidationTestInline]
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'ValidationTestInline.extra' should be a integer.",
validate,
@@ -1447,7 +1447,7 @@ class ValidationTestInline(TabularInline):
class ValidationTestModelAdmin(ModelAdmin):
inlines = [ValidationTestInline]
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'ValidationTestInline.max_num' should be an integer or None \(default\).",
validate,
@@ -1476,7 +1476,7 @@ class ValidationTestInline(TabularInline):
class ValidationTestModelAdmin(ModelAdmin):
inlines = [ValidationTestInline]
- self.assertRaisesRegexp(
+ six.assertRaisesRegex(self,
ImproperlyConfigured,
"'ValidationTestInline.formset' does not inherit from BaseModelFormSet.",
validate,
2  tests/regressiontests/staticfiles_tests/tests.py
View
@@ -617,7 +617,7 @@ def setUp(self):
settings.DEBUG = False
def test_disabled_serving(self):
- self.assertRaisesRegexp(ImproperlyConfigured, 'The staticfiles view '
+ six.assertRaisesRegex(self, ImproperlyConfigured, 'The staticfiles view '
'can only be used in debug mode ', self._response, 'test.txt')
51 tests/regressiontests/templates/custom.py
View
@@ -1,6 +1,7 @@
from __future__ import absolute_import, unicode_literals
from django import template
+from django.utils import six
from django.utils.unittest import TestCase
from .templatetags import custom
@@ -51,7 +52,7 @@ def test_simple_tags(self):
t = template.Template('{% load custom %}{% simple_one_default one=99 two="hello" %}')
self.assertEqual(t.render(c), 'simple_one_default - Expected result: 99, hello')
- self.assertRaisesRegexp(template.TemplateSyntaxError,
+ six.assertRaisesRegex(self, template.TemplateSyntaxError,
"'simple_one_default' received unexpected keyword argument 'three'",
template.Template, '{% load custom %}{% simple_one_default 99 two="hello" three="foo" %}')
@@ -70,22 +71,22 @@ def test_simple_tags(self):
t = template.Template('{% load custom %}{% simple_only_unlimited_args 37 42 56 89 %}')
self.assertEqual(t.render(c), 'simple_only_unlimited_args - Expected result: 37, 42, 56, 89')
- self.assertRaisesRegexp(template.TemplateSyntaxError,
+ six.assertRaisesRegex(self, template.TemplateSyntaxError,
"'simple_two_params' received too many positional arguments",
template.Template, '{% load custom %}{% simple_two_params 37 42 56 %}')
- self.assertRaisesRegexp(template.TemplateSyntaxError,
+ six.assertRaisesRegex(self, template.TemplateSyntaxError,
"'simple_one_default' received too many positional arguments",
template.Template, '{% load custom %}{% simple_one_default 37 42 56 %}')
t = template.Template('{% load custom %}{% simple_unlimited_args_kwargs 37 40|add:2 56 eggs="scrambled" four=1|add:3 %}')
self.assertEqual(t.render(c), 'simple_unlimited_args_kwargs - Expected result: 37, 42, 56 / eggs=scrambled, four=4')
- self.assertRaisesRegexp(template.TemplateSyntaxError,
+ six.assertRaisesRegex(self, template.TemplateSyntaxError,
"'simple_unlimited_args_kwargs' received some positional argument\(s\) after some keyword argument\(s\)",
template.Template, '{% load custom %}{% simple_unlimited_args_kwargs 37 40|add:2 eggs="scrambled" 56 four=1|add:3 %}')
- self.assertRaisesRegexp(template.TemplateSyntaxError,
+ six.assertRaisesRegex(self, template.TemplateSyntaxError,
"'simple_unlimited_args_kwargs' received multiple values for keyword argument 'eggs'",
template.Template, '{% load custom %}{% simple_unlimited_args_kwargs 37 eggs="scrambled" eggs="scrambled" %}')
@@ -101,7 +102,7 @@ def test_simple_tag_registration(self):
def test_simple_tag_missing_context(self):
# The 'context' parameter must be present when takes_context is True
- self.assertRaisesRegexp(template.TemplateSyntaxError,
+ six.assertRaisesRegex(self, template.TemplateSyntaxError,
"'simple_tag_without_context_parameter' is decorated with takes_context=True so it must have a first argument of 'context'",
template.Template, '{% load custom %}{% simple_tag_without_context_parameter 123 %}')
@@ -135,7 +136,7 @@ def test_inclusion_tags(self):
t = template.Template('{% load custom %}{% inclusion_one_default one=99 two="hello" %}')
self.assertEqual(t.render(c), 'inclusion_one_default - Expected result: 99, hello\n')
- self.assertRaisesRegexp(template.TemplateSyntaxError,
+ six.assertRaisesRegex(self, template.TemplateSyntaxError,
"'inclusion_one_default' received unexpected keyword argument 'three'",
template.Template, '{% load custom %}{% inclusion_one_default 99 two="hello" three="foo" %}')
@@ -154,36 +155,36 @@ def test_inclusion_tags(self):
t = template.Template('{% load custom %}{% inclusion_only_unlimited_args 37 42 56 89 %}')
self.assertEqual(t.render(c), 'inclusion_only_unlimited_args - Expected result: 37, 42, 56, 89\n')
- self.assertRaisesRegexp(template.TemplateSyntaxError,
+ six.assertRaisesRegex(self, template.TemplateSyntaxError,
"'inclusion_two_params' received too many positional arguments",
template.Template, '{% load custom %}{% inclusion_two_params 37 42 56 %}')
- self.assertRaisesRegexp(template.TemplateSyntaxError,
+ six.assertRaisesRegex(self, template.TemplateSyntaxError,
"'inclusion_one_default' received too many positional arguments",
template.Template, '{% load custom %}{% inclusion_one_default 37 42 56 %}')
- self.assertRaisesRegexp(template.TemplateSyntaxError,
+ six.assertRaisesRegex(self, template.TemplateSyntaxError,
"'inclusion_one_default' did not receive value\(s\) for the argument\(s\): 'one'",
template.Template, '{% load custom %}{% inclusion_one_default %}')
- self.assertRaisesRegexp(template.TemplateSyntaxError,
+ six.assertRaisesRegex(self, template.TemplateSyntaxError,
"'inclusion_unlimited_args' did not receive value\(s\) for the argument\(s\): 'one'",
template.Template, '{% load custom %}{% inclusion_unlimited_args %}')
t = template.Template('{% load custom %}{% inclusion_unlimited_args_kwargs 37 40|add:2 56 eggs="scrambled" four=1|add:3 %}')
self.assertEqual(t.render(c), 'inclusion_unlimited_args_kwargs - Expected result: 37, 42, 56 / eggs=scrambled, four=4\n')
- self.assertRaisesRegexp(template.TemplateSyntaxError,
+ six.assertRaisesRegex(self, template.TemplateSyntaxError,
"'inclusion_unlimited_args_kwargs' received some positional argument\(s\) after some keyword argument\(s\)",
template.Template, '{% load custom %}{% inclusion_unlimited_args_kwargs 37 40|add:2 eggs="scrambled" 56 four=1|add:3 %}')
- self.assertRaisesRegexp(template.TemplateSyntaxError,
+ six.assertRaisesRegex(self, template.TemplateSyntaxError,
"'inclusion_unlimited_args_kwargs' received multiple values for keyword argument 'eggs'",
template.Template, '{% load custom %}{% inclusion_unlimited_args_kwargs 37 eggs="scrambled" eggs="scrambled" %}')
def test_include_tag_missing_context(self):
# The 'context' parameter must be present when takes_context is True
- self.assertRaisesRegexp(template.TemplateSyntaxError,
+ six.assertRaisesRegex(self, template.TemplateSyntaxError,
"'inclusion_tag_without_context_parameter' is decorated with takes_context=True so it must have a first argument of 'context'",
template.Template, '{% load custom %}{% inclusion_tag_without_context_parameter 123 %}')
@@ -296,7 +297,7 @@ def test_assignment_tags(self):
t = template.Template('{% load custom %}{% assignment_one_default one=99 two="hello" as var %}The result is: {{ var }}')
self.assertEqual(t.render(c), 'The result is: assignment_one_default - Expected result: 99, hello')
- self.assertRaisesRegexp(template.TemplateSyntaxError,
+ six.assertRaisesRegex(self, template.TemplateSyntaxError,
"'assignment_one_default' received unexpected keyword argument 'three'",
template.Template, '{% load custom %}{% assignment_one_default 99 two="hello" three="foo" as var %}')
@@ -315,42 +316,42 @@ def test_assignment_tags(self):
t = template.Template('{% load custom %}{% assignment_only_unlimited_args 37 42 56 89 as var %}The result is: {{ var }}')
self.assertEqual(t.render(c), 'The result is: assignment_only_unlimited_args - Expected result: 37, 42, 56, 89')
- self.assertRaisesRegexp(template.TemplateSyntaxError,
+ six.assertRaisesRegex(self, template.TemplateSyntaxError,
"'assignment_one_param' tag takes at least 2 arguments and the second last argument must be 'as'",
template.Template, '{% load custom %}{% assignment_one_param 37 %}The result is: {{ var }}')
- self.assertRaisesRegexp(template.TemplateSyntaxError,
+ six.assertRaisesRegex(self, template.TemplateSyntaxError,
"'assignment_one_param' tag takes at least 2 arguments and the second last argument must be 'as'",
template.Template, '{% load custom %}{% assignment_one_param 37 as %}The result is: {{ var }}')
- self.assertRaisesRegexp(template.TemplateSyntaxError,
+ six.assertRaisesRegex(self, template.TemplateSyntaxError,
"'assignment_one_param' tag takes at least 2 arguments and the second last argument must be 'as'",
template.Template, '{% load custom %}{% assignment_one_param 37 ass var %}The result is: {{ var }}')
- self.assertRaisesRegexp(template.TemplateSyntaxError,
+ six.assertRaisesRegex(self, template.TemplateSyntaxError,
"'assignment_two_params' received too many positional arguments",
template.Template, '{% load custom %}{% assignment_two_params 37 42 56 as var %}The result is: {{ var }}')
- self.assertRaisesRegexp(template.TemplateSyntaxError,
+ six.assertRaisesRegex(self, template.TemplateSyntaxError,
"'assignment_one_default' received too many positional arguments",
template.Template, '{% load custom %}{% assignment_one_default 37 42 56 as var %}The result is: {{ var }}')
- self.assertRaisesRegexp(template.TemplateSyntaxError,
+ six.assertRaisesRegex(self, template.TemplateSyntaxError,
"'assignment_one_default' did not receive value\(s\) for the argument\(s\): 'one'",
template.Template, '{% load custom %}{% assignment_one_default as var %}The result is: {{ var }}')
- self.assertRaisesRegexp(template.TemplateSyntaxError,
+ six.assertRaisesRegex(self, template.TemplateSyntaxError,
"'assignment_unlimited_args' did not receive value\(s\) for the argument\(s\): 'one'",
template.Template, '{% load custom %}{% assignment_unlimited_args as var %}The result is: {{ var }}')
t = template.Template('{% load custom %}{% assignment_unlimited_args_kwargs 37 40|add:2 56 eggs="scrambled" four=1|add:3 as var %}The result is: {{ var }}')
self.assertEqual(t.render(c), 'The result is: assignment_unlimited_args_kwargs - Expected result: 37, 42, 56 / eggs=scrambled, four=4')
- self.assertRaisesRegexp(template.TemplateSyntaxError,
+ six.assertRaisesRegex(self, template.TemplateSyntaxError,
"'assignment_unlimited_args_kwargs' received some positional argument\(s\) after some keyword argument\(s\)",
template.Template, '{% load custom %}{% assignment_unlimited_args_kwargs 37 40|add:2 eggs="scrambled" 56 four=1|add:3 as var %}The result is: {{ var }}')
- self.assertRaisesRegexp(template.TemplateSyntaxError,
+ six.assertRaisesRegex(self, template.TemplateSyntaxError,
"'assignment_unlimited_args_kwargs' received multiple values for keyword argument 'eggs'",
template.Template, '{% load custom %}{% assignment_unlimited_args_kwargs 37 eggs="scrambled" eggs="scrambled" as var %}The result is: {{ var }}')
@@ -371,6 +372,6 @@ def test_assignment_tag_registration(self):
def test_assignment_tag_missing_context(self):
# The 'context' parameter must be present when takes_context is True
- self.assertRaisesRegexp(template.TemplateSyntaxError,
+ six.assertRaisesRegex(self, template.TemplateSyntaxError,
"'assignment_tag_without_context_parameter' is decorated with takes_context=True so it must have a first argument of 'context'",
template.Template, '{% load custom %}{% assignment_tag_without_context_parameter 123 as var %}')
12 tests/regressiontests/templates/loaders.py
View
@@ -17,7 +17,7 @@
from django.template import TemplateDoesNotExist, Context
from django.template.loaders.eggs import Loader as EggLoader
from django.template import loader
-from django.utils import unittest
+from django.utils import unittest, six
from django.utils.six import StringIO
@@ -30,7 +30,7 @@ def __init__(self, module):
def _has(self, path):
return path in self.module._resources
- def _isdir(self,path):
+ def _isdir(self, path):
return False
def get_resource_stream(self, manager, resource_name):
@@ -61,8 +61,8 @@ def setUp(self):
self.empty_egg = create_egg("egg_empty", {})
self.egg_1 = create_egg("egg_1", {
- os.path.normcase('templates/y.html') : StringIO("y"),
- os.path.normcase('templates/x.txt') : StringIO("x"),
+ os.path.normcase('templates/y.html'): StringIO("y"),
+ os.path.normcase('templates/x.txt'): StringIO("x"),
})
self._old_installed_apps = settings.INSTALLED_APPS
settings.INSTALLED_APPS = []
@@ -144,12 +144,12 @@ def test_existing_context_kept_clean(self):
self.assertEqual(context['obj'], 'before')
def test_empty_list(self):
- self.assertRaisesRegexp(TemplateDoesNotExist,
+ six.assertRaisesRegex(self, TemplateDoesNotExist,
'No template names provided$',
loader.render_to_string, [])
def test_select_templates_from_empty_list(self):
- self.assertRaisesRegexp(TemplateDoesNotExist,
+ six.assertRaisesRegex(self, TemplateDoesNotExist,
'No template names provided$',
loader.select_template, [])
6 tests/regressiontests/test_utils/tests.py
View
@@ -137,15 +137,15 @@ def test_not_used(self):
pass
def test_error_message(self):
- with self.assertRaisesRegexp(AssertionError, r'^template_used/base\.html'):
+ with six.assertRaisesRegex(self, AssertionError, r'^template_used/base\.html'):
with self.assertTemplateUsed('template_used/base.html'):
pass
- with self.assertRaisesRegexp(AssertionError, r'^template_used/base\.html'):
+ with six.assertRaisesRegex(self, AssertionError, r'^template_used/base\.html'):
with self.assertTemplateUsed(template_name='template_used/base.html'):
pass
- with self.assertRaisesRegexp(AssertionError, r'^template_used/base\.html.*template_used/alternative\.html$'):
+ with six.assertRaisesRegex(self, AssertionError, r'^template_used/base\.html.*template_used/alternative\.html$'):
with self.assertTemplateUsed('template_used/base.html'):
render_to_string('template_used/alternative.html')
8 tests/regressiontests/urlpatterns_reverse/tests.py
View
@@ -4,6 +4,7 @@
from __future__ import absolute_import, unicode_literals
from django.conf import settings
+from django.contrib.auth.models import User
from django.core.exceptions import ImproperlyConfigured, ViewDoesNotExist
from django.core.urlresolvers import (reverse, resolve, get_callable,
get_resolver, NoReverseMatch, Resolver404, ResolverMatch, RegexURLResolver,
@@ -11,10 +12,9 @@
from django.http import HttpResponseRedirect, HttpResponsePermanentRedirect
from django.shortcuts import redirect
from django.test import TestCase
-from django.utils import unittest
-from django.contrib.auth.models import User
+from django.utils import unittest, six
-from . import urlconf_outer, urlconf_inner, middleware, views
+from . import urlconf_outer, middleware, views
resolve_test_data = (
@@ -535,7 +535,7 @@ class ViewLoadingTests(TestCase):
def test_view_loading(self):
# A missing view (identified by an AttributeError) should raise
# ViewDoesNotExist, ...
- self.assertRaisesRegexp(ViewDoesNotExist, ".*View does not exist in.*",
+ six.assertRaisesRegex(self, ViewDoesNotExist, ".*View does not exist in.*",
get_callable,
'regressiontests.urlpatterns_reverse.views.i_should_not_exist')
# ... but if the AttributeError is caused by something else don't
7 tests/regressiontests/wsgi/tests.py
View
@@ -6,8 +6,7 @@
from django.test import TestCase
from django.test.client import RequestFactory
from django.test.utils import override_settings
-from django.utils import six
-from django.utils import unittest
+from django.utils import six, unittest
class WSGITest(TestCase):
@@ -84,7 +83,7 @@ def mock_get_wsgi_app():
@override_settings(WSGI_APPLICATION="regressiontests.wsgi.noexist.app")
def test_bad_module(self):
- with self.assertRaisesRegexp(
+ with six.assertRaisesRegex(self,
ImproperlyConfigured,
r"^WSGI application 'regressiontests.wsgi.noexist.app' could not be loaded; could not import module 'regressiontests.wsgi.noexist':"):
@@ -93,7 +92,7 @@ def test_bad_module(self):
@override_settings(WSGI_APPLICATION="regressiontests.wsgi.wsgi.noexist")
def test_bad_name(self):
- with self.assertRaisesRegexp(
+ with six.assertRaisesRegex(self,
ImproperlyConfigured,
r"^WSGI application 'regressiontests.wsgi.wsgi.noexist' could not be loaded; can't find 'noexist' in module 'regressiontests.wsgi.wsgi':"):
Please sign in to comment.
Something went wrong with that request. Please try again.