Made multiline assertRaises* conform to flake8's E128 rule.

This commit is contained in:
Hasan 2016-02-04 14:40:50 +03:30 committed by Tim Graham
parent 6eb3ce11e4
commit 04de436932
4 changed files with 25 additions and 33 deletions

View File

@ -111,8 +111,9 @@ class EarliestOrLatestTests(TestCase):
Article.objects.model._meta.get_latest_by = None
with self.assertRaisesMessage(
AssertionError,
"earliest() and latest() require either a field_name parameter or "
"'get_latest_by' in the model"):
"earliest() and latest() require either a field_name parameter or "
"'get_latest_by' in the model"
):
Article.objects.latest()
def test_latest_manual(self):

View File

@ -508,9 +508,11 @@ class JsonResponseTests(SimpleTestCase):
self.assertEqual(json.loads(response.content.decode()), data)
def test_json_response_raises_type_error_with_default_setting(self):
with self.assertRaisesMessage(TypeError,
'In order to allow non-dict objects to be serialized set the '
'safe parameter to False'):
with self.assertRaisesMessage(
TypeError,
'In order to allow non-dict objects to be serialized set the '
'safe parameter to False'
):
JsonResponse([1, 2, 3])
def test_json_response_text(self):

View File

@ -1318,12 +1318,10 @@ class Queries3Tests(BaseQuerysetTest):
Item.objects.datetimes('name', 'month')
def test_ticket22023(self):
with self.assertRaisesMessage(TypeError,
"Cannot call only() after .values() or .values_list()"):
with self.assertRaisesMessage(TypeError, "Cannot call only() after .values() or .values_list()"):
Valid.objects.values().only()
with self.assertRaisesMessage(TypeError,
"Cannot call defer() after .values() or .values_list()"):
with self.assertRaisesMessage(TypeError, "Cannot call defer() after .values() or .values_list()"):
Valid.objects.values().defer()
@ -2244,9 +2242,8 @@ class ValuesQuerysetTests(BaseQuerysetTest):
def test_field_error_values_list(self):
# see #23443
with self.assertRaisesMessage(FieldError,
"Cannot resolve keyword %r into field."
" Join on 'name' not permitted." % 'foo'):
msg = "Cannot resolve keyword %r into field. Join on 'name' not permitted." % 'foo'
with self.assertRaisesMessage(FieldError, msg):
Tag.objects.values_list('name__foo')
@ -3462,25 +3459,20 @@ class RelatedLookupTypeTests(TestCase):
query lookup.
"""
# Passing incorrect object type
with self.assertRaisesMessage(ValueError,
self.error % (self.wrong_type, ObjectA._meta.object_name)):
with self.assertRaisesMessage(ValueError, self.error % (self.wrong_type, ObjectA._meta.object_name)):
ObjectB.objects.get(objecta=self.wrong_type)
with self.assertRaisesMessage(ValueError,
self.error % (self.wrong_type, ObjectA._meta.object_name)):
with self.assertRaisesMessage(ValueError, self.error % (self.wrong_type, ObjectA._meta.object_name)):
ObjectB.objects.filter(objecta__in=[self.wrong_type])
with self.assertRaisesMessage(ValueError,
self.error % (self.wrong_type, ObjectA._meta.object_name)):
with self.assertRaisesMessage(ValueError, self.error % (self.wrong_type, ObjectA._meta.object_name)):
ObjectB.objects.filter(objecta=self.wrong_type)
with self.assertRaisesMessage(ValueError,
self.error % (self.wrong_type, ObjectB._meta.object_name)):
with self.assertRaisesMessage(ValueError, self.error % (self.wrong_type, ObjectB._meta.object_name)):
ObjectA.objects.filter(objectb__in=[self.wrong_type, self.ob])
# Passing an object of the class on which query is done.
with self.assertRaisesMessage(ValueError,
self.error % (self.ob, ObjectA._meta.object_name)):
with self.assertRaisesMessage(ValueError, self.error % (self.ob, ObjectA._meta.object_name)):
ObjectB.objects.filter(objecta__in=[self.poa, self.ob])
with self.assertRaisesMessage(ValueError,
@ -3492,16 +3484,13 @@ class RelatedLookupTypeTests(TestCase):
A ValueError is raised when the incorrect object type is passed to a
query lookup for backward relations.
"""
with self.assertRaisesMessage(ValueError,
self.error % (self.oa, ObjectB._meta.object_name)):
with self.assertRaisesMessage(ValueError, self.error % (self.oa, ObjectB._meta.object_name)):
ObjectA.objects.filter(objectb__in=[self.oa, self.ob])
with self.assertRaisesMessage(ValueError,
self.error % (self.oa, ObjectB._meta.object_name)):
with self.assertRaisesMessage(ValueError, self.error % (self.oa, ObjectB._meta.object_name)):
ObjectA.objects.exclude(objectb=self.oa)
with self.assertRaisesMessage(ValueError,
self.error % (self.wrong_type, ObjectB._meta.object_name)):
with self.assertRaisesMessage(ValueError, self.error % (self.wrong_type, ObjectB._meta.object_name)):
ObjectA.objects.get(objectb=self.wrong_type)
def test_correct_lookup(self):

View File

@ -195,10 +195,11 @@ class SyndicationFeedTest(FeedTestCase):
self.assertEqual(len(enclosures), 1)
def test_rss2_multiple_enclosures(self):
with self.assertRaisesMessage(ValueError, (
with self.assertRaisesMessage(
ValueError,
"RSS feed items may only have one enclosure, see "
"http://www.rssboard.org/rss-profile#element-channel-item-enclosure"
)):
):
self.client.get('/syndication/rss2/multiple-enclosure/')
def test_rss091_feed(self):
@ -530,9 +531,8 @@ class SyndicationFeedTest(FeedTestCase):
class FeedgeneratorTestCase(TestCase):
def test_add_item_warns_when_enclosure_kwarg_is_used(self):
feed = SyndicationFeed(title='Example', link='http://example.com', description='Foo')
with self.assertRaisesMessage(RemovedInDjango20Warning, (
'The enclosure keyword argument is deprecated, use enclosures instead.'
)):
msg = 'The enclosure keyword argument is deprecated, use enclosures instead.'
with self.assertRaisesMessage(RemovedInDjango20Warning, msg):
feed.add_item(
title='Example Item',
link='https://example.com/item',