diff --git a/django/contrib/auth/tests/test_views.py b/django/contrib/auth/tests/test_views.py index fa8b38f4c5..3dd8953d88 100644 --- a/django/contrib/auth/tests/test_views.py +++ b/django/contrib/auth/tests/test_views.py @@ -475,8 +475,7 @@ class LoginTest(AuthViewsTestCase): self.assertEqual(response.context['site_name'], site.name) else: self.assertIsInstance(response.context['site'], RequestSite) - self.assertTrue(isinstance(response.context['form'], AuthenticationForm), - 'Login form is not an AuthenticationForm') + self.assertIsInstance(response.context['form'], AuthenticationForm) def test_security_check(self, password='password'): login_url = reverse('login') diff --git a/django/contrib/formtools/tests/wizard/test_forms.py b/django/contrib/formtools/tests/wizard/test_forms.py index fedb799669..9ae99cc89b 100644 --- a/django/contrib/formtools/tests/wizard/test_forms.py +++ b/django/contrib/formtools/tests/wizard/test_forms.py @@ -246,11 +246,11 @@ class SessionFormTests(TestCase): def test_init(self): request = get_request() testform = SessionWizardView.as_view([('start', Step1)]) - self.assertTrue(isinstance(testform(request), TemplateResponse)) + self.assertIsInstance(testform(request), TemplateResponse) class CookieFormTests(TestCase): def test_init(self): request = get_request() testform = CookieWizardView.as_view([('start', Step1)]) - self.assertTrue(isinstance(testform(request), TemplateResponse)) + self.assertIsInstance(testform(request), TemplateResponse) diff --git a/django/contrib/gis/geoip/tests.py b/django/contrib/gis/geoip/tests.py index 9631a192ab..06558e0093 100644 --- a/django/contrib/gis/geoip/tests.py +++ b/django/contrib/gis/geoip/tests.py @@ -106,7 +106,7 @@ class GeoIPTest(unittest.TestCase): self.assertEqual('TX', d['region']) self.assertEqual(713, d['area_code']) geom = g.geos(query) - self.assertTrue(isinstance(geom, GEOSGeometry)) + self.assertIsInstance(geom, GEOSGeometry) lon, lat = (-95.4010, 29.7079) lat_lon = g.lat_lon(query) lat_lon = (lat_lon[1], lat_lon[0]) diff --git a/django/contrib/gis/tests/geoapp/tests.py b/django/contrib/gis/tests/geoapp/tests.py index 3501fb6a7f..2e572c4052 100644 --- a/django/contrib/gis/tests/geoapp/tests.py +++ b/django/contrib/gis/tests/geoapp/tests.py @@ -201,7 +201,7 @@ class GeoModelTest(TestCase): as_text = 'ST_AsText' if postgis else 'asText' cities2 = City.objects.raw('select id, name, %s(point) from geoapp_city' % as_text) self.assertEqual(len(cities1), len(list(cities2))) - self.assertTrue(isinstance(cities2[0].point, Point)) + self.assertIsInstance(cities2[0].point, Point) @skipUnless(HAS_GEOS and HAS_SPATIAL_DB, "Geos and spatial db are required.") diff --git a/django/contrib/gis/tests/relatedapp/tests.py b/django/contrib/gis/tests/relatedapp/tests.py index 67059120a7..6f0c568803 100644 --- a/django/contrib/gis/tests/relatedapp/tests.py +++ b/django/contrib/gis/tests/relatedapp/tests.py @@ -179,8 +179,8 @@ class RelatedGeoModelTest(TestCase): for m, d, t in zip(gqs, gvqs, gvlqs): # The values should be Geometry objects and not raw strings returned # by the spatial database. - self.assertTrue(isinstance(d['point'], Geometry)) - self.assertTrue(isinstance(t[1], Geometry)) + self.assertIsInstance(d['point'], Geometry) + self.assertIsInstance(t[1], Geometry) self.assertEqual(m.point, d['point']) self.assertEqual(m.point, t[1]) @@ -255,7 +255,7 @@ class RelatedGeoModelTest(TestCase): qs = Location.objects.filter(id=5).annotate(num_cities=Count('city')).values('id', 'point', 'num_cities') self.assertEqual(1, len(qs)) self.assertEqual(2, qs[0]['num_cities']) - self.assertTrue(isinstance(qs[0]['point'], GEOSGeometry)) + self.assertIsInstance(qs[0]['point'], GEOSGeometry) # TODO: The phantom model does appear on Oracle. @no_oracle diff --git a/django/contrib/gis/tests/test_measure.py b/django/contrib/gis/tests/test_measure.py index 643a1b1794..94284fb28a 100644 --- a/django/contrib/gis/tests/test_measure.py +++ b/django/contrib/gis/tests/test_measure.py @@ -93,7 +93,7 @@ class DistanceTest(unittest.TestCase): self.assertEqual(d5, 50) a5 = d1 * D(m=10) - self.assertTrue(isinstance(a5, Area)) + self.assertIsInstance(a5, Area) self.assertEqual(a5.sq_m, 100 * 10) with self.assertRaises(TypeError): diff --git a/django/contrib/sites/tests.py b/django/contrib/sites/tests.py index 8f80087c5b..fadd4aa81d 100644 --- a/django/contrib/sites/tests.py +++ b/django/contrib/sites/tests.py @@ -26,7 +26,7 @@ class SitesFrameworkTests(TestCase): def test_site_manager(self): # Make sure that get_current() does not return a deleted Site object. s = Site.objects.get_current() - self.assertTrue(isinstance(s, Site)) + self.assertIsInstance(s, Site) s.delete() self.assertRaises(ObjectDoesNotExist, Site.objects.get_current) @@ -57,7 +57,7 @@ class SitesFrameworkTests(TestCase): "SERVER_PORT": "80", } site = get_current_site(request) - self.assertTrue(isinstance(site, Site)) + self.assertIsInstance(site, Site) self.assertEqual(site.id, settings.SITE_ID) # Test that an exception is raised if the sites framework is installed @@ -68,7 +68,7 @@ class SitesFrameworkTests(TestCase): # A RequestSite is returned if the sites framework is not installed with self.modify_settings(INSTALLED_APPS={'remove': 'django.contrib.sites'}): site = get_current_site(request) - self.assertTrue(isinstance(site, RequestSite)) + self.assertIsInstance(site, RequestSite) self.assertEqual(site.name, "example.com") def test_domain_name_with_whitespaces(self): diff --git a/django/test/testcases.py b/django/test/testcases.py index 354c4d3963..95d0d8e399 100644 --- a/django/test/testcases.py +++ b/django/test/testcases.py @@ -620,8 +620,8 @@ class SimpleTestCase(unittest.TestCase): # test that max_length and min_length are always accepted if issubclass(fieldclass, CharField): field_kwargs.update({'min_length': 2, 'max_length': 20}) - self.assertTrue(isinstance(fieldclass(*field_args, **field_kwargs), - fieldclass)) + self.assertIsInstance(fieldclass(*field_args, **field_kwargs), + fieldclass) def assertHTMLEqual(self, html1, html2, msg=None): """ diff --git a/tests/backends/tests.py b/tests/backends/tests.py index c8c1875e26..ee1e56676f 100644 --- a/tests/backends/tests.py +++ b/tests/backends/tests.py @@ -646,7 +646,7 @@ class BackendTestCase(TestCase): Test that cursors can be used as a context manager """ with connection.cursor() as cursor: - self.assertTrue(isinstance(cursor, CursorWrapper)) + self.assertIsInstance(cursor, CursorWrapper) # Both InterfaceError and ProgrammingError seem to be used when # accessing closed cursor (psycopg2 has InterfaceError, rest seem # to use ProgrammingError). @@ -661,7 +661,7 @@ class BackendTestCase(TestCase): # psycopg2 offers us a way to check that by closed attribute. # So, run only on psycopg2 for that reason. with connection.cursor() as cursor: - self.assertTrue(isinstance(cursor, CursorWrapper)) + self.assertIsInstance(cursor, CursorWrapper) self.assertTrue(cursor.closed) diff --git a/tests/forms_tests/tests/test_forms.py b/tests/forms_tests/tests/test_forms.py index d2e80d5b4d..2db40ef55c 100644 --- a/tests/forms_tests/tests/test_forms.py +++ b/tests/forms_tests/tests/test_forms.py @@ -1908,7 +1908,7 @@ class FormsTestCase(TestCase): field = ChoicesField() field2 = copy.deepcopy(field) - self.assertTrue(isinstance(field2, ChoicesField)) + self.assertIsInstance(field2, ChoicesField) self.assertFalse(id(field2.fields) == id(field.fields)) self.assertFalse(id(field2.fields[0].choices) == id(field.fields[0].choices)) @@ -2152,7 +2152,7 @@ class FormsTestCase(TestCase): e.append('Foo') e.append(ValidationError('Foo%(bar)s', code='foobar', params={'bar': 'bar'})) - self.assertTrue(isinstance(e, list)) + self.assertIsInstance(e, list) self.assertIn('Foo', e) self.assertIn('Foo', forms.ValidationError(e)) diff --git a/tests/model_fields/tests.py b/tests/model_fields/tests.py index 754ad20e5d..e8c798adc5 100644 --- a/tests/model_fields/tests.py +++ b/tests/model_fields/tests.py @@ -298,7 +298,7 @@ class BooleanFieldTests(unittest.TestCase): # conversions are applied with an offset b5 = BooleanModel.objects.all().extra( select={'string_col': 'string'})[0] - self.assertFalse(isinstance(b5.pk, bool)) + self.assertNotIsInstance(b5.pk, bool) def test_select_related(self): """