Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Partial revert of 165f44a.

That commit didn't always improve readability.

See discussion on django-developers for details.
  • Loading branch information...
commit ee0ef1b0948c19bc5fee06a6b9b4286b879f81c1 1 parent 222460a
@aaugustin aaugustin authored
View
24 django/contrib/humanize/tests.py
@@ -90,9 +90,9 @@ def test_l10n_intcomma(self):
'100', '1,000', '10,123', '10,311', '1,000,000', '1,234,567.1234567', '1,234,567.1234567',
None)
- with self.settings(USE_L10N=True, USE_THOUSAND_SEPARATOR=False), \
- translation.override('en'):
- self.humanize_tester(test_list, result_list, 'intcomma')
+ with self.settings(USE_L10N=True, USE_THOUSAND_SEPARATOR=False):
+ with translation.override('en'):
+ self.humanize_tester(test_list, result_list, 'intcomma')
def test_intcomma_without_number_grouping(self):
# Regression for #17414
@@ -116,18 +116,18 @@ def test_i18n_intcomma(self):
'100', '1000', '10123', '10311', '1000000', None)
result_list = ('100', '1.000', '10.123', '10.311', '1.000.000', '1.234.567,25',
'100', '1.000', '10.123', '10.311', '1.000.000', None)
- with self.settings(USE_L10N=True, USE_THOUSAND_SEPARATOR=True), \
- translation.override('de'):
- self.humanize_tester(test_list, result_list, 'intcomma')
+ with self.settings(USE_L10N=True, USE_THOUSAND_SEPARATOR=True):
+ with translation.override('de'):
+ self.humanize_tester(test_list, result_list, 'intcomma')
def test_i18n_intword(self):
test_list = ('100', '1000000', '1200000', '1290000',
'1000000000', '2000000000', '6000000000000')
result_list = ('100', '1,0 Million', '1,2 Millionen', '1,3 Millionen',
'1,0 Milliarde', '2,0 Milliarden', '6,0 Billionen')
- with self.settings(USE_L10N=True, USE_THOUSAND_SEPARATOR=True), \
- translation.override('de'):
- self.humanize_tester(test_list, result_list, 'intword')
+ with self.settings(USE_L10N=True, USE_THOUSAND_SEPARATOR=True):
+ with translation.override('de'):
+ self.humanize_tester(test_list, result_list, 'intword')
def test_apnumber(self):
test_list = [str(x) for x in range(1, 11)]
@@ -174,9 +174,9 @@ def test_naturalday_uses_localtime(self):
orig_humanize_datetime, humanize.datetime = humanize.datetime, MockDateTime
try:
- with override_settings(TIME_ZONE="America/Chicago", USE_TZ=True), \
- translation.override('en'):
- self.humanize_tester([dt], ['yesterday'], 'naturalday')
+ with override_settings(TIME_ZONE="America/Chicago", USE_TZ=True):
+ with translation.override('en'):
+ self.humanize_tester([dt], ['yesterday'], 'naturalday')
finally:
humanize.datetime = orig_humanize_datetime
View
10 tests/i18n/tests.py
@@ -745,11 +745,11 @@ def test_get_format_modules_lang(self):
self.assertEqual('.', get_format('DECIMAL_SEPARATOR', lang='en'))
def test_get_format_modules_stability(self):
- with self.settings(FORMAT_MODULE_PATH='i18n.other.locale'), \
- translation.override('de', deactivate=True):
- old = str("%r") % get_format_modules(reverse=True)
- new = str("%r") % get_format_modules(reverse=True) # second try
- self.assertEqual(new, old, 'Value returned by get_formats_modules() must be preserved between calls.')
+ with self.settings(FORMAT_MODULE_PATH='i18n.other.locale'):
+ with translation.override('de', deactivate=True):
+ old = str("%r") % get_format_modules(reverse=True)
+ new = str("%r") % get_format_modules(reverse=True) # second try
+ self.assertEqual(new, old, 'Value returned by get_formats_modules() must be preserved between calls.')
def test_localize_templatetag_and_filter(self):
"""
View
35 tests/one_to_one_regress/tests.py
@@ -141,10 +141,12 @@ def test_reverse_object_does_not_exist_cache(self):
"""
p = Place(name='Zombie Cats', address='Not sure')
p.save()
- with self.assertNumQueries(1), self.assertRaises(Restaurant.DoesNotExist):
- p.restaurant
- with self.assertNumQueries(0), self.assertRaises(Restaurant.DoesNotExist):
- p.restaurant
+ with self.assertNumQueries(1):
+ with self.assertRaises(Restaurant.DoesNotExist):
+ p.restaurant
+ with self.assertNumQueries(0):
+ with self.assertRaises(Restaurant.DoesNotExist):
+ p.restaurant
def test_reverse_object_cached_when_related_is_accessed(self):
"""
@@ -197,8 +199,9 @@ def test_reverse_object_cached_when_related_is_unset(self):
self.assertEqual(self.p1.undergroundbar, b)
b.place = None
b.save()
- with self.assertNumQueries(0), self.assertRaises(UndergroundBar.DoesNotExist):
- self.p1.undergroundbar
+ with self.assertNumQueries(0):
+ with self.assertRaises(UndergroundBar.DoesNotExist):
+ self.p1.undergroundbar
def test_get_reverse_on_unsaved_object(self):
"""
@@ -210,21 +213,24 @@ def test_get_reverse_on_unsaved_object(self):
p = Place()
# When there's no instance of the origin of the one-to-one
- with self.assertNumQueries(0), self.assertRaises(UndergroundBar.DoesNotExist):
- p.undergroundbar
+ with self.assertNumQueries(0):
+ with self.assertRaises(UndergroundBar.DoesNotExist):
+ p.undergroundbar
UndergroundBar.objects.create()
# When there's one instance of the origin
# (p.undergroundbar used to return that instance)
- with self.assertNumQueries(0), self.assertRaises(UndergroundBar.DoesNotExist):
- p.undergroundbar
+ with self.assertNumQueries(0):
+ with self.assertRaises(UndergroundBar.DoesNotExist):
+ p.undergroundbar
UndergroundBar.objects.create()
# When there are several instances of the origin
- with self.assertNumQueries(0), self.assertRaises(UndergroundBar.DoesNotExist):
- p.undergroundbar
+ with self.assertNumQueries(0):
+ with self.assertRaises(UndergroundBar.DoesNotExist):
+ p.undergroundbar
def test_set_reverse_on_unsaved_object(self):
"""
@@ -233,8 +239,9 @@ def test_set_reverse_on_unsaved_object(self):
"""
p = Place()
b = UndergroundBar.objects.create()
- with self.assertNumQueries(0), self.assertRaises(ValueError):
- p.undergroundbar = b
+ with self.assertNumQueries(0):
+ with self.assertRaises(ValueError):
+ p.undergroundbar = b
def test_nullable_o2o_delete(self):
u = UndergroundBar.objects.create(place=self.p1)
View
71 tests/test_utils/tests.py
@@ -152,8 +152,9 @@ def test_nested(self):
self.assertEqual(2, len(captured_queries))
def test_failure(self):
- with self.assertRaises(TypeError), CaptureQueriesContext(connection):
- raise TypeError
+ with self.assertRaises(TypeError):
+ with CaptureQueriesContext(connection):
+ raise TypeError
def test_with_client(self):
with CaptureQueriesContext(connection) as captured_queries:
@@ -189,12 +190,14 @@ def test_simple(self):
Person.objects.count()
def test_failure(self):
- with self.assertRaises(AssertionError) as exc_info, self.assertNumQueries(2):
- Person.objects.count()
+ with self.assertRaises(AssertionError) as exc_info:
+ with self.assertNumQueries(2):
+ Person.objects.count()
self.assertIn("1 queries executed, 2 expected", str(exc_info.exception))
- with self.assertRaises(TypeError), self.assertNumQueries(4000):
- raise TypeError
+ with self.assertRaises(TypeError):
+ with self.assertNumQueries(4000):
+ raise TypeError
def test_with_client(self):
person = Person.objects.create(name="test")
@@ -229,13 +232,13 @@ def test_usage(self):
render_to_string('template_used/base.html')
def test_nested_usage(self):
- with self.assertTemplateUsed('template_used/base.html'), \
- self.assertTemplateUsed('template_used/include.html'):
- render_to_string('template_used/include.html')
+ with self.assertTemplateUsed('template_used/base.html'):
+ with self.assertTemplateUsed('template_used/include.html'):
+ render_to_string('template_used/include.html')
- with self.assertTemplateUsed('template_used/extends.html'), \
- self.assertTemplateUsed('template_used/base.html'):
- render_to_string('template_used/extends.html')
+ with self.assertTemplateUsed('template_used/extends.html'):
+ with self.assertTemplateUsed('template_used/base.html'):
+ render_to_string('template_used/extends.html')
with self.assertTemplateUsed('template_used/base.html'):
with self.assertTemplateUsed('template_used/alternative.html'):
@@ -255,34 +258,38 @@ def test_not_used(self):
pass
def test_error_message(self):
- with six.assertRaisesRegex(self, AssertionError, r'^template_used/base\.html'), \
- self.assertTemplateUsed('template_used/base.html'):
- pass
+ with six.assertRaisesRegex(self, AssertionError, r'^template_used/base\.html'):
+ with self.assertTemplateUsed('template_used/base.html'):
+ pass
- with six.assertRaisesRegex(self, AssertionError, r'^template_used/base\.html'), \
- self.assertTemplateUsed(template_name='template_used/base.html'):
- pass
+ with six.assertRaisesRegex(self, AssertionError, r'^template_used/base\.html'):
+ with self.assertTemplateUsed(template_name='template_used/base.html'):
+ pass
- with six.assertRaisesRegex(self, AssertionError, r'^template_used/base\.html.*template_used/alternative\.html$'), \
- self.assertTemplateUsed('template_used/base.html'):
- render_to_string('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')
def test_failure(self):
- with self.assertRaises(TypeError), self.assertTemplateUsed():
- pass
+ with self.assertRaises(TypeError):
+ with self.assertTemplateUsed():
+ pass
- with self.assertRaises(AssertionError), self.assertTemplateUsed(''):
- pass
+ with self.assertRaises(AssertionError):
+ with self.assertTemplateUsed(''):
+ pass
- with self.assertRaises(AssertionError), self.assertTemplateUsed(''):
- render_to_string('template_used/base.html')
+ with self.assertRaises(AssertionError):
+ with self.assertTemplateUsed(''):
+ render_to_string('template_used/base.html')
- with self.assertRaises(AssertionError), self.assertTemplateUsed(template_name=''):
- pass
+ with self.assertRaises(AssertionError):
+ with self.assertTemplateUsed(template_name=''):
+ pass
- with self.assertRaises(AssertionError), \
- self.assertTemplateUsed('template_used/base.html'):
- render_to_string('template_used/alternative.html')
+ with self.assertRaises(AssertionError):
+ with self.assertTemplateUsed('template_used/base.html'):
+ render_to_string('template_used/alternative.html')
class HTMLEqualTests(TestCase):
View
179 tests/transactions/tests.py
@@ -65,9 +65,10 @@ def test_commit(self):
self.assertQuerysetEqual(Reporter.objects.all(), ['<Reporter: Tintin>'])
def test_rollback(self):
- with six.assertRaisesRegex(self, Exception, "Oops"), transaction.atomic():
- Reporter.objects.create(first_name="Haddock")
- raise Exception("Oops, that's his last name")
+ with six.assertRaisesRegex(self, Exception, "Oops"):
+ with transaction.atomic():
+ Reporter.objects.create(first_name="Haddock")
+ raise Exception("Oops, that's his last name")
self.assertQuerysetEqual(Reporter.objects.all(), [])
def test_nested_commit_commit(self):
@@ -81,27 +82,30 @@ def test_nested_commit_commit(self):
def test_nested_commit_rollback(self):
with transaction.atomic():
Reporter.objects.create(first_name="Tintin")
- with six.assertRaisesRegex(self, Exception, "Oops"), transaction.atomic():
- Reporter.objects.create(first_name="Haddock")
- raise Exception("Oops, that's his last name")
+ with six.assertRaisesRegex(self, Exception, "Oops"):
+ with transaction.atomic():
+ Reporter.objects.create(first_name="Haddock")
+ raise Exception("Oops, that's his last name")
self.assertQuerysetEqual(Reporter.objects.all(), ['<Reporter: Tintin>'])
def test_nested_rollback_commit(self):
- with six.assertRaisesRegex(self, Exception, "Oops"), transaction.atomic():
- Reporter.objects.create(last_name="Tintin")
+ with six.assertRaisesRegex(self, Exception, "Oops"):
with transaction.atomic():
- Reporter.objects.create(last_name="Haddock")
- raise Exception("Oops, that's his first name")
+ Reporter.objects.create(last_name="Tintin")
+ with transaction.atomic():
+ Reporter.objects.create(last_name="Haddock")
+ raise Exception("Oops, that's his first name")
self.assertQuerysetEqual(Reporter.objects.all(), [])
def test_nested_rollback_rollback(self):
- with six.assertRaisesRegex(self, Exception, "Oops"), transaction.atomic():
- Reporter.objects.create(last_name="Tintin")
- with six.assertRaisesRegex(self, Exception, "Oops"):
- with transaction.atomic():
- Reporter.objects.create(first_name="Haddock")
- raise Exception("Oops, that's his last name")
- raise Exception("Oops, that's his first name")
+ with six.assertRaisesRegex(self, Exception, "Oops"):
+ with transaction.atomic():
+ Reporter.objects.create(last_name="Tintin")
+ with six.assertRaisesRegex(self, Exception, "Oops"):
+ with transaction.atomic():
+ Reporter.objects.create(first_name="Haddock")
+ raise Exception("Oops, that's his last name")
+ raise Exception("Oops, that's his first name")
self.assertQuerysetEqual(Reporter.objects.all(), [])
def test_merged_commit_commit(self):
@@ -115,29 +119,31 @@ def test_merged_commit_commit(self):
def test_merged_commit_rollback(self):
with transaction.atomic():
Reporter.objects.create(first_name="Tintin")
- with six.assertRaisesRegex(self, Exception, "Oops"), \
- transaction.atomic(savepoint=False):
- Reporter.objects.create(first_name="Haddock")
- raise Exception("Oops, that's his last name")
+ with six.assertRaisesRegex(self, Exception, "Oops"):
+ with transaction.atomic(savepoint=False):
+ Reporter.objects.create(first_name="Haddock")
+ raise Exception("Oops, that's his last name")
# Writes in the outer block are rolled back too.
self.assertQuerysetEqual(Reporter.objects.all(), [])
def test_merged_rollback_commit(self):
- with six.assertRaisesRegex(self, Exception, "Oops"), transaction.atomic():
- Reporter.objects.create(last_name="Tintin")
- with transaction.atomic(savepoint=False):
- Reporter.objects.create(last_name="Haddock")
- raise Exception("Oops, that's his first name")
+ with six.assertRaisesRegex(self, Exception, "Oops"):
+ with transaction.atomic():
+ Reporter.objects.create(last_name="Tintin")
+ with transaction.atomic(savepoint=False):
+ Reporter.objects.create(last_name="Haddock")
+ raise Exception("Oops, that's his first name")
self.assertQuerysetEqual(Reporter.objects.all(), [])
def test_merged_rollback_rollback(self):
- with six.assertRaisesRegex(self, Exception, "Oops"), transaction.atomic():
- Reporter.objects.create(last_name="Tintin")
- with six.assertRaisesRegex(self, Exception, "Oops"):
- with transaction.atomic(savepoint=False):
- Reporter.objects.create(first_name="Haddock")
- raise Exception("Oops, that's his last name")
- raise Exception("Oops, that's his first name")
+ with six.assertRaisesRegex(self, Exception, "Oops"):
+ with transaction.atomic():
+ Reporter.objects.create(last_name="Tintin")
+ with six.assertRaisesRegex(self, Exception, "Oops"):
+ with transaction.atomic(savepoint=False):
+ Reporter.objects.create(first_name="Haddock")
+ raise Exception("Oops, that's his last name")
+ raise Exception("Oops, that's his first name")
self.assertQuerysetEqual(Reporter.objects.all(), [])
def test_reuse_commit_commit(self):
@@ -153,29 +159,32 @@ def test_reuse_commit_rollback(self):
atomic = transaction.atomic()
with atomic:
Reporter.objects.create(first_name="Tintin")
- with six.assertRaisesRegex(self, Exception, "Oops"), atomic:
- Reporter.objects.create(first_name="Haddock")
- raise Exception("Oops, that's his last name")
+ with six.assertRaisesRegex(self, Exception, "Oops"):
+ with atomic:
+ Reporter.objects.create(first_name="Haddock")
+ raise Exception("Oops, that's his last name")
self.assertQuerysetEqual(Reporter.objects.all(), ['<Reporter: Tintin>'])
def test_reuse_rollback_commit(self):
atomic = transaction.atomic()
- with six.assertRaisesRegex(self, Exception, "Oops"), atomic:
- Reporter.objects.create(last_name="Tintin")
+ with six.assertRaisesRegex(self, Exception, "Oops"):
with atomic:
- Reporter.objects.create(last_name="Haddock")
- raise Exception("Oops, that's his first name")
+ Reporter.objects.create(last_name="Tintin")
+ with atomic:
+ Reporter.objects.create(last_name="Haddock")
+ raise Exception("Oops, that's his first name")
self.assertQuerysetEqual(Reporter.objects.all(), [])
def test_reuse_rollback_rollback(self):
atomic = transaction.atomic()
- with six.assertRaisesRegex(self, Exception, "Oops"), atomic:
- Reporter.objects.create(last_name="Tintin")
- with six.assertRaisesRegex(self, Exception, "Oops"):
- with atomic:
- Reporter.objects.create(first_name="Haddock")
- raise Exception("Oops, that's his last name")
- raise Exception("Oops, that's his first name")
+ with six.assertRaisesRegex(self, Exception, "Oops"):
+ with atomic:
+ Reporter.objects.create(last_name="Tintin")
+ with six.assertRaisesRegex(self, Exception, "Oops"):
+ with atomic:
+ Reporter.objects.create(first_name="Haddock")
+ raise Exception("Oops, that's his last name")
+ raise Exception("Oops, that's his first name")
self.assertQuerysetEqual(Reporter.objects.all(), [])
def test_force_rollback(self):
@@ -191,9 +200,10 @@ def test_prevent_rollback(self):
Reporter.objects.create(first_name="Tintin")
sid = transaction.savepoint()
# trigger a database error inside an inner atomic without savepoint
- with self.assertRaises(DatabaseError), transaction.atomic(savepoint=False):
- connection.cursor().execute(
- "SELECT no_such_col FROM transactions_reporter")
+ with self.assertRaises(DatabaseError):
+ with transaction.atomic(savepoint=False):
+ connection.cursor().execute(
+ "SELECT no_such_col FROM transactions_reporter")
transaction.savepoint_rollback(sid)
# atomic block should rollback, but prevent it, as we just did it.
self.assertTrue(transaction.get_rollback())
@@ -253,10 +263,10 @@ def test_merged_outer_rollback(self):
Reporter.objects.create(first_name="Tintin")
with transaction.atomic(savepoint=False):
Reporter.objects.create(first_name="Archibald", last_name="Haddock")
- with six.assertRaisesRegex(self, Exception, "Oops"), \
- transaction.atomic(savepoint=False):
- Reporter.objects.create(first_name="Tournesol")
- raise Exception("Oops, that's his last name")
+ with six.assertRaisesRegex(self, Exception, "Oops"):
+ with transaction.atomic(savepoint=False):
+ Reporter.objects.create(first_name="Tournesol")
+ raise Exception("Oops, that's his last name")
# It wasn't possible to roll back
self.assertEqual(Reporter.objects.count(), 3)
# It wasn't possible to roll back
@@ -269,10 +279,10 @@ def test_merged_inner_savepoint_rollback(self):
Reporter.objects.create(first_name="Tintin")
with transaction.atomic():
Reporter.objects.create(first_name="Archibald", last_name="Haddock")
- with six.assertRaisesRegex(self, Exception, "Oops"), \
- transaction.atomic(savepoint=False):
- Reporter.objects.create(first_name="Tournesol")
- raise Exception("Oops, that's his last name")
+ with six.assertRaisesRegex(self, Exception, "Oops"):
+ with transaction.atomic(savepoint=False):
+ Reporter.objects.create(first_name="Tournesol")
+ raise Exception("Oops, that's his last name")
# It wasn't possible to roll back
self.assertEqual(Reporter.objects.count(), 3)
# The first block with a savepoint must roll back
@@ -283,10 +293,10 @@ def test_merged_outer_rollback_after_inner_failure_and_inner_success(self):
with transaction.atomic():
Reporter.objects.create(first_name="Tintin")
# Inner block without a savepoint fails
- with six.assertRaisesRegex(self, Exception, "Oops"), \
- transaction.atomic(savepoint=False):
- Reporter.objects.create(first_name="Haddock")
- raise Exception("Oops, that's his last name")
+ with six.assertRaisesRegex(self, Exception, "Oops"):
+ with transaction.atomic(savepoint=False):
+ Reporter.objects.create(first_name="Haddock")
+ raise Exception("Oops, that's his last name")
# It wasn't possible to roll back
self.assertEqual(Reporter.objects.count(), 2)
# Inner block with a savepoint succeeds
@@ -306,9 +316,9 @@ class AtomicErrorsTests(TransactionTestCase):
def test_atomic_prevents_setting_autocommit(self):
autocommit = transaction.get_autocommit()
- with transaction.atomic(), \
- self.assertRaises(transaction.TransactionManagementError):
- transaction.set_autocommit(not autocommit)
+ with transaction.atomic():
+ with self.assertRaises(transaction.TransactionManagementError):
+ transaction.set_autocommit(not autocommit)
# Make sure autocommit wasn't changed.
self.assertEqual(connection.autocommit, autocommit)
@@ -542,8 +552,9 @@ def test_autocommit_context_manager(self):
The autocommit context manager works exactly the same as the default
behavior.
"""
- with self.assertRaises(Exception), transaction.autocommit():
- self.create_reporter_and_fail()
+ with self.assertRaises(Exception):
+ with transaction.autocommit():
+ self.create_reporter_and_fail()
self.assertEqual(Reporter.objects.count(), 1)
@@ -552,8 +563,9 @@ def test_autocommit_context_manager_with_using(self):
"""
The autocommit context manager also works with a using argument.
"""
- with self.assertRaises(Exception), transaction.autocommit(using="default"):
- self.create_reporter_and_fail()
+ with self.assertRaises(Exception):
+ with transaction.autocommit(using="default"):
+ self.create_reporter_and_fail()
self.assertEqual(Reporter.objects.count(), 1)
@@ -563,8 +575,9 @@ def test_commit_on_success(self):
With the commit_on_success context manager, the transaction is only
committed if the block doesn't throw an exception.
"""
- with self.assertRaises(Exception), transaction.commit_on_success():
- self.create_reporter_and_fail()
+ with self.assertRaises(Exception):
+ with transaction.commit_on_success():
+ self.create_reporter_and_fail()
self.assertEqual(Reporter.objects.count(), 0)
@@ -573,8 +586,9 @@ def test_commit_on_success_with_using(self):
"""
The commit_on_success context manager also works with a using argument.
"""
- with self.assertRaises(Exception), transaction.commit_on_success(using="default"):
- self.create_reporter_and_fail()
+ with self.assertRaises(Exception):
+ with transaction.commit_on_success(using="default"):
+ self.create_reporter_and_fail()
self.assertEqual(Reporter.objects.count(), 0)
@@ -619,18 +633,18 @@ def test_manually_managed_mistake(self):
"""
If you forget, you'll get bad errors.
"""
- with self.assertRaises(transaction.TransactionManagementError), \
- transaction.commit_manually():
- Reporter.objects.create(first_name="Scott", last_name="Browning")
+ with self.assertRaises(transaction.TransactionManagementError):
+ with transaction.commit_manually():
+ Reporter.objects.create(first_name="Scott", last_name="Browning")
@skipUnlessDBFeature('supports_transactions')
def test_manually_managed_with_using(self):
"""
The commit_manually function also works with a using argument.
"""
- with self.assertRaises(transaction.TransactionManagementError), \
- transaction.commit_manually(using="default"):
- Reporter.objects.create(first_name="Walter", last_name="Cronkite")
+ with self.assertRaises(transaction.TransactionManagementError):
+ with transaction.commit_manually(using="default"):
+ Reporter.objects.create(first_name="Walter", last_name="Cronkite")
@skipUnlessDBFeature('requires_rollback_on_dirty_transaction')
def test_bad_sql(self):
@@ -640,7 +654,8 @@ def test_bad_sql(self):
be rolled back. The bug is only visible using the psycopg2 backend,
though the fix is generally a good idea.
"""
- with self.assertRaises(IntegrityError), transaction.commit_on_success():
- cursor = connection.cursor()
- cursor.execute("INSERT INTO transactions_reporter (first_name, last_name) VALUES ('Douglas', 'Adams');")
+ with self.assertRaises(IntegrityError):
+ with transaction.commit_on_success():
+ cursor = connection.cursor()
+ cursor.execute("INSERT INTO transactions_reporter (first_name, last_name) VALUES ('Douglas', 'Adams');")
transaction.rollback()
View
36 tests/view_tests/tests/test_i18n.py
@@ -116,10 +116,10 @@ def test_nonenglish_default_english_userpref(self):
with the proper English translations. See #13726 for more details.
"""
extended_apps = list(settings.INSTALLED_APPS) + ['view_tests.app0']
- with self.settings(LANGUAGE_CODE='fr', INSTALLED_APPS=extended_apps), \
- override('en-us'):
- response = self.client.get('/views/jsi18n_english_translation/')
- self.assertContains(response, javascript_quote('this app0 string is to be translated'))
+ with self.settings(LANGUAGE_CODE='fr', INSTALLED_APPS=extended_apps):
+ with override('en-us'):
+ response = self.client.get('/views/jsi18n_english_translation/')
+ self.assertContains(response, javascript_quote('this app0 string is to be translated'))
def testI18NLanguageNonEnglishFallback(self):
"""
@@ -145,11 +145,10 @@ def testI18NLanguageEnglishDefault(self):
#3594 and #13514 for more details.
"""
extended_apps = list(settings.INSTALLED_APPS) + ['view_tests.app1', 'view_tests.app2']
- with self.settings(LANGUAGE_CODE='en-us', INSTALLED_APPS=extended_apps), \
- override('fr'):
- response = self.client.get('/views/jsi18n_multi_packages1/')
- self.assertContains(response,
- javascript_quote('il faut traduire cette chaîne de caractères de app1'))
+ with self.settings(LANGUAGE_CODE='en-us', INSTALLED_APPS=extended_apps):
+ with override('fr'):
+ response = self.client.get('/views/jsi18n_multi_packages1/')
+ self.assertContains(response, javascript_quote('il faut traduire cette chaîne de caractères de app1'))
def testI18NDifferentNonEnLangs(self):
"""
@@ -157,21 +156,20 @@ def testI18NDifferentNonEnLangs(self):
English.
"""
extended_apps = list(settings.INSTALLED_APPS) + ['view_tests.app3', 'view_tests.app4']
- with self.settings(LANGUAGE_CODE='fr', INSTALLED_APPS=extended_apps), \
- override('es-ar'):
- response = self.client.get('/views/jsi18n_multi_packages2/')
- self.assertContains(response,
- javascript_quote('este texto de app3 debe ser traducido'))
+ with self.settings(LANGUAGE_CODE='fr', INSTALLED_APPS=extended_apps):
+ with override('es-ar'):
+ response = self.client.get('/views/jsi18n_multi_packages2/')
+ self.assertContains(response, javascript_quote('este texto de app3 debe ser traducido'))
def testI18NWithLocalePaths(self):
extended_locale_paths = settings.LOCALE_PATHS + (
path.join(path.dirname(
path.dirname(path.abspath(upath(__file__)))), 'app3', 'locale'),)
- with self.settings(LANGUAGE_CODE='es-ar', LOCALE_PATHS=extended_locale_paths), \
- override('es-ar'):
- response = self.client.get('/views/jsi18n/')
- self.assertContains(response,
- javascript_quote('este texto de app3 debe ser traducido'))
+ with self.settings(LANGUAGE_CODE='es-ar', LOCALE_PATHS=extended_locale_paths):
+ with override('es-ar'):
+ response = self.client.get('/views/jsi18n/')
+ self.assertContains(response,
+ javascript_quote('este texto de app3 debe ser traducido'))
skip_selenium = not os.environ.get('DJANGO_SELENIUM_TESTS', False)
Please sign in to comment.
Something went wrong with that request. Please try again.