Fixed #24714 -- Used more specific assertions than assertEqual in tests.

This commit is contained in:
Alasdair Nicol 2015-04-27 15:59:16 +01:00 committed by Tim Graham
parent 3b133ffb8b
commit eaeea6f947
17 changed files with 83 additions and 82 deletions

View file

@ -118,7 +118,7 @@ class DataSourceTest(unittest.TestCase):
# Now checking the field names.
flds = layer.fields
for f in flds:
self.assertEqual(True, f in source.fields)
self.assertIn(f, source.fields)
# Negative FIDs are not allowed.
self.assertRaises(OGRIndexError, layer.__getitem__, -1)
@ -199,7 +199,7 @@ class DataSourceTest(unittest.TestCase):
# Testing Feature.__iter__
for fld in feat:
self.assertEqual(True, fld.name in source.fields.keys())
self.assertIn(fld.name, source.fields.keys())
def test05_geometries(self):
"Testing Geometries from Data Source Features."
@ -229,7 +229,7 @@ class DataSourceTest(unittest.TestCase):
lyr = ds[0]
# When not set, it should be None.
self.assertEqual(None, lyr.spatial_filter)
self.assertIsNone(lyr.spatial_filter)
# Must be set a/an OGRGeometry or 4-tuple.
self.assertRaises(TypeError, lyr._set_spatial_filter, 'foo')

View file

@ -255,4 +255,4 @@ class SpatialRefTest(unittest.TestCase):
self.assertEqual('WGS_1984', s1['DATUM'])
self.assertEqual('EPSG', s1['AUTHORITY'])
self.assertEqual(4326, int(s1['AUTHORITY', 1]))
self.assertEqual(None, s1['FOOBAR'])
self.assertIsNone(s1['FOOBAR'])

View file

@ -227,8 +227,8 @@ class GEOSTest(unittest.TestCase, TestDataMixin):
self.assertEqual(pnt.geom_typeid, 0)
self.assertEqual(p.x, pnt.x)
self.assertEqual(p.y, pnt.y)
self.assertEqual(True, pnt == fromstr(p.wkt))
self.assertEqual(False, pnt == prev)
self.assertEqual(pnt, fromstr(p.wkt))
self.assertEqual(False, pnt == prev) # Use assertEqual to test __eq__
# Making sure that the point's X, Y components are what we expect
self.assertAlmostEqual(p.x, pnt.tuple[0], 9)
@ -244,7 +244,7 @@ class GEOSTest(unittest.TestCase, TestDataMixin):
set_tup2 = (5.23, 2.71, 3.14)
else:
self.assertEqual(False, pnt.hasz)
self.assertEqual(None, pnt.z)
self.assertIsNone(pnt.z)
tup_args = (p.x, p.y)
set_tup1 = (2.71, 3.14)
set_tup2 = (3.14, 2.71)
@ -255,8 +255,8 @@ class GEOSTest(unittest.TestCase, TestDataMixin):
# Now testing the different constructors
pnt2 = Point(tup_args) # e.g., Point((1, 2))
pnt3 = Point(*tup_args) # e.g., Point(1, 2)
self.assertEqual(True, pnt == pnt2)
self.assertEqual(True, pnt == pnt3)
self.assertEqual(pnt, pnt2)
self.assertEqual(pnt, pnt3)
# Now testing setting the x and y
pnt.y = 3.14
@ -305,8 +305,8 @@ class GEOSTest(unittest.TestCase, TestDataMixin):
if hasattr(l, 'tup'):
self.assertEqual(l.tup, ls.tuple)
self.assertEqual(True, ls == fromstr(l.wkt))
self.assertEqual(False, ls == prev)
self.assertEqual(ls, fromstr(l.wkt))
self.assertEqual(False, ls == prev) # Use assertEqual to test __eq__
self.assertRaises(GEOSIndexError, ls.__getitem__, len(ls))
prev = ls
@ -330,8 +330,8 @@ class GEOSTest(unittest.TestCase, TestDataMixin):
self.assertAlmostEqual(l.centroid[0], ml.centroid.x, 9)
self.assertAlmostEqual(l.centroid[1], ml.centroid.y, 9)
self.assertEqual(True, ml == fromstr(l.wkt))
self.assertEqual(False, ml == prev)
self.assertEqual(ml, fromstr(l.wkt))
self.assertEqual(False, ml == prev) # Use assertEqual to test __eq__
prev = ml
for ls in ml:
@ -394,9 +394,10 @@ class GEOSTest(unittest.TestCase, TestDataMixin):
self.assertAlmostEqual(p.centroid[1], poly.centroid.tuple[1], 9)
# Testing the geometry equivalence
self.assertEqual(True, poly == fromstr(p.wkt))
self.assertEqual(False, poly == prev) # Should not be equal to previous geometry
self.assertEqual(True, poly != prev)
self.assertEqual(poly, fromstr(p.wkt))
# Should not be equal to previous geometry
self.assertEqual(False, poly == prev) # Use assertEqual to test __eq__
self.assertNotEqual(poly, prev) # Use assertNotEqual to test __ne__
# Testing the exterior ring
ring = poly.exterior_ring

View file

@ -288,7 +288,7 @@ class RelatedGeoModelTest(TestCase):
Book.objects.create(title='Without Author')
b = Book.objects.select_related('author').get(title='Without Author')
# Should be `None`, and not a 'dummy' model.
self.assertEqual(None, b.author)
self.assertIsNone(b.author)
@skipUnlessDBFeature("supports_collect_aggr")
@ignore_warnings(category=RemovedInDjango20Warning)

View file

@ -32,16 +32,16 @@ class GeoIPTest(unittest.TestCase):
g3 = GeoIP.open(path, 0) # MaxMind Python API syntax.
for g in (g1, g2, g3):
self.assertEqual(True, bool(g._country))
self.assertEqual(True, bool(g._city))
self.assertTrue(g._country)
self.assertTrue(g._city)
# Only passing in the location of one database.
city = os.path.join(path, 'GeoLiteCity.dat')
cntry = os.path.join(path, 'GeoIP.dat')
g4 = GeoIP(city, country='')
self.assertEqual(None, g4._country)
self.assertIsNone(g4._country)
g5 = GeoIP(cntry, city='')
self.assertEqual(None, g5._city)
self.assertIsNone(g5._city)
# Improper parameters.
bad_params = (23, 'foo', 15.23)

View file

@ -56,7 +56,7 @@ class SpatialRefSysTest(unittest.TestCase):
# the testing with the 'startswith' flag.
auth_name, oracle_flag = sd['auth_name']
if postgis or (oracle and oracle_flag):
self.assertEqual(True, srs.auth_name.startswith(auth_name))
self.assertTrue(srs.auth_name.startswith(auth_name))
self.assertEqual(sd['auth_srid'], srs.auth_srid)
@ -71,14 +71,14 @@ class SpatialRefSysTest(unittest.TestCase):
"""
for sd in test_srs:
sr = SpatialRefSys.objects.get(srid=sd['srid'])
self.assertEqual(True, sr.spheroid.startswith(sd['spheroid']))
self.assertTrue(sr.spheroid.startswith(sd['spheroid']))
self.assertEqual(sd['geographic'], sr.geographic)
self.assertEqual(sd['projected'], sr.projected)
if not (spatialite and not sd['spatialite']):
# Can't get 'NAD83 / Texas South Central' from PROJ.4 string
# on SpatiaLite
self.assertEqual(True, sr.name.startswith(sd['name']))
self.assertTrue(sr.name.startswith(sd['name']))
# Testing the SpatialReference object directly.
if postgis or spatialite: