Made multiline assertRaises* conform to flake8's E128 rule.
This commit is contained in:
parent
6eb3ce11e4
commit
04de436932
|
@ -111,8 +111,9 @@ class EarliestOrLatestTests(TestCase):
|
||||||
Article.objects.model._meta.get_latest_by = None
|
Article.objects.model._meta.get_latest_by = None
|
||||||
with self.assertRaisesMessage(
|
with self.assertRaisesMessage(
|
||||||
AssertionError,
|
AssertionError,
|
||||||
"earliest() and latest() require either a field_name parameter or "
|
"earliest() and latest() require either a field_name parameter or "
|
||||||
"'get_latest_by' in the model"):
|
"'get_latest_by' in the model"
|
||||||
|
):
|
||||||
Article.objects.latest()
|
Article.objects.latest()
|
||||||
|
|
||||||
def test_latest_manual(self):
|
def test_latest_manual(self):
|
||||||
|
|
|
@ -508,9 +508,11 @@ class JsonResponseTests(SimpleTestCase):
|
||||||
self.assertEqual(json.loads(response.content.decode()), data)
|
self.assertEqual(json.loads(response.content.decode()), data)
|
||||||
|
|
||||||
def test_json_response_raises_type_error_with_default_setting(self):
|
def test_json_response_raises_type_error_with_default_setting(self):
|
||||||
with self.assertRaisesMessage(TypeError,
|
with self.assertRaisesMessage(
|
||||||
'In order to allow non-dict objects to be serialized set the '
|
TypeError,
|
||||||
'safe parameter to False'):
|
'In order to allow non-dict objects to be serialized set the '
|
||||||
|
'safe parameter to False'
|
||||||
|
):
|
||||||
JsonResponse([1, 2, 3])
|
JsonResponse([1, 2, 3])
|
||||||
|
|
||||||
def test_json_response_text(self):
|
def test_json_response_text(self):
|
||||||
|
|
|
@ -1318,12 +1318,10 @@ class Queries3Tests(BaseQuerysetTest):
|
||||||
Item.objects.datetimes('name', 'month')
|
Item.objects.datetimes('name', 'month')
|
||||||
|
|
||||||
def test_ticket22023(self):
|
def test_ticket22023(self):
|
||||||
with self.assertRaisesMessage(TypeError,
|
with self.assertRaisesMessage(TypeError, "Cannot call only() after .values() or .values_list()"):
|
||||||
"Cannot call only() after .values() or .values_list()"):
|
|
||||||
Valid.objects.values().only()
|
Valid.objects.values().only()
|
||||||
|
|
||||||
with self.assertRaisesMessage(TypeError,
|
with self.assertRaisesMessage(TypeError, "Cannot call defer() after .values() or .values_list()"):
|
||||||
"Cannot call defer() after .values() or .values_list()"):
|
|
||||||
Valid.objects.values().defer()
|
Valid.objects.values().defer()
|
||||||
|
|
||||||
|
|
||||||
|
@ -2244,9 +2242,8 @@ class ValuesQuerysetTests(BaseQuerysetTest):
|
||||||
|
|
||||||
def test_field_error_values_list(self):
|
def test_field_error_values_list(self):
|
||||||
# see #23443
|
# see #23443
|
||||||
with self.assertRaisesMessage(FieldError,
|
msg = "Cannot resolve keyword %r into field. Join on 'name' not permitted." % 'foo'
|
||||||
"Cannot resolve keyword %r into field."
|
with self.assertRaisesMessage(FieldError, msg):
|
||||||
" Join on 'name' not permitted." % 'foo'):
|
|
||||||
Tag.objects.values_list('name__foo')
|
Tag.objects.values_list('name__foo')
|
||||||
|
|
||||||
|
|
||||||
|
@ -3462,25 +3459,20 @@ class RelatedLookupTypeTests(TestCase):
|
||||||
query lookup.
|
query lookup.
|
||||||
"""
|
"""
|
||||||
# Passing incorrect object type
|
# Passing incorrect object type
|
||||||
with self.assertRaisesMessage(ValueError,
|
with self.assertRaisesMessage(ValueError, self.error % (self.wrong_type, ObjectA._meta.object_name)):
|
||||||
self.error % (self.wrong_type, ObjectA._meta.object_name)):
|
|
||||||
ObjectB.objects.get(objecta=self.wrong_type)
|
ObjectB.objects.get(objecta=self.wrong_type)
|
||||||
|
|
||||||
with self.assertRaisesMessage(ValueError,
|
with self.assertRaisesMessage(ValueError, self.error % (self.wrong_type, ObjectA._meta.object_name)):
|
||||||
self.error % (self.wrong_type, ObjectA._meta.object_name)):
|
|
||||||
ObjectB.objects.filter(objecta__in=[self.wrong_type])
|
ObjectB.objects.filter(objecta__in=[self.wrong_type])
|
||||||
|
|
||||||
with self.assertRaisesMessage(ValueError,
|
with self.assertRaisesMessage(ValueError, self.error % (self.wrong_type, ObjectA._meta.object_name)):
|
||||||
self.error % (self.wrong_type, ObjectA._meta.object_name)):
|
|
||||||
ObjectB.objects.filter(objecta=self.wrong_type)
|
ObjectB.objects.filter(objecta=self.wrong_type)
|
||||||
|
|
||||||
with self.assertRaisesMessage(ValueError,
|
with self.assertRaisesMessage(ValueError, self.error % (self.wrong_type, ObjectB._meta.object_name)):
|
||||||
self.error % (self.wrong_type, ObjectB._meta.object_name)):
|
|
||||||
ObjectA.objects.filter(objectb__in=[self.wrong_type, self.ob])
|
ObjectA.objects.filter(objectb__in=[self.wrong_type, self.ob])
|
||||||
|
|
||||||
# Passing an object of the class on which query is done.
|
# Passing an object of the class on which query is done.
|
||||||
with self.assertRaisesMessage(ValueError,
|
with self.assertRaisesMessage(ValueError, self.error % (self.ob, ObjectA._meta.object_name)):
|
||||||
self.error % (self.ob, ObjectA._meta.object_name)):
|
|
||||||
ObjectB.objects.filter(objecta__in=[self.poa, self.ob])
|
ObjectB.objects.filter(objecta__in=[self.poa, self.ob])
|
||||||
|
|
||||||
with self.assertRaisesMessage(ValueError,
|
with self.assertRaisesMessage(ValueError,
|
||||||
|
@ -3492,16 +3484,13 @@ class RelatedLookupTypeTests(TestCase):
|
||||||
A ValueError is raised when the incorrect object type is passed to a
|
A ValueError is raised when the incorrect object type is passed to a
|
||||||
query lookup for backward relations.
|
query lookup for backward relations.
|
||||||
"""
|
"""
|
||||||
with self.assertRaisesMessage(ValueError,
|
with self.assertRaisesMessage(ValueError, self.error % (self.oa, ObjectB._meta.object_name)):
|
||||||
self.error % (self.oa, ObjectB._meta.object_name)):
|
|
||||||
ObjectA.objects.filter(objectb__in=[self.oa, self.ob])
|
ObjectA.objects.filter(objectb__in=[self.oa, self.ob])
|
||||||
|
|
||||||
with self.assertRaisesMessage(ValueError,
|
with self.assertRaisesMessage(ValueError, self.error % (self.oa, ObjectB._meta.object_name)):
|
||||||
self.error % (self.oa, ObjectB._meta.object_name)):
|
|
||||||
ObjectA.objects.exclude(objectb=self.oa)
|
ObjectA.objects.exclude(objectb=self.oa)
|
||||||
|
|
||||||
with self.assertRaisesMessage(ValueError,
|
with self.assertRaisesMessage(ValueError, self.error % (self.wrong_type, ObjectB._meta.object_name)):
|
||||||
self.error % (self.wrong_type, ObjectB._meta.object_name)):
|
|
||||||
ObjectA.objects.get(objectb=self.wrong_type)
|
ObjectA.objects.get(objectb=self.wrong_type)
|
||||||
|
|
||||||
def test_correct_lookup(self):
|
def test_correct_lookup(self):
|
||||||
|
|
|
@ -195,10 +195,11 @@ class SyndicationFeedTest(FeedTestCase):
|
||||||
self.assertEqual(len(enclosures), 1)
|
self.assertEqual(len(enclosures), 1)
|
||||||
|
|
||||||
def test_rss2_multiple_enclosures(self):
|
def test_rss2_multiple_enclosures(self):
|
||||||
with self.assertRaisesMessage(ValueError, (
|
with self.assertRaisesMessage(
|
||||||
|
ValueError,
|
||||||
"RSS feed items may only have one enclosure, see "
|
"RSS feed items may only have one enclosure, see "
|
||||||
"http://www.rssboard.org/rss-profile#element-channel-item-enclosure"
|
"http://www.rssboard.org/rss-profile#element-channel-item-enclosure"
|
||||||
)):
|
):
|
||||||
self.client.get('/syndication/rss2/multiple-enclosure/')
|
self.client.get('/syndication/rss2/multiple-enclosure/')
|
||||||
|
|
||||||
def test_rss091_feed(self):
|
def test_rss091_feed(self):
|
||||||
|
@ -530,9 +531,8 @@ class SyndicationFeedTest(FeedTestCase):
|
||||||
class FeedgeneratorTestCase(TestCase):
|
class FeedgeneratorTestCase(TestCase):
|
||||||
def test_add_item_warns_when_enclosure_kwarg_is_used(self):
|
def test_add_item_warns_when_enclosure_kwarg_is_used(self):
|
||||||
feed = SyndicationFeed(title='Example', link='http://example.com', description='Foo')
|
feed = SyndicationFeed(title='Example', link='http://example.com', description='Foo')
|
||||||
with self.assertRaisesMessage(RemovedInDjango20Warning, (
|
msg = 'The enclosure keyword argument is deprecated, use enclosures instead.'
|
||||||
'The enclosure keyword argument is deprecated, use enclosures instead.'
|
with self.assertRaisesMessage(RemovedInDjango20Warning, msg):
|
||||||
)):
|
|
||||||
feed.add_item(
|
feed.add_item(
|
||||||
title='Example Item',
|
title='Example Item',
|
||||||
link='https://example.com/item',
|
link='https://example.com/item',
|
||||||
|
|
Loading…
Reference in New Issue