From 68ef44c565d901945eb74768d439c93678315cf6 Mon Sep 17 00:00:00 2001 From: Simon Charette Date: Sun, 16 Nov 2014 02:05:54 +0100 Subject: [PATCH] Removed references to the deprecated assertRaisesRegexp method. --- tests/aggregation/tests.py | 13 +++++++------ tests/annotations/tests.py | 5 +++-- tests/expressions/tests.py | 2 +- tests/migrations/test_operations.py | 5 +++-- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/tests/aggregation/tests.py b/tests/aggregation/tests.py index 851ce69db0e..8c6529c73b6 100644 --- a/tests/aggregation/tests.py +++ b/tests/aggregation/tests.py @@ -17,6 +17,7 @@ with warnings.catch_warnings(record=True) as w: 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 @@ -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): @@ -703,7 +704,7 @@ class ComplexAggregateTestCase(TestCase): 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): @@ -742,7 +743,7 @@ class ComplexAggregateTestCase(TestCase): 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'), @@ -758,9 +759,9 @@ class ComplexAggregateTestCase(TestCase): 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): @@ -856,7 +857,7 @@ class ComplexAggregateTestCase(TestCase): 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): diff --git a/tests/annotations/tests.py b/tests/annotations/tests.py index afc23b85dfd..b0886266f60 100644 --- a/tests/annotations/tests.py +++ b/tests/annotations/tests.py @@ -9,6 +9,7 @@ from django.db.models import ( 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 @@ -75,7 +76,7 @@ class NonAggregateAnnotationTestCase(TestCase): 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'))) @@ -137,7 +138,7 @@ class NonAggregateAnnotationTestCase(TestCase): 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): diff --git a/tests/expressions/tests.py b/tests/expressions/tests.py index 2756c8e10d2..4c4f9dd4074 100644 --- a/tests/expressions/tests.py +++ b/tests/expressions/tests.py @@ -384,7 +384,7 @@ class ExpressionsNumericTests(TestCase): 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'))) diff --git a/tests/migrations/test_operations.py b/tests/migrations/test_operations.py index 5aee55fe029..6e7e8d2059a 100644 --- a/tests/migrations/test_operations.py +++ b/tests/migrations/test_operations.py @@ -15,6 +15,7 @@ from django.db.migrations.state import ProjectState 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 @@ -1300,13 +1301,13 @@ class OperationTests(OperationTestBase): ) 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)