summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/modeltests/basic/tests.py10
-rw-r--r--tests/modeltests/get_or_create/tests.py2
-rw-r--r--tests/modeltests/invalid_models/tests.py2
-rw-r--r--tests/modeltests/lookup/tests.py4
-rw-r--r--tests/modeltests/select_for_update/tests.py6
-rw-r--r--tests/modeltests/validation/models.py2
-rw-r--r--tests/modeltests/validation/test_error_messages.py32
-rw-r--r--tests/modeltests/validation/test_unique.py6
-rw-r--r--tests/regressiontests/app_loading/tests.py2
-rw-r--r--tests/regressiontests/backends/tests.py6
-rw-r--r--tests/regressiontests/file_uploads/tests.py12
-rw-r--r--tests/regressiontests/forms/tests/error_messages.py2
-rw-r--r--tests/regressiontests/forms/tests/validators.py2
-rw-r--r--tests/regressiontests/middleware/tests.py4
-rw-r--r--tests/regressiontests/middleware_exceptions/tests.py4
-rw-r--r--tests/regressiontests/model_fields/tests.py2
-rw-r--r--tests/regressiontests/model_forms_regress/tests.py2
-rw-r--r--tests/regressiontests/servers/tests.py2
-rw-r--r--tests/regressiontests/settings_tests/tests.py2
-rw-r--r--tests/regressiontests/templates/nodelist.py2
-rw-r--r--tests/regressiontests/templates/tests.py16
-rw-r--r--tests/regressiontests/test_client_regress/models.py100
-rw-r--r--tests/regressiontests/urlpatterns_reverse/tests.py4
23 files changed, 112 insertions, 114 deletions
diff --git a/tests/modeltests/basic/tests.py b/tests/modeltests/basic/tests.py
index 14d35cc644..fc1f593c13 100644
--- a/tests/modeltests/basic/tests.py
+++ b/tests/modeltests/basic/tests.py
@@ -384,9 +384,9 @@ class ModelTest(TestCase):
try:
Article.objects.all()[0:1] & Article.objects.all()[4:5]
self.fail('Should raise an AssertionError')
- except AssertionError, e:
+ except AssertionError as e:
self.assertEqual(str(e), "Cannot combine queries once a slice has been taken.")
- except Exception, e:
+ except Exception as e:
self.fail('Should raise an AssertionError, not %s' % e)
# Negative slices are not supported, due to database constraints.
@@ -394,15 +394,15 @@ class ModelTest(TestCase):
try:
Article.objects.all()[-1]
self.fail('Should raise an AssertionError')
- except AssertionError, e:
+ except AssertionError as e:
self.assertEqual(str(e), "Negative indexing is not supported.")
- except Exception, e:
+ except Exception as e:
self.fail('Should raise an AssertionError, not %s' % e)
error = None
try:
Article.objects.all()[0:-5]
- except Exception, e:
+ except Exception as e:
error = e
self.assertTrue(isinstance(error, AssertionError))
self.assertEqual(str(error), "Negative indexing is not supported.")
diff --git a/tests/modeltests/get_or_create/tests.py b/tests/modeltests/get_or_create/tests.py
index f98f0e63d8..1e300fbb4d 100644
--- a/tests/modeltests/get_or_create/tests.py
+++ b/tests/modeltests/get_or_create/tests.py
@@ -60,7 +60,7 @@ class GetOrCreateTests(TestCase):
# the actual traceback. Refs #16340.
try:
ManualPrimaryKeyTest.objects.get_or_create(id=1, data="Different")
- except IntegrityError, e:
+ except IntegrityError as e:
formatted_traceback = traceback.format_exc()
self.assertIn('obj.save', formatted_traceback)
diff --git a/tests/modeltests/invalid_models/tests.py b/tests/modeltests/invalid_models/tests.py
index dac562c66e..dfc6199624 100644
--- a/tests/modeltests/invalid_models/tests.py
+++ b/tests/modeltests/invalid_models/tests.py
@@ -35,7 +35,7 @@ class InvalidModelTestCase(unittest.TestCase):
try:
module = load_app("modeltests.invalid_models.invalid_models")
- except Exception, e:
+ except Exception:
self.fail('Unable to load invalid model module')
count = get_validation_errors(self.stdout, module)
diff --git a/tests/modeltests/lookup/tests.py b/tests/modeltests/lookup/tests.py
index 60ab25fc63..502e0d5f2b 100644
--- a/tests/modeltests/lookup/tests.py
+++ b/tests/modeltests/lookup/tests.py
@@ -468,13 +468,13 @@ class LookupTests(TestCase):
try:
Article.objects.filter(pub_date_year='2005').count()
self.fail('FieldError not raised')
- except FieldError, ex:
+ except FieldError as ex:
self.assertEqual(str(ex), "Cannot resolve keyword 'pub_date_year' "
"into field. Choices are: author, headline, id, pub_date, tag")
try:
Article.objects.filter(headline__starts='Article')
self.fail('FieldError not raised')
- except FieldError, ex:
+ except FieldError as ex:
self.assertEqual(str(ex), "Join on field 'headline' not permitted. "
"Did you misspell 'starts' for the lookup type?")
diff --git a/tests/modeltests/select_for_update/tests.py b/tests/modeltests/select_for_update/tests.py
index 65bc13a1f9..0587e11a3a 100644
--- a/tests/modeltests/select_for_update/tests.py
+++ b/tests/modeltests/select_for_update/tests.py
@@ -169,10 +169,8 @@ class SelectForUpdateTests(TransactionTestCase):
people[0].name = 'Fred'
people[0].save()
transaction.commit()
- except DatabaseError, e:
+ except DatabaseError as e:
status.append(e)
- except Exception, e:
- raise
finally:
# This method is run in a separate thread. It uses its own
# database connection. Close it without waiting for the GC.
@@ -246,7 +244,7 @@ class SelectForUpdateTests(TransactionTestCase):
)
)
)
- except DatabaseError, e:
+ except DatabaseError as e:
status.append(e)
finally:
# This method is run in a separate thread. It uses its own
diff --git a/tests/modeltests/validation/models.py b/tests/modeltests/validation/models.py
index e402162b9a..1a6fdd7c16 100644
--- a/tests/modeltests/validation/models.py
+++ b/tests/modeltests/validation/models.py
@@ -99,6 +99,6 @@ try:
class MultipleAutoFields(models.Model):
auto1 = models.AutoField(primary_key=True)
auto2 = models.AutoField(primary_key=True)
-except AssertionError, assertion_error:
+except AssertionError as assertion_error:
pass # Fail silently
assert str(assertion_error) == u"A model can't have more than one AutoField."
diff --git a/tests/modeltests/validation/test_error_messages.py b/tests/modeltests/validation/test_error_messages.py
index 4a2ad1fffa..04ad7aadf7 100644
--- a/tests/modeltests/validation/test_error_messages.py
+++ b/tests/modeltests/validation/test_error_messages.py
@@ -10,13 +10,13 @@ class ValidationMessagesTest(TestCase):
self.assertRaises(ValidationError, f.clean, 'foo', None)
try:
f.clean('foo', None)
- except ValidationError, e:
+ except ValidationError as e:
self.assertEqual(e.messages, [u"'foo' value must be an integer."])
# primary_key must be True. Refs #12467.
self.assertRaises(AssertionError, models.AutoField, 'primary_key', False)
try:
models.AutoField(primary_key=False)
- except AssertionError, e:
+ except AssertionError as e:
self.assertEqual(str(e), "AutoFields must have primary_key=True.")
def test_integer_field_raises_error_message(self):
@@ -24,7 +24,7 @@ class ValidationMessagesTest(TestCase):
self.assertRaises(ValidationError, f.clean, 'foo', None)
try:
f.clean('foo', None)
- except ValidationError, e:
+ except ValidationError as e:
self.assertEqual(e.messages, [u"'foo' value must be an integer."])
def test_boolean_field_raises_error_message(self):
@@ -32,7 +32,7 @@ class ValidationMessagesTest(TestCase):
self.assertRaises(ValidationError, f.clean, 'foo', None)
try:
f.clean('foo', None)
- except ValidationError, e:
+ except ValidationError as e:
self.assertEqual(e.messages,
[u"'foo' value must be either True or False."])
@@ -41,7 +41,7 @@ class ValidationMessagesTest(TestCase):
self.assertRaises(ValidationError, f.clean, 'foo', None)
try:
f.clean('foo', None)
- except ValidationError, e:
+ except ValidationError as e:
self.assertEqual(e.messages, [u"'foo' value must be a float."])
def test_decimal_field_raises_error_message(self):
@@ -49,7 +49,7 @@ class ValidationMessagesTest(TestCase):
self.assertRaises(ValidationError, f.clean, 'foo', None)
try:
f.clean('foo', None)
- except ValidationError, e:
+ except ValidationError as e:
self.assertEqual(e.messages,
[u"'foo' value must be a decimal number."])
@@ -58,7 +58,7 @@ class ValidationMessagesTest(TestCase):
self.assertRaises(ValidationError, f.clean, 'foo', None)
try:
f.clean('foo', None)
- except ValidationError, e:
+ except ValidationError as e:
self.assertEqual(e.messages,
[u"'foo' value must be either None, True or False."])
@@ -67,7 +67,7 @@ class ValidationMessagesTest(TestCase):
self.assertRaises(ValidationError, f.clean, 'foo', None)
try:
f.clean('foo', None)
- except ValidationError, e:
+ except ValidationError as e:
self.assertEqual(e.messages, [
u"'foo' value has an invalid date format. "
u"It must be in YYYY-MM-DD format."])
@@ -75,7 +75,7 @@ class ValidationMessagesTest(TestCase):
self.assertRaises(ValidationError, f.clean, 'aaaa-10-10', None)
try:
f.clean('aaaa-10-10', None)
- except ValidationError, e:
+ except ValidationError as e:
self.assertEqual(e.messages, [
u"'aaaa-10-10' value has an invalid date format. "
u"It must be in YYYY-MM-DD format."])
@@ -83,7 +83,7 @@ class ValidationMessagesTest(TestCase):
self.assertRaises(ValidationError, f.clean, '2011-13-10', None)
try:
f.clean('2011-13-10', None)
- except ValidationError, e:
+ except ValidationError as e:
self.assertEqual(e.messages, [
u"'2011-13-10' value has the correct format (YYYY-MM-DD) "
u"but it is an invalid date."])
@@ -91,7 +91,7 @@ class ValidationMessagesTest(TestCase):
self.assertRaises(ValidationError, f.clean, '2011-10-32', None)
try:
f.clean('2011-10-32', None)
- except ValidationError, e:
+ except ValidationError as e:
self.assertEqual(e.messages, [
u"'2011-10-32' value has the correct format (YYYY-MM-DD) "
u"but it is an invalid date."])
@@ -102,7 +102,7 @@ class ValidationMessagesTest(TestCase):
self.assertRaises(ValidationError, f.clean, 'foo', None)
try:
f.clean('foo', None)
- except ValidationError, e:
+ except ValidationError as e:
self.assertEqual(e.messages, [
u"'foo' value has an invalid format. It must be "
u"in YYYY-MM-DD HH:MM[:ss[.uuuuuu]][TZ] format."])
@@ -111,7 +111,7 @@ class ValidationMessagesTest(TestCase):
self.assertRaises(ValidationError, f.clean, '2011-10-32', None)
try:
f.clean('2011-10-32', None)
- except ValidationError, e:
+ except ValidationError as e:
self.assertEqual(e.messages, [
u"'2011-10-32' value has the correct format "
u"(YYYY-MM-DD) but it is an invalid date."])
@@ -120,7 +120,7 @@ class ValidationMessagesTest(TestCase):
self.assertRaises(ValidationError, f.clean, '2011-10-32 10:10', None)
try:
f.clean('2011-10-32 10:10', None)
- except ValidationError, e:
+ except ValidationError as e:
self.assertEqual(e.messages, [
u"'2011-10-32 10:10' value has the correct format "
u"(YYYY-MM-DD HH:MM[:ss[.uuuuuu]][TZ]) "
@@ -132,7 +132,7 @@ class ValidationMessagesTest(TestCase):
self.assertRaises(ValidationError, f.clean, 'foo', None)
try:
f.clean('foo', None)
- except ValidationError, e:
+ except ValidationError as e:
self.assertEqual(e.messages, [
u"'foo' value has an invalid format. It must be in "
u"HH:MM[:ss[.uuuuuu]] format."])
@@ -140,7 +140,7 @@ class ValidationMessagesTest(TestCase):
self.assertRaises(ValidationError, f.clean, '25:50', None)
try:
f.clean('25:50', None)
- except ValidationError, e:
+ except ValidationError as e:
self.assertEqual(e.messages, [
u"'25:50' value has the correct format "
u"(HH:MM[:ss[.uuuuuu]]) but it is an invalid time."])
diff --git a/tests/modeltests/validation/test_unique.py b/tests/modeltests/validation/test_unique.py
index 497bb9d72d..8f819b9d9c 100644
--- a/tests/modeltests/validation/test_unique.py
+++ b/tests/modeltests/validation/test_unique.py
@@ -115,19 +115,19 @@ class PerformUniqueChecksTest(TestCase):
p = FlexibleDatePost(title="Django 1.0 is released")
try:
p.full_clean()
- except ValidationError, e:
+ except ValidationError:
self.fail("unique_for_date checks shouldn't trigger when the associated DateField is None.")
p = FlexibleDatePost(slug="Django 1.0")
try:
p.full_clean()
- except ValidationError, e:
+ except ValidationError:
self.fail("unique_for_year checks shouldn't trigger when the associated DateField is None.")
p = FlexibleDatePost(subtitle="Finally")
try:
p.full_clean()
- except ValidationError, e:
+ except ValidationError:
self.fail("unique_for_month checks shouldn't trigger when the associated DateField is None.")
def test_unique_errors(self):
diff --git a/tests/regressiontests/app_loading/tests.py b/tests/regressiontests/app_loading/tests.py
index 5173338399..0e66a5aad3 100644
--- a/tests/regressiontests/app_loading/tests.py
+++ b/tests/regressiontests/app_loading/tests.py
@@ -61,7 +61,7 @@ class EggLoadingTest(TestCase):
self.assertRaises(ImportError, load_app, 'broken_app')
try:
load_app('broken_app')
- except ImportError, e:
+ except ImportError as e:
# Make sure the message is indicating the actual
# problem in the broken app.
self.assertTrue("modelz" in e.args[0])
diff --git a/tests/regressiontests/backends/tests.py b/tests/regressiontests/backends/tests.py
index 3e675cc1ea..038f652698 100644
--- a/tests/regressiontests/backends/tests.py
+++ b/tests/regressiontests/backends/tests.py
@@ -569,7 +569,7 @@ class ThreadTests(TestCase):
connections['default'] = main_thread_connection
try:
models.Person.objects.get(first_name="John", last_name="Doe")
- except DatabaseError, e:
+ except DatabaseError as e:
exceptions.append(e)
t = threading.Thread(target=runner, args=[connections['default']])
t.start()
@@ -607,7 +607,7 @@ class ThreadTests(TestCase):
def runner2(other_thread_connection):
try:
other_thread_connection.close()
- except DatabaseError, e:
+ except DatabaseError as e:
exceptions.add(e)
t2 = threading.Thread(target=runner2, args=[connections['default']])
t2.start()
@@ -624,7 +624,7 @@ class ThreadTests(TestCase):
def runner2(other_thread_connection):
try:
other_thread_connection.close()
- except DatabaseError, e:
+ except DatabaseError as e:
exceptions.add(e)
# Enable thread sharing
connections['default'].allow_thread_sharing = True
diff --git a/tests/regressiontests/file_uploads/tests.py b/tests/regressiontests/file_uploads/tests.py
index b6191ba033..a461ce1702 100644
--- a/tests/regressiontests/file_uploads/tests.py
+++ b/tests/regressiontests/file_uploads/tests.py
@@ -304,7 +304,7 @@ class FileUploadTests(TestCase):
# it raises when there is an attempt to read more than the available bytes:
try:
client.FakePayload('a').read(2)
- except Exception, reference_error:
+ except Exception as reference_error:
pass
# install the custom handler that tries to access request.POST
@@ -312,12 +312,12 @@ class FileUploadTests(TestCase):
try:
response = self.client.post('/file_uploads/upload_errors/', post_data)
- except reference_error.__class__, err:
+ except reference_error.__class__ as err:
self.failIf(
str(err) == str(reference_error),
"Caught a repeated exception that'll cause an infinite loop in file uploads."
)
- except Exception, err:
+ except Exception as err:
# CustomUploadError is the error that should have been raised
self.assertEqual(err.__class__, uploadhandler.CustomUploadError)
@@ -374,9 +374,9 @@ class DirectoryCreationTests(unittest.TestCase):
os.chmod(temp_storage.location, 0500)
try:
self.obj.testfile.save('foo.txt', SimpleUploadedFile('foo.txt', 'x'))
- except OSError, err:
+ except OSError as err:
self.assertEqual(err.errno, errno.EACCES)
- except Exception, err:
+ except Exception:
self.fail("OSError [Errno %s] not raised." % errno.EACCES)
def test_not_a_directory(self):
@@ -386,7 +386,7 @@ class DirectoryCreationTests(unittest.TestCase):
fd.close()
try:
self.obj.testfile.save('foo.txt', SimpleUploadedFile('foo.txt', 'x'))
- except IOError, err:
+ except IOError as err:
# The test needs to be done on a specific string as IOError
# is raised even without the patch (just not early enough)
self.assertEqual(err.args[0],
diff --git a/tests/regressiontests/forms/tests/error_messages.py b/tests/regressiontests/forms/tests/error_messages.py
index 973bf22ab1..7153a3b0a6 100644
--- a/tests/regressiontests/forms/tests/error_messages.py
+++ b/tests/regressiontests/forms/tests/error_messages.py
@@ -13,7 +13,7 @@ class AssertFormErrorsMixin(object):
try:
the_callable(*args, **kwargs)
self.fail("Testing the 'clean' method on %s failed to raise a ValidationError.")
- except ValidationError, e:
+ except ValidationError as e:
self.assertEqual(e.messages, expected)
class FormsErrorMessagesTestCase(TestCase, AssertFormErrorsMixin):
diff --git a/tests/regressiontests/forms/tests/validators.py b/tests/regressiontests/forms/tests/validators.py
index cadf660ab8..a4cb324815 100644
--- a/tests/regressiontests/forms/tests/validators.py
+++ b/tests/regressiontests/forms/tests/validators.py
@@ -12,5 +12,5 @@ class TestFieldWithValidators(TestCase):
self.assertRaises(ValidationError, field.clean, 'not int nor mail')
try:
field.clean('not int nor mail')
- except ValidationError, e:
+ except ValidationError as e:
self.assertEqual(2, len(e.messages))
diff --git a/tests/regressiontests/middleware/tests.py b/tests/regressiontests/middleware/tests.py
index 3adb10964a..47fca03ba3 100644
--- a/tests/regressiontests/middleware/tests.py
+++ b/tests/regressiontests/middleware/tests.py
@@ -88,7 +88,7 @@ class CommonMiddlewareTest(TestCase):
request)
try:
CommonMiddleware().process_request(request)
- except RuntimeError, e:
+ except RuntimeError as e:
self.assertTrue('end in a slash' in str(e))
settings.DEBUG = False
@@ -202,7 +202,7 @@ class CommonMiddlewareTest(TestCase):
request)
try:
CommonMiddleware().process_request(request)
- except RuntimeError, e:
+ except RuntimeError as e:
self.assertTrue('end in a slash' in str(e))
settings.DEBUG = False
diff --git a/tests/regressiontests/middleware_exceptions/tests.py b/tests/regressiontests/middleware_exceptions/tests.py
index ac5f09a0a8..586aa0f004 100644
--- a/tests/regressiontests/middleware_exceptions/tests.py
+++ b/tests/regressiontests/middleware_exceptions/tests.py
@@ -118,13 +118,13 @@ class BaseMiddlewareExceptionTest(TestCase):
def assert_exceptions_handled(self, url, errors, extra_error=None):
try:
response = self.client.get(url)
- except TestException, e:
+ except TestException:
# Test client intentionally re-raises any exceptions being raised
# during request handling. Hence actual testing that exception was
# properly handled is done by relying on got_request_exception
# signal being sent.
pass
- except Exception, e:
+ except Exception as e:
if type(extra_error) != type(e):
self.fail("Unexpected exception: %s" % e)
self.assertEqual(len(self.exceptions), len(errors))
diff --git a/tests/regressiontests/model_fields/tests.py b/tests/regressiontests/model_fields/tests.py
index 8fe67fb606..ea1e1c7d99 100644
--- a/tests/regressiontests/model_fields/tests.py
+++ b/tests/regressiontests/model_fields/tests.py
@@ -44,7 +44,7 @@ class BasicFieldTests(test.TestCase):
nullboolean = NullBooleanModel(nbfield=None)
try:
nullboolean.full_clean()
- except ValidationError, e:
+ except ValidationError as e:
self.fail("NullBooleanField failed validation with value of None: %s" % e.messages)
def test_field_repr(self):
diff --git a/tests/regressiontests/model_forms_regress/tests.py b/tests/regressiontests/model_forms_regress/tests.py
index caf24d336c..09da9737a8 100644
--- a/tests/regressiontests/model_forms_regress/tests.py
+++ b/tests/regressiontests/model_forms_regress/tests.py
@@ -333,7 +333,7 @@ class InvalidFieldAndFactory(TestCase):
class Meta:
model = Person
fields = ('name', 'no-field')
- except FieldError, e:
+ except FieldError as e:
# Make sure the exception contains some reference to the
# field responsible for the problem.
self.assertTrue('no-field' in e.args[0])
diff --git a/tests/regressiontests/servers/tests.py b/tests/regressiontests/servers/tests.py
index 3a72550011..c3def15771 100644
--- a/tests/regressiontests/servers/tests.py
+++ b/tests/regressiontests/servers/tests.py
@@ -102,7 +102,7 @@ class LiveServerViews(LiveServerBase):
"""
try:
self.urlopen('/')
- except urllib2.HTTPError, err:
+ except urllib2.HTTPError as err:
self.assertEquals(err.code, 404, 'Expected 404 response')
else:
self.fail('Expected 404 response')
diff --git a/tests/regressiontests/settings_tests/tests.py b/tests/regressiontests/settings_tests/tests.py
index 1dbd5bd849..493ee8021d 100644
--- a/tests/regressiontests/settings_tests/tests.py
+++ b/tests/regressiontests/settings_tests/tests.py
@@ -62,7 +62,7 @@ class ClassDecoratedTestCase(ClassDecoratedTestCaseSuper):
"""
try:
super(ClassDecoratedTestCase, self).test_max_recursion_error()
- except RuntimeError, e:
+ except RuntimeError:
self.fail()
diff --git a/tests/regressiontests/templates/nodelist.py b/tests/regressiontests/templates/nodelist.py
index b78653683f..97aa5af6a7 100644
--- a/tests/regressiontests/templates/nodelist.py
+++ b/tests/regressiontests/templates/nodelist.py
@@ -52,7 +52,7 @@ class ErrorIndexTest(TestCase):
template = get_template_from_string(source)
try:
template.render(context)
- except (RuntimeError, TypeError), e:
+ except (RuntimeError, TypeError) as e:
error_source_index = e.django_template_source[1]
self.assertEqual(error_source_index,
expected_error_source_index)
diff --git a/tests/regressiontests/templates/tests.py b/tests/regressiontests/templates/tests.py
index 9b6f8d40a4..7de27a08a9 100644
--- a/tests/regressiontests/templates/tests.py
+++ b/tests/regressiontests/templates/tests.py
@@ -41,7 +41,7 @@ from .response import (TemplateResponseTest, CacheMiddlewareTest,
try:
from .loaders import RenderToStringTest, EggLoaderTest
-except ImportError, e:
+except ImportError as e:
if "pkg_resources" in e.message:
pass # If setuptools isn't installed, that's fine. Just move on.
else:
@@ -274,7 +274,7 @@ class Templates(unittest.TestCase):
try:
tmpl = loader.select_template([load_name])
r = tmpl.render(template.Context({}))
- except template.TemplateDoesNotExist, e:
+ except template.TemplateDoesNotExist as e:
settings.TEMPLATE_DEBUG = old_td
self.assertEqual(e.args[0], 'missing.html')
self.assertEqual(r, None, 'Template rendering unexpectedly succeeded, produced: ->%r<-' % r)
@@ -307,7 +307,7 @@ class Templates(unittest.TestCase):
r = None
try:
r = tmpl.render(template.Context({}))
- except template.TemplateDoesNotExist, e:
+ except template.TemplateDoesNotExist as e:
settings.TEMPLATE_DEBUG = old_td
self.assertEqual(e.args[0], 'missing.html')
self.assertEqual(r, None, 'Template rendering unexpectedly succeeded, produced: ->%r<-' % r)
@@ -334,7 +334,7 @@ class Templates(unittest.TestCase):
r = None
try:
r = tmpl.render(template.Context({}))
- except template.TemplateDoesNotExist, e:
+ except template.TemplateDoesNotExist as e:
self.assertEqual(e.args[0], 'missing.html')
self.assertEqual(r, None, 'Template rendering unexpectedly succeeded, produced: ->%r<-' % r)
@@ -343,7 +343,7 @@ class Templates(unittest.TestCase):
tmpl = loader.get_template(load_name)
try:
tmpl.render(template.Context({}))
- except template.TemplateDoesNotExist, e:
+ except template.TemplateDoesNotExist as e:
self.assertEqual(e.args[0], 'missing.html')
self.assertEqual(r, None, 'Template rendering unexpectedly succeeded, produced: ->%r<-' % r)
finally:
@@ -384,7 +384,7 @@ class Templates(unittest.TestCase):
from django.template import Template, TemplateSyntaxError
try:
t = Template("{% if 1 %}lala{% endblock %}{% endif %}")
- except TemplateSyntaxError, e:
+ except TemplateSyntaxError as e:
self.assertEqual(e.args[0], "Invalid block tag: 'endblock', expected 'elif', 'else' or 'endif'")
def test_templates(self):
@@ -1638,7 +1638,7 @@ class TemplateTagLoading(unittest.TestCase):
self.assertRaises(template.TemplateSyntaxError, template.Template, ttext)
try:
template.Template(ttext)
- except template.TemplateSyntaxError, e:
+ except template.TemplateSyntaxError as e:
self.assertTrue('ImportError' in e.args[0])
self.assertTrue('Xtemplate' in e.args[0])
@@ -1650,7 +1650,7 @@ class TemplateTagLoading(unittest.TestCase):
self.assertRaises(template.TemplateSyntaxError, template.Template, ttext)
try:
template.Template(ttext)
- except template.TemplateSyntaxError, e:
+ except template.TemplateSyntaxError as e:
self.assertTrue('ImportError' in e.args[0])
self.assertTrue('Xtemplate' in e.args[0])
diff --git a/tests/regressiontests/test_client_regress/models.py b/tests/regressiontests/test_client_regress/models.py
index f75e6458d1..ab4e592239 100644
--- a/tests/regressiontests/test_client_regress/models.py
+++ b/tests/regressiontests/test_client_regress/models.py
@@ -38,83 +38,83 @@ class AssertContainsTests(TestCase):
try:
self.assertContains(response, 'text', status_code=999)
- except AssertionError, e:
+ except AssertionError as e:
self.assertIn("Couldn't retrieve content: Response code was 200 (expected 999)", str(e))
try:
self.assertContains(response, 'text', status_code=999, msg_prefix='abc')
- except AssertionError, e:
+ except AssertionError as e:
self.assertIn("abc: Couldn't retrieve content: Response code was 200 (expected 999)", str(e))
try:
self.assertNotContains(response, 'text', status_code=999)
- except AssertionError, e:
+ except AssertionError as e:
self.assertIn("Couldn't retrieve content: Response code was 200 (expected 999)", str(e))
try:
self.assertNotContains(response, 'text', status_code=999, msg_prefix='abc')
- except AssertionError, e:
+ except AssertionError as e:
self.assertIn("abc: Couldn't retrieve content: Response code was 200 (expected 999)", str(e))
try:
self.assertNotContains(response, 'once')
- except AssertionError, e:
+ except AssertionError as e:
self.assertIn("Response should not contain 'once'", str(e))
try:
self.assertNotContains(response, 'once', msg_prefix='abc')
- except AssertionError, e:
+ except AssertionError as e:
self.assertIn("abc: Response should not contain 'once'", str(e))
try:
self.assertContains(response, 'never', 1)
- except AssertionError, e:
+ except AssertionError as e:
self.assertIn("Found 0 instances of 'never' in response (expected 1)", str(e))
try:
self.assertContains(response, 'never', 1, msg_prefix='abc')
- except AssertionError, e:
+ except AssertionError as e:
self.assertIn("abc: Found 0 instances of 'never' in response (expected 1)", str(e))
try:
self.assertContains(response, 'once', 0)
- except AssertionError, e:
+ except AssertionError as e:
self.assertIn("Found 1 instances of 'once' in response (expected 0)", str(e))
try:
self.assertContains(response, 'once', 0, msg_prefix='abc')
- except AssertionError, e:
+ except AssertionError as e:
self.assertIn("abc: Found 1 instances of 'once' in response (expected 0)", str(e))
try:
self.assertContains(response, 'once', 2)
- except AssertionError, e:
+ except AssertionError as e:
self.assertIn("Found 1 instances of 'once' in response (expected 2)", str(e))
try:
self.assertContains(response, 'once', 2, msg_prefix='abc')
- except AssertionError, e:
+ except AssertionError as e:
self.assertIn("abc: Found 1 instances of 'once' in response (expected 2)", str(e))
try:
self.assertContains(response, 'twice', 1)
- except AssertionError, e:
+ except AssertionError as e:
self.assertIn("Found 2 instances of 'twice' in response (expected 1)", str(e))
try:
self.assertContains(response, 'twice', 1, msg_prefix='abc')
- except AssertionError, e:
+ except AssertionError as e:
self.assertIn("abc: Found 2 instances of 'twice' in response (expected 1)", str(e))
try:
self.assertContains(response, 'thrice')
- except AssertionError, e:
+ except AssertionError as e:
self.assertIn("Couldn't find 'thrice' in response", str(e))
try:
self.assertContains(response, 'thrice', msg_prefix='abc')
- except AssertionError, e:
+ except AssertionError as e:
self.assertIn("abc: Couldn't find 'thrice' in response", str(e))
try:
self.assertContains(response, 'thrice', 3)
- except AssertionError, e:
+ except AssertionError as e:
self.assertIn("Found 0 instances of 'thrice' in response (expected 3)", str(e))
try:
self.assertContains(response, 'thrice', 3, msg_prefix='abc')
- except AssertionError, e:
+ except AssertionError as e:
self.assertIn("abc: Found 0 instances of 'thrice' in response (expected 3)", str(e))
def test_unicode_contains(self):
@@ -175,12 +175,12 @@ class AssertTemplateUsedTests(TestCase):
try:
self.assertTemplateUsed(response, 'GET Template')
- except AssertionError, e:
+ except AssertionError as e:
self.assertIn("No templates used to render the response", str(e))
try:
self.assertTemplateUsed(response, 'GET Template', msg_prefix='abc')
- except AssertionError, e:
+ except AssertionError as e:
self.assertIn("abc: No templates used to render the response", str(e))
def test_single_context(self):
@@ -189,22 +189,22 @@ class AssertTemplateUsedTests(TestCase):
try:
self.assertTemplateNotUsed(response, 'Empty GET Template')
- except AssertionError, e:
+ except AssertionError as e:
self.assertIn("Template 'Empty GET Template' was used unexpectedly in rendering the response", str(e))
try:
self.assertTemplateNotUsed(response, 'Empty GET Template', msg_prefix='abc')
- except AssertionError, e:
+ except AssertionError as e:
self.assertIn("abc: Template 'Empty GET Template' was used unexpectedly in rendering the response", str(e))
try:
self.assertTemplateUsed(response, 'Empty POST Template')
- except AssertionError, e:
+ except AssertionError as e:
self.assertIn("Template 'Empty POST Template' was not a template used to render the response. Actual template(s) used: Empty GET Template", str(e))
try:
self.assertTemplateUsed(response, 'Empty POST Template', msg_prefix='abc')
- except AssertionError, e:
+ except AssertionError as e:
self.assertIn("abc: Template 'Empty POST Template' was not a template used to render the response. Actual template(s) used: Empty GET Template", str(e))
def test_multiple_context(self):
@@ -220,17 +220,17 @@ class AssertTemplateUsedTests(TestCase):
self.assertContains(response, 'POST data OK')
try:
self.assertTemplateNotUsed(response, "form_view.html")
- except AssertionError, e:
+ except AssertionError as e:
self.assertIn("Template 'form_view.html' was used unexpectedly in rendering the response", str(e))
try:
self.assertTemplateNotUsed(response, 'base.html')
- except AssertionError, e:
+ except AssertionError as e:
self.assertIn("Template 'base.html' was used unexpectedly in rendering the response", str(e))
try:
self.assertTemplateUsed(response, "Valid POST Template")
- except AssertionError, e:
+ except AssertionError as e:
self.assertIn("Template 'Valid POST Template' was not a template used to render the response. Actual template(s) used: form_view.html, base.html", str(e))
class AssertRedirectsTests(TestCase):
@@ -240,12 +240,12 @@ class AssertRedirectsTests(TestCase):
response = self.client.get('/test_client/permanent_redirect_view/')
try:
self.assertRedirects(response, '/test_client/get_view/')
- except AssertionError, e:
+ except AssertionError as e:
self.assertIn("Response didn't redirect as expected: Response code was 301 (expected 302)", str(e))
try:
self.assertRedirects(response, '/test_client/get_view/', msg_prefix='abc')
- except AssertionError, e:
+ except AssertionError as e:
self.assertIn("abc: Response didn't redirect as expected: Response code was 301 (expected 302)", str(e))
def test_lost_query(self):
@@ -253,12 +253,12 @@ class AssertRedirectsTests(TestCase):
response = self.client.get('/test_client/redirect_view/', {'var': 'value'})
try:
self.assertRedirects(response, '/test_client/get_view/')
- except AssertionError, e:
+ except AssertionError as e:
self.assertIn("Response redirected to 'http://testserver/test_client/get_view/?var=value', expected 'http://testserver/test_client/get_view/'", str(e))
try:
self.assertRedirects(response, '/test_client/get_view/', msg_prefix='abc')
- except AssertionError, e:
+ except AssertionError as e:
self.assertIn("abc: Response redirected to 'http://testserver/test_client/get_view/?var=value', expected 'http://testserver/test_client/get_view/'", str(e))
def test_incorrect_target(self):
@@ -267,7 +267,7 @@ class AssertRedirectsTests(TestCase):
try:
# Should redirect to get_view
self.assertRedirects(response, '/test_client/some_view/')
- except AssertionError, e:
+ except AssertionError as e:
self.assertIn("Response didn't redirect as expected: Response code was 301 (expected 302)", str(e))
def test_target_page(self):
@@ -276,13 +276,13 @@ class AssertRedirectsTests(TestCase):
try:
# The redirect target responds with a 301 code, not 200
self.assertRedirects(response, 'http://testserver/test_client/permanent_redirect_view/')
- except AssertionError, e:
+ except AssertionError as e:
self.assertIn("Couldn't retrieve redirection page '/test_client/permanent_redirect_view/': response code was 301 (expected 200)", str(e))
try:
# The redirect target responds with a 301 code, not 200
self.assertRedirects(response, 'http://testserver/test_client/permanent_redirect_view/', msg_prefix='abc')
- except AssertionError, e:
+ except AssertionError as e:
self.assertIn("abc: Couldn't retrieve redirection page '/test_client/permanent_redirect_view/': response code was 301 (expected 200)", str(e))
def test_redirect_chain(self):
@@ -385,12 +385,12 @@ class AssertRedirectsTests(TestCase):
response = self.client.get('/test_client/get_view/', follow=True)
try:
self.assertRedirects(response, '/test_client/get_view/')
- except AssertionError, e:
+ except AssertionError as e:
self.assertIn("Response didn't redirect as expected: Response code was 200 (expected 302)", str(e))
try:
self.assertRedirects(response, '/test_client/get_view/', msg_prefix='abc')
- except AssertionError, e:
+ except AssertionError as e:
self.assertIn("abc: Response didn't redirect as expected: Response code was 200 (expected 302)", str(e))
def test_redirect_on_non_redirect_page(self):
@@ -399,12 +399,12 @@ class AssertRedirectsTests(TestCase):
response = self.client.get('/test_client/get_view/')
try:
self.assertRedirects(response, '/test_client/get_view/')
- except AssertionError, e:
+ except AssertionError as e:
self.assertIn("Response didn't redirect as expected: Response code was 200 (expected 302)", str(e))
try:
self.assertRedirects(response, '/test_client/get_view/', msg_prefix='abc')
- except AssertionError, e:
+ except AssertionError as e:
self.assertIn("abc: Response didn't redirect as expected: Response code was 200 (expected 302)", str(e))
@@ -424,11 +424,11 @@ class AssertFormErrorTests(TestCase):
try:
self.assertFormError(response, 'wrong_form', 'some_field', 'Some error.')
- except AssertionError, e:
+ except AssertionError as e:
self.assertIn("The form 'wrong_form' was not used to render the response", str(e))
try:
self.assertFormError(response, 'wrong_form', 'some_field', 'Some error.', msg_prefix='abc')
- except AssertionError, e:
+ except AssertionError as e:
self.assertIn("abc: The form 'wrong_form' was not used to render the response", str(e))
def test_unknown_field(self):
@@ -446,11 +446,11 @@ class AssertFormErrorTests(TestCase):
try:
self.assertFormError(response, 'form', 'some_field', 'Some error.')
- except AssertionError, e:
+ except AssertionError as e:
self.assertIn("The form 'form' in context 0 does not contain the field 'some_field'", str(e))
try:
self.assertFormError(response, 'form', 'some_field', 'Some error.', msg_prefix='abc')
- except AssertionError, e:
+ except AssertionError as e:
self.assertIn("abc: The form 'form' in context 0 does not contain the field 'some_field'", str(e))
def test_noerror_field(self):
@@ -468,11 +468,11 @@ class AssertFormErrorTests(TestCase):
try:
self.assertFormError(response, 'form', 'value', 'Some error.')
- except AssertionError, e:
+ except AssertionError as e:
self.assertIn("The field 'value' on form 'form' in context 0 contains no errors", str(e))
try:
self.assertFormError(response, 'form', 'value', 'Some error.', msg_prefix='abc')
- except AssertionError, e:
+ except AssertionError as e:
self.assertIn("abc: The field 'value' on form 'form' in context 0 contains no errors", str(e))
def test_unknown_error(self):
@@ -490,11 +490,11 @@ class AssertFormErrorTests(TestCase):
try:
self.assertFormError(response, 'form', 'email', 'Some error.')
- except AssertionError, e:
+ except AssertionError as e:
self.assertIn("The field 'email' on form 'form' in context 0 does not contain the error 'Some error.' (actual errors: [u'Enter a valid e-mail address.'])", str(e))
try:
self.assertFormError(response, 'form', 'email', 'Some error.', msg_prefix='abc')
- except AssertionError, e:
+ except AssertionError as e:
self.assertIn("abc: The field 'email' on form 'form' in context 0 does not contain the error 'Some error.' (actual errors: [u'Enter a valid e-mail address.'])", str(e))
def test_unknown_nonfield_error(self):
@@ -515,11 +515,11 @@ class AssertFormErrorTests(TestCase):
try:
self.assertFormError(response, 'form', None, 'Some error.')
- except AssertionError, e:
+ except AssertionError as e:
self.assertIn("The form 'form' in context 0 does not contain the non-field error 'Some error.' (actual errors: )", str(e))
try:
self.assertFormError(response, 'form', None, 'Some error.', msg_prefix='abc')
- except AssertionError, e:
+ except AssertionError as e:
self.assertIn("abc: The form 'form' in context 0 does not contain the non-field error 'Some error.' (actual errors: )", str(e))
class LoginTests(TestCase):
@@ -676,7 +676,7 @@ class ContextTests(TestCase):
try:
response.context['does-not-exist']
self.fail('Should not be able to retrieve non-existent key')
- except KeyError, e:
+ except KeyError as e:
self.assertEqual(e.args[0], 'does-not-exist')
def test_inherited_context(self):
@@ -692,7 +692,7 @@ class ContextTests(TestCase):
try:
response.context['does-not-exist']
self.fail('Should not be able to retrieve non-existent key')
- except KeyError, e:
+ except KeyError as e:
self.assertEqual(e.args[0], 'does-not-exist')
def test_15368(self):
diff --git a/tests/regressiontests/urlpatterns_reverse/tests.py b/tests/regressiontests/urlpatterns_reverse/tests.py
index a1c9244918..bb25806830 100644
--- a/tests/regressiontests/urlpatterns_reverse/tests.py
+++ b/tests/regressiontests/urlpatterns_reverse/tests.py
@@ -161,7 +161,7 @@ class URLPatternReverse(TestCase):
for name, expected, args, kwargs in test_data:
try:
got = reverse(name, args=args, kwargs=kwargs)
- except NoReverseMatch, e:
+ except NoReverseMatch:
self.assertEqual(expected, NoReverseMatch)
else:
self.assertEqual(got, expected)
@@ -207,7 +207,7 @@ class ResolverTests(unittest.TestCase):
try:
resolve('/included/non-existent-url', urlconf=urls)
self.fail('resolve did not raise a 404')
- except Resolver404, e:
+ except Resolver404 as e:
# make sure we at least matched the root ('/') url resolver:
self.assertTrue('tried' in e.args[0])
tried = e.args[0]['tried']