diff options
| author | Claude Paroz <claude@2xlibre.net> | 2015-01-25 00:03:02 +0100 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2015-04-22 19:54:17 +0200 |
| commit | 71e20814fcb5983bdc96a6b15765b8f6abd11542 (patch) | |
| tree | 79f567fc49fefcd7241c5172646bebfceea9113e /tests | |
| parent | 44bdbbc316e4e0b2f5d8c7767d04924c9e00f2da (diff) | |
Added MySQL support to GIS functions
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/gis_tests/distapp/tests.py | 11 | ||||
| -rw-r--r-- | tests/gis_tests/geoapp/test_functions.py | 18 |
2 files changed, 16 insertions, 13 deletions
diff --git a/tests/gis_tests/distapp/tests.py b/tests/gis_tests/distapp/tests.py index c59772a782..e6d66d22ae 100644 --- a/tests/gis_tests/distapp/tests.py +++ b/tests/gis_tests/distapp/tests.py @@ -438,7 +438,8 @@ class DistanceFunctionsTests(TestCase): # Tolerance has to be lower for Oracle tol = 2 for i, z in enumerate(SouthTexasZipcode.objects.annotate(area=Area('poly')).order_by('name')): - self.assertAlmostEqual(area_sq_m[i], z.area.sq_m, tol) + # MySQL is returning a raw float value + self.assertAlmostEqual(area_sq_m[i], z.area.sq_m if hasattr(z.area, 'sq_m') else z.area, tol) @skipUnlessDBFeature("has_Distance_function") def test_distance_simple(self): @@ -624,12 +625,12 @@ class DistanceFunctionsTests(TestCase): # TODO: test with spheroid argument (True and False) else: # Does not support geodetic coordinate systems. - with self.assertRaises(ValueError): - Interstate.objects.annotate(length=Length('path')) + with self.assertRaises(NotImplementedError): + list(Interstate.objects.annotate(length=Length('path'))) # Now doing length on a projected coordinate system. i10 = SouthTexasInterstate.objects.annotate(length=Length('path')).get(name='I-10') - self.assertAlmostEqual(len_m2, i10.length.m, 2) + self.assertAlmostEqual(len_m2, i10.length.m if isinstance(i10.length, D) else i10.length, 2) self.assertTrue( SouthTexasInterstate.objects.annotate(length=Length('path')).filter(length__gt=4000).exists() ) @@ -652,7 +653,7 @@ class DistanceFunctionsTests(TestCase): for city in qs: self.assertEqual(0, city.perim.m) - @skipUnlessDBFeature("has_Area_function", "has_Distance_function") + @skipUnlessDBFeature("supports_null_geometries", "has_Area_function", "has_Distance_function") def test_measurement_null_fields(self): """ Test the measurement functions on fields with NULL values. diff --git a/tests/gis_tests/geoapp/test_functions.py b/tests/gis_tests/geoapp/test_functions.py index fb2a88be09..b17a1a2fc0 100644 --- a/tests/gis_tests/geoapp/test_functions.py +++ b/tests/gis_tests/geoapp/test_functions.py @@ -9,7 +9,7 @@ from django.db import connection from django.test import TestCase, skipUnlessDBFeature from django.utils import six -from ..utils import oracle, postgis, spatialite +from ..utils import mysql, oracle, postgis, spatialite if HAS_GEOS: from django.contrib.gis.geos import LineString, Point, Polygon, fromstr @@ -165,8 +165,8 @@ class GISFunctionsTests(TestCase): @skipUnlessDBFeature("has_Centroid_function") def test_centroid(self): qs = State.objects.exclude(poly__isnull=True).annotate(centroid=functions.Centroid('poly')) + tol = 1.8 if mysql else (0.1 if oracle else 0.00001) for state in qs: - tol = 0.1 # High tolerance due to oracle self.assertTrue(state.poly.centroid.equals_exact(state.centroid, tol)) @skipUnlessDBFeature("has_Difference_function") @@ -248,9 +248,9 @@ class GISFunctionsTests(TestCase): qs = City.objects.filter(point__isnull=False).annotate(num_geom=functions.NumGeometries('point')) for city in qs: # Oracle and PostGIS 2.0+ will return 1 for the number of - # geometries on non-collections, whereas PostGIS < 2.0.0 + # geometries on non-collections, whereas PostGIS < 2.0.0 and MySQL # will return None. - if postgis and connection.ops.spatial_version < (2, 0, 0): + if (postgis and connection.ops.spatial_version < (2, 0, 0)) or mysql: self.assertIsNone(city.num_geom) else: self.assertEqual(1, city.num_geom) @@ -261,8 +261,8 @@ class GISFunctionsTests(TestCase): Track.objects.create(name='Foo', line=LineString(coords)) qs = Track.objects.annotate(num_points=functions.NumPoints('line')) self.assertEqual(qs.first().num_points, 2) - if spatialite: - # Spatialite can only count points on LineStrings + if spatialite or mysql: + # Spatialite and MySQL can only count points on LineStrings return for c in Country.objects.annotate(num_points=functions.NumPoints('mpoly')): @@ -455,5 +455,7 @@ class GISFunctionsTests(TestCase): geom = Point(-95.363151, 29.763374, srid=4326) ptown = City.objects.annotate(union=functions.Union('point', geom)).get(name='Dallas') tol = 0.00001 - expected = fromstr('MULTIPOINT(-96.801611 32.782057,-95.363151 29.763374)', srid=4326) - self.assertTrue(expected.equals_exact(ptown.union, tol)) + # Undefined ordering + expected1 = fromstr('MULTIPOINT(-96.801611 32.782057,-95.363151 29.763374)', srid=4326) + expected2 = fromstr('MULTIPOINT(-95.363151 29.763374,-96.801611 32.782057)', srid=4326) + self.assertTrue(expected1.equals_exact(ptown.union, tol) or expected2.equals_exact(ptown.union, tol)) |
