Skip to content

Commit

Permalink
Removed references to the deprecated assertRaisesRegexp method.
Browse files Browse the repository at this point in the history
  • Loading branch information
charettes committed Nov 16, 2014
1 parent 5b9470e commit 68ef44c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
13 changes: 7 additions & 6 deletions tests/aggregation/tests.py
Expand Up @@ -17,6 +17,7 @@
from django.test import TestCase
from django.test.utils import Approximate
from django.test.utils import CaptureQueriesContext
from django.utils import six
from django.utils.deprecation import RemovedInDjango20Warning

from .models import Author, Publisher, Book, Store
Expand Down Expand Up @@ -693,7 +694,7 @@ class ComplexAggregateTestCase(TestCase):
fixtures = ["aggregation.json"]

def test_nonaggregate_aggregation_throws(self):
with self.assertRaisesRegexp(TypeError, 'fail is not an aggregate expression'):
with six.assertRaisesRegex(self, TypeError, 'fail is not an aggregate expression'):
Book.objects.aggregate(fail=F('price'))

def test_nonfield_annotation(self):
Expand All @@ -703,7 +704,7 @@ def test_nonfield_annotation(self):
self.assertEqual(book.val, 2)

def test_missing_output_field_raises_error(self):
with self.assertRaisesRegexp(FieldError, 'Cannot resolve expression type, unknown output_field'):
with six.assertRaisesRegex(self, FieldError, 'Cannot resolve expression type, unknown output_field'):
Book.objects.annotate(val=Max(Value(2)))[0]

def test_annotation_expressions(self):
Expand Down Expand Up @@ -742,7 +743,7 @@ def test_order_of_precedence(self):
self.assertEqual(p2, {'avg_price': Approximate(53.39, places=2)})

def test_combine_different_types(self):
with self.assertRaisesRegexp(FieldError, 'Expression contains mixed types. You must set output_field'):
with six.assertRaisesRegex(self, FieldError, 'Expression contains mixed types. You must set output_field'):
Book.objects.annotate(sums=Sum('rating') + Sum('pages') + Sum('price')).get(pk=4)

b1 = Book.objects.annotate(sums=Sum(F('rating') + F('pages') + F('price'),
Expand All @@ -758,9 +759,9 @@ def test_combine_different_types(self):
self.assertEqual(b3.sums, Decimal("383.69"))

def test_complex_aggregations_require_kwarg(self):
with self.assertRaisesRegexp(TypeError, 'Complex expressions require an alias'):
with six.assertRaisesRegex(self, TypeError, 'Complex expressions require an alias'):
Author.objects.annotate(Sum(F('age') + F('friends__age')))
with self.assertRaisesRegexp(TypeError, 'Complex aggregates require an alias'):
with six.assertRaisesRegex(self, TypeError, 'Complex aggregates require an alias'):
Author.objects.aggregate(Sum('age') / Count('age'))

def test_aggregate_over_complex_annotation(self):
Expand Down Expand Up @@ -856,7 +857,7 @@ def test_annotate_over_annotate(self):
self.assertEqual(author.sum_age, other_author.sum_age)

def test_annotated_aggregate_over_annotated_aggregate(self):
with self.assertRaisesRegexp(FieldError, "Cannot compute Sum\('id__max'\): 'id__max' is an aggregate"):
with six.assertRaisesRegex(self, FieldError, "Cannot compute Sum\('id__max'\): 'id__max' is an aggregate"):
Book.objects.annotate(Max('id')).annotate(Sum('id__max'))

def test_add_implementation(self):
Expand Down
5 changes: 3 additions & 2 deletions tests/annotations/tests.py
Expand Up @@ -9,6 +9,7 @@
IntegerField, BooleanField, CharField)
from django.db.models.fields import FieldDoesNotExist
from django.test import TestCase
from django.utils import six

from .models import Author, Book, Store, DepartmentStore, Company, Employee

Expand Down Expand Up @@ -75,7 +76,7 @@ def test_filter_agg_with_double_f(self):
self.assertEqual(book.sum_rating, book.rating)

def test_filter_wrong_annotation(self):
with self.assertRaisesRegexp(FieldError, "Cannot resolve keyword .*"):
with six.assertRaisesRegex(self, FieldError, "Cannot resolve keyword .*"):
list(Book.objects.annotate(
sum_rating=Sum('rating')
).filter(sum_rating=F('nope')))
Expand Down Expand Up @@ -137,7 +138,7 @@ def test_defer_annotation(self):
self.assertEqual(book.rating, 5)
self.assertEqual(book.other_rating, 4)

with self.assertRaisesRegexp(FieldDoesNotExist, "\w has no field named u?'other_rating'"):
with six.assertRaisesRegex(self, FieldDoesNotExist, "\w has no field named u?'other_rating'"):
book = qs.defer('other_rating').get(other_rating=4)

def test_mti_annotations(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/expressions/tests.py
Expand Up @@ -384,7 +384,7 @@ def test_complex_expressions(self):
self.assertEqual(Number.objects.get(pk=n.pk).float, Approximate(256.900, places=3))

def test_incorrect_field_expression(self):
with self.assertRaisesRegexp(FieldError, "Cannot resolve keyword u?'nope' into field.*"):
with six.assertRaisesRegex(self, FieldError, "Cannot resolve keyword u?'nope' into field.*"):
list(Employee.objects.filter(firstname=F('nope')))


Expand Down
5 changes: 3 additions & 2 deletions tests/migrations/test_operations.py
Expand Up @@ -15,6 +15,7 @@
from django.db.models.fields import NOT_PROVIDED
from django.db.transaction import atomic
from django.db.utils import IntegrityError, DatabaseError
from django.utils import six

from .test_base import MigrationTestBase

Expand Down Expand Up @@ -1300,13 +1301,13 @@ def test_run_sql_params_invalid(self):
)

with connection.schema_editor() as editor:
self.assertRaisesRegexp(ValueError,
six.assertRaisesRegex(self, ValueError,
"Expected a 2-tuple but got 1",
operation.database_forwards,
"test_runsql", editor, project_state, new_state)

with connection.schema_editor() as editor:
self.assertRaisesRegexp(ValueError,
six.assertRaisesRegex(self, ValueError,
"Expected a 2-tuple but got 3",
operation.database_backwards,
"test_runsql", editor, new_state, project_state)
Expand Down

0 comments on commit 68ef44c

Please sign in to comment.