Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Used more specific test assertions.
  • Loading branch information
aaugustin committed Apr 9, 2014
1 parent 11e7254 commit 2791fbf
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 20 deletions.
3 changes: 1 addition & 2 deletions django/contrib/auth/tests/test_views.py
Expand Up @@ -475,8 +475,7 @@ def test_current_site_in_context_after_login(self):
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')
Expand Down
4 changes: 2 additions & 2 deletions django/contrib/formtools/tests/wizard/test_forms.py
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion django/contrib/gis/geoip/tests.py
Expand Up @@ -106,7 +106,7 @@ def test04_city(self):
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])
Expand Down
2 changes: 1 addition & 1 deletion django/contrib/gis/tests/geoapp/tests.py
Expand Up @@ -201,7 +201,7 @@ def test_raw_sql_query(self):
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.")
Expand Down
6 changes: 3 additions & 3 deletions django/contrib/gis/tests/relatedapp/tests.py
Expand Up @@ -179,8 +179,8 @@ def test07_values(self):
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])

Expand Down Expand Up @@ -255,7 +255,7 @@ def test13c_count(self):
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
Expand Down
2 changes: 1 addition & 1 deletion django/contrib/gis/tests/test_measure.py
Expand Up @@ -93,7 +93,7 @@ def testMultiplication(self):
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):
Expand Down
6 changes: 3 additions & 3 deletions django/contrib/sites/tests.py
Expand Up @@ -26,7 +26,7 @@ def test_save_another(self):
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)

Expand Down Expand Up @@ -57,7 +57,7 @@ def test_get_current_site(self):
"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
Expand All @@ -68,7 +68,7 @@ def test_get_current_site(self):
# 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):
Expand Down
4 changes: 2 additions & 2 deletions django/test/testcases.py
Expand Up @@ -620,8 +620,8 @@ def assertFieldOutput(self, fieldclass, valid, invalid, field_args=None,
# 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):
"""
Expand Down
4 changes: 2 additions & 2 deletions tests/backends/tests.py
Expand Up @@ -646,7 +646,7 @@ def test_cursor_contextmanager(self):
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).
Expand All @@ -661,7 +661,7 @@ def test_cursor_contextmanager_closing(self):
# 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)


Expand Down
4 changes: 2 additions & 2 deletions tests/forms_tests/tests/test_forms.py
Expand Up @@ -1908,7 +1908,7 @@ def __init__(self, fields=(), *args, **kwargs):

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))
Expand Down Expand Up @@ -2152,7 +2152,7 @@ def test_error_list(self):
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))

Expand Down
2 changes: 1 addition & 1 deletion tests/model_fields/tests.py
Expand Up @@ -298,7 +298,7 @@ def test_return_type(self):
# 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):
"""
Expand Down

0 comments on commit 2791fbf

Please sign in to comment.