summaryrefslogtreecommitdiff
path: root/tests/aggregation_regress
diff options
context:
space:
mode:
authorHasan <hasan.r67@gmail.com>2016-01-17 14:56:39 +0330
committerTim Graham <timograham@gmail.com>2016-01-29 12:32:18 -0500
commit3d0dcd7f5af378d3ab6adb303b913e6c7b2e0ee5 (patch)
tree0d1074cc65a72096e44a4165611fddfc5b7ef7fb /tests/aggregation_regress
parent575706331bec4bf58ce36a9540c4c61fca49025b (diff)
downloaddjango-3d0dcd7f5af378d3ab6adb303b913e6c7b2e0ee5.tar.gz
Refs #26022 -- Used context manager version of assertRaises in tests.
Diffstat (limited to 'tests/aggregation_regress')
-rw-r--r--tests/aggregation_regress/tests.py40
1 files changed, 16 insertions, 24 deletions
diff --git a/tests/aggregation_regress/tests.py b/tests/aggregation_regress/tests.py
index 1373594276..7068b86f6a 100644
--- a/tests/aggregation_regress/tests.py
+++ b/tests/aggregation_regress/tests.py
@@ -376,20 +376,14 @@ class AggregationTests(TestCase):
def test_field_error(self):
# Bad field requests in aggregates are caught and reported
- self.assertRaises(
- FieldError,
- lambda: Book.objects.all().aggregate(num_authors=Count('foo'))
- )
+ with self.assertRaises(FieldError):
+ Book.objects.all().aggregate(num_authors=Count('foo'))
- self.assertRaises(
- FieldError,
- lambda: Book.objects.all().annotate(num_authors=Count('foo'))
- )
+ with self.assertRaises(FieldError):
+ Book.objects.all().annotate(num_authors=Count('foo'))
- self.assertRaises(
- FieldError,
- lambda: Book.objects.all().annotate(num_authors=Count('authors__id')).aggregate(Max('foo'))
- )
+ with self.assertRaises(FieldError):
+ Book.objects.all().annotate(num_authors=Count('authors__id')).aggregate(Max('foo'))
def test_more(self):
# Old-style count aggregations can be mixed with new-style
@@ -698,21 +692,20 @@ class AggregationTests(TestCase):
def test_duplicate_alias(self):
# Regression for #11256 - duplicating a default alias raises ValueError.
- self.assertRaises(
- ValueError,
- Book.objects.all().annotate,
- Avg('authors__age'), authors__age__avg=Avg('authors__age')
- )
+ with self.assertRaises(ValueError):
+ Book.objects.all().annotate(Avg('authors__age'), authors__age__avg=Avg('authors__age'))
def test_field_name_conflict(self):
# Regression for #11256 - providing an aggregate name
# that conflicts with a field name on the model raises ValueError
- self.assertRaises(ValueError, Author.objects.annotate, age=Avg('friends__age'))
+ with self.assertRaises(ValueError):
+ Author.objects.annotate(age=Avg('friends__age'))
def test_m2m_name_conflict(self):
# Regression for #11256 - providing an aggregate name
# that conflicts with an m2m name on the model raises ValueError
- self.assertRaises(ValueError, Author.objects.annotate, friends=Count('friends'))
+ with self.assertRaises(ValueError):
+ Author.objects.annotate(friends=Count('friends'))
def test_values_queryset_non_conflict(self):
# Regression for #14707 -- If you're using a values query set, some potential conflicts are avoided.
@@ -739,7 +732,8 @@ class AggregationTests(TestCase):
def test_reverse_relation_name_conflict(self):
# Regression for #11256 - providing an aggregate name
# that conflicts with a reverse-related name on the model raises ValueError
- self.assertRaises(ValueError, Author.objects.annotate, book_contact_set=Avg('friends__age'))
+ with self.assertRaises(ValueError):
+ Author.objects.annotate(book_contact_set=Avg('friends__age'))
def test_pickle(self):
# Regression for #10197 -- Queries with aggregates can be pickled.
@@ -900,10 +894,8 @@ class AggregationTests(TestCase):
# Regression for #10766 - Shouldn't be able to reference an aggregate
# fields in an aggregate() call.
- self.assertRaises(
- FieldError,
- lambda: Book.objects.annotate(mean_age=Avg('authors__age')).annotate(Avg('mean_age'))
- )
+ with self.assertRaises(FieldError):
+ Book.objects.annotate(mean_age=Avg('authors__age')).annotate(Avg('mean_age'))
def test_empty_filter_count(self):
self.assertEqual(