mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Partial revert of 165f44aa.
That commit didn't always improve readability. See discussion on django-developers for details.
This commit is contained in:
@@ -152,8 +152,9 @@ class CaptureQueriesContextManagerTests(TestCase):
|
||||
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 @@ class AssertNumQueriesContextManagerTests(TestCase):
|
||||
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 @@ class AssertTemplateUsedContextManagerTests(TestCase):
|
||||
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 @@ class AssertTemplateUsedContextManagerTests(TestCase):
|
||||
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):
|
||||
|
||||
Reference in New Issue
Block a user