summaryrefslogtreecommitdiff
path: root/tests/gis_tests/distapp/tests.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/gis_tests/distapp/tests.py')
-rw-r--r--tests/gis_tests/distapp/tests.py63
1 files changed, 35 insertions, 28 deletions
diff --git a/tests/gis_tests/distapp/tests.py b/tests/gis_tests/distapp/tests.py
index 70e1f98d20..eab144b3e4 100644
--- a/tests/gis_tests/distapp/tests.py
+++ b/tests/gis_tests/distapp/tests.py
@@ -68,32 +68,35 @@ class DistanceTest(TestCase):
qs1 = SouthTexasCity.objects.filter(point__dwithin=(self.stx_pnt, dist1))
qs2 = SouthTexasCityFt.objects.filter(point__dwithin=(self.stx_pnt, dist2))
for qs in qs1, qs2:
- self.assertEqual(tx_cities, self.get_names(qs))
+ with self.subTest(dist=dist, qs=qs):
+ self.assertEqual(tx_cities, self.get_names(qs))
# Now performing the `dwithin` queries on a geodetic coordinate system.
for dist in au_dists:
- if isinstance(dist, D) and not oracle:
- type_error = True
- else:
- type_error = False
-
- if isinstance(dist, tuple):
- if oracle or spatialite:
- # Result in meters
- dist = dist[1]
+ with self.subTest(dist=dist):
+ if isinstance(dist, D) and not oracle:
+ type_error = True
else:
- # Result in units of the field
- dist = dist[0]
+ type_error = False
- # Creating the query set.
- qs = AustraliaCity.objects.order_by('name')
- if type_error:
- # A ValueError should be raised on PostGIS when trying to pass
- # Distance objects into a DWithin query using a geodetic field.
- with self.assertRaises(ValueError):
- AustraliaCity.objects.filter(point__dwithin=(self.au_pnt, dist)).count()
- else:
- self.assertEqual(au_cities, self.get_names(qs.filter(point__dwithin=(self.au_pnt, dist))))
+ if isinstance(dist, tuple):
+ if oracle or spatialite:
+ # Result in meters
+ dist = dist[1]
+ else:
+ # Result in units of the field
+ dist = dist[0]
+
+ # Creating the query set.
+ qs = AustraliaCity.objects.order_by('name')
+ if type_error:
+ # A ValueError should be raised on PostGIS when trying to
+ # pass Distance objects into a DWithin query using a
+ # geodetic field.
+ with self.assertRaises(ValueError):
+ AustraliaCity.objects.filter(point__dwithin=(self.au_pnt, dist)).count()
+ else:
+ self.assertEqual(au_cities, self.get_names(qs.filter(point__dwithin=(self.au_pnt, dist))))
@skipUnlessDBFeature("supports_distances_lookups")
def test_distance_lookups(self):
@@ -298,8 +301,9 @@ class DistanceFunctionsTests(TestCase):
# Ensuring expected distances are returned for each distance queryset.
for qs in dist_qs:
for i, c in enumerate(qs):
- self.assertAlmostEqual(m_distances[i], c.distance.m, tol)
- self.assertAlmostEqual(ft_distances[i], c.distance.survey_ft, tol)
+ with self.subTest(c=c):
+ self.assertAlmostEqual(m_distances[i], c.distance.m, tol)
+ self.assertAlmostEqual(ft_distances[i], c.distance.survey_ft, tol)
@skipUnlessDBFeature("has_Distance_function", "supports_distance_geodetic")
def test_distance_geodetic(self):
@@ -318,9 +322,10 @@ class DistanceFunctionsTests(TestCase):
40435.4335201384, 0, 68272.3896586844, 12375.0643697706, 0]
qs = AustraliaCity.objects.annotate(distance=Distance('point', ls)).order_by('name')
for city, distance in zip(qs, distances):
- # Testing equivalence to within a meter (kilometer on SpatiaLite).
- tol = -3 if spatialite else 0
- self.assertAlmostEqual(distance, city.distance.m, tol)
+ with self.subTest(city=city, distance=distance):
+ # Testing equivalence to within a meter (kilometer on SpatiaLite).
+ tol = -3 if spatialite else 0
+ self.assertAlmostEqual(distance, city.distance.m, tol)
@skipUnlessDBFeature("has_Distance_function", "supports_distance_geodetic")
def test_distance_geodetic_spheroid(self):
@@ -349,14 +354,16 @@ class DistanceFunctionsTests(TestCase):
distance=Distance('point', hillsdale.point, spheroid=True)
).order_by('id')
for i, c in enumerate(qs):
- self.assertAlmostEqual(spheroid_distances[i], c.distance.m, tol)
+ with self.subTest(c=c):
+ self.assertAlmostEqual(spheroid_distances[i], c.distance.m, tol)
if postgis or spatialite:
# PostGIS uses sphere-only distances by default, testing these as well.
qs = AustraliaCity.objects.exclude(id=hillsdale.id).annotate(
distance=Distance('point', hillsdale.point)
).order_by('id')
for i, c in enumerate(qs):
- self.assertAlmostEqual(sphere_distances[i], c.distance.m, tol)
+ with self.subTest(c=c):
+ self.assertAlmostEqual(sphere_distances[i], c.distance.m, tol)
@skipIfDBFeature("supports_distance_geodetic")
@skipUnlessDBFeature("has_Distance_function")