From 7e5ebcce5365a172d802c76b57771c321430317f Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Thu, 13 Sep 2012 16:17:32 +0200 Subject: [PATCH] Fixed #18795 -- Fixed failing GeoDjango tests Proj.4 and SRS strings may slightly vary depending on the installed libraries. Made some tests pass again with recent Proj.4/GDAL lib versions. --- django/contrib/gis/gdal/tests/test_ds.py | 6 +++- django/contrib/gis/gdal/tests/test_geom.py | 6 ++-- django/contrib/gis/geos/tests/test_geos.py | 6 ++-- .../contrib/gis/tests/test_spatialrefsys.py | 32 +++++++------------ 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/django/contrib/gis/gdal/tests/test_ds.py b/django/contrib/gis/gdal/tests/test_ds.py index 71d22a0a27..22394a2888 100644 --- a/django/contrib/gis/gdal/tests/test_ds.py +++ b/django/contrib/gis/gdal/tests/test_ds.py @@ -181,7 +181,11 @@ class DataSourceTest(unittest.TestCase): # Making sure the SpatialReference is as expected. if hasattr(source, 'srs_wkt'): - self.assertEqual(source.srs_wkt, g.srs.wkt) + self.assertEqual( + source.srs_wkt, + # Depending on lib versions, WGS_84 might be WGS_1984 + g.srs.wkt.replace('SPHEROID["WGS_84"', 'SPHEROID["WGS_1984"') + ) def test06_spatial_filter(self): "Testing the Layer.spatial_filter property." diff --git a/django/contrib/gis/gdal/tests/test_geom.py b/django/contrib/gis/gdal/tests/test_geom.py index a0b2593605..dda22036e3 100644 --- a/django/contrib/gis/gdal/tests/test_geom.py +++ b/django/contrib/gis/gdal/tests/test_geom.py @@ -1,3 +1,4 @@ +import json from binascii import b2a_hex try: from django.utils.six.moves import cPickle as pickle @@ -111,8 +112,9 @@ class OGRGeomTest(unittest.TestCase, TestDataMixin): for g in self.geometries.json_geoms: geom = OGRGeometry(g.wkt) if not hasattr(g, 'not_equal'): - self.assertEqual(g.json, geom.json) - self.assertEqual(g.json, geom.geojson) + # Loading jsons to prevent decimal differences + self.assertEqual(json.loads(g.json), json.loads(geom.json)) + self.assertEqual(json.loads(g.json), json.loads(geom.geojson)) self.assertEqual(OGRGeometry(g.wkt), OGRGeometry(geom.json)) def test02_points(self): diff --git a/django/contrib/gis/geos/tests/test_geos.py b/django/contrib/gis/geos/tests/test_geos.py index d621c6b4d4..7300ab9c63 100644 --- a/django/contrib/gis/geos/tests/test_geos.py +++ b/django/contrib/gis/geos/tests/test_geos.py @@ -1,4 +1,5 @@ import ctypes +import json import random from django.contrib.gis.geos import (GEOSException, GEOSIndexError, GEOSGeometry, @@ -204,8 +205,9 @@ class GEOSTest(unittest.TestCase, TestDataMixin): for g in self.geometries.json_geoms: geom = GEOSGeometry(g.wkt) if not hasattr(g, 'not_equal'): - self.assertEqual(g.json, geom.json) - self.assertEqual(g.json, geom.geojson) + # Loading jsons to prevent decimal differences + self.assertEqual(json.loads(g.json), json.loads(geom.json)) + self.assertEqual(json.loads(g.json), json.loads(geom.geojson)) self.assertEqual(GEOSGeometry(g.wkt), GEOSGeometry(geom.json)) def test_fromfile(self): diff --git a/django/contrib/gis/tests/test_spatialrefsys.py b/django/contrib/gis/tests/test_spatialrefsys.py index 5cdc68a74d..7f7a0111f1 100644 --- a/django/contrib/gis/tests/test_spatialrefsys.py +++ b/django/contrib/gis/tests/test_spatialrefsys.py @@ -8,9 +8,11 @@ from django.utils import unittest test_srs = ({'srid' : 4326, 'auth_name' : ('EPSG', True), 'auth_srid' : 4326, - 'srtext' : 'GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]]', - 'srtext14' : 'GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]]', - 'proj4' : '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs ', + # Only the beginning, because there are differences depending on installed libs + 'srtext' : 'GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84"', + 'proj4' : ['+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs ', + # +ellps=WGS84 has been removed in the 4326 proj string in proj-4.8 + '+proj=longlat +datum=WGS84 +no_defs '], 'spheroid' : 'WGS 84', 'name' : 'WGS 84', 'geographic' : True, 'projected' : False, 'spatialite' : True, 'ellipsoid' : (6378137.0, 6356752.3, 298.257223563), # From proj's "cs2cs -le" and Wikipedia (semi-minor only) @@ -19,9 +21,9 @@ test_srs = ({'srid' : 4326, {'srid' : 32140, 'auth_name' : ('EPSG', False), 'auth_srid' : 32140, - 'srtext' : 'PROJCS["NAD83 / Texas South Central",GEOGCS["NAD83",DATUM["North_American_Datum_1983",SPHEROID["GRS 1980",6378137,298.257222101,AUTHORITY["EPSG","7019"]],AUTHORITY["EPSG","6269"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4269"]],PROJECTION["Lambert_Conformal_Conic_2SP"],PARAMETER["standard_parallel_1",30.28333333333333],PARAMETER["standard_parallel_2",28.38333333333333],PARAMETER["latitude_of_origin",27.83333333333333],PARAMETER["central_meridian",-99],PARAMETER["false_easting",600000],PARAMETER["false_northing",4000000],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AUTHORITY["EPSG","32140"]]', - 'srtext14': 'PROJCS["NAD83 / Texas South Central",GEOGCS["NAD83",DATUM["North_American_Datum_1983",SPHEROID["GRS 1980",6378137,298.257222101,AUTHORITY["EPSG","7019"]],AUTHORITY["EPSG","6269"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4269"]],UNIT["metre",1,AUTHORITY["EPSG","9001"]],PROJECTION["Lambert_Conformal_Conic_2SP"],PARAMETER["standard_parallel_1",30.28333333333333],PARAMETER["standard_parallel_2",28.38333333333333],PARAMETER["latitude_of_origin",27.83333333333333],PARAMETER["central_meridian",-99],PARAMETER["false_easting",600000],PARAMETER["false_northing",4000000],AUTHORITY["EPSG","32140"],AXIS["X",EAST],AXIS["Y",NORTH]]', - 'proj4' : '+proj=lcc +lat_1=30.28333333333333 +lat_2=28.38333333333333 +lat_0=27.83333333333333 +lon_0=-99 +x_0=600000 +y_0=4000000 +ellps=GRS80 +datum=NAD83 +units=m +no_defs ', + 'srtext' : 'PROJCS["NAD83 / Texas South Central",GEOGCS["NAD83",DATUM["North_American_Datum_1983",SPHEROID["GRS 1980"', + 'proj4' : ['+proj=lcc +lat_1=30.28333333333333 +lat_2=28.38333333333333 +lat_0=27.83333333333333 +lon_0=-99 +x_0=600000 +y_0=4000000 +ellps=GRS80 +datum=NAD83 +units=m +no_defs ', + '+proj=lcc +lat_1=30.28333333333333 +lat_2=28.38333333333333 +lat_0=27.83333333333333 +lon_0=-99 +x_0=600000 +y_0=4000000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs '], 'spheroid' : 'GRS 1980', 'name' : 'NAD83 / Texas South Central', 'geographic' : False, 'projected' : True, 'spatialite' : False, 'ellipsoid' : (6378137.0, 6356752.31414, 298.257222101), # From proj's "cs2cs -le" and Wikipedia (semi-minor only) @@ -51,17 +53,12 @@ class SpatialRefSysTest(unittest.TestCase): # No proj.4 and different srtext on oracle backends :( if postgis: - if connection.ops.spatial_version >= (1, 4, 0): - srtext = sd['srtext14'] - else: - srtext = sd['srtext'] - self.assertEqual(srtext, srs.wkt) - self.assertEqual(sd['proj4'], srs.proj4text) + self.assertTrue(srs.wkt.startswith(sd['srtext'])) + self.assertTrue(srs.proj4text in sd['proj4']) @no_mysql def test02_osr(self): "Testing getting OSR objects from SpatialRefSys model objects." - from django.contrib.gis.gdal import GDAL_VERSION for sd in test_srs: sr = SpatialRefSys.objects.get(srid=sd['srid']) self.assertEqual(True, sr.spheroid.startswith(sd['spheroid'])) @@ -76,15 +73,10 @@ class SpatialRefSysTest(unittest.TestCase): # Testing the SpatialReference object directly. if postgis or spatialite: srs = sr.srs - if GDAL_VERSION <= (1, 8): - self.assertEqual(sd['proj4'], srs.proj4) + self.assertTrue(srs.proj4 in sd['proj4']) # No `srtext` field in the `spatial_ref_sys` table in SpatiaLite if not spatialite: - if connection.ops.spatial_version >= (1, 4, 0): - srtext = sd['srtext14'] - else: - srtext = sd['srtext'] - self.assertEqual(srtext, srs.wkt) + self.assertTrue(srs.wkt.startswith(sd['srtext'])) @no_mysql def test03_ellipsoid(self):