Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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.
  • Loading branch information...
commit 7e5ebcce5365a172d802c76b57771c321430317f 1 parent 9db7652
Claude Paroz authored September 13, 2012
6  django/contrib/gis/gdal/tests/test_ds.py
@@ -181,7 +181,11 @@ def test05_geometries(self):
181 181
 
182 182
                     # Making sure the SpatialReference is as expected.
183 183
                     if hasattr(source, 'srs_wkt'):
184  
-                        self.assertEqual(source.srs_wkt, g.srs.wkt)
  184
+                        self.assertEqual(
  185
+                            source.srs_wkt,
  186
+                            # Depending on lib versions, WGS_84 might be WGS_1984
  187
+                            g.srs.wkt.replace('SPHEROID["WGS_84"', 'SPHEROID["WGS_1984"')
  188
+                        )
185 189
 
186 190
     def test06_spatial_filter(self):
187 191
         "Testing the Layer.spatial_filter property."
6  django/contrib/gis/gdal/tests/test_geom.py
... ...
@@ -1,3 +1,4 @@
  1
+import json
1 2
 from binascii import b2a_hex
2 3
 try:
3 4
     from django.utils.six.moves import cPickle as pickle
@@ -111,8 +112,9 @@ def test01e_json(self):
111 112
         for g in self.geometries.json_geoms:
112 113
             geom = OGRGeometry(g.wkt)
113 114
             if not hasattr(g, 'not_equal'):
114  
-                self.assertEqual(g.json, geom.json)
115  
-                self.assertEqual(g.json, geom.geojson)
  115
+                # Loading jsons to prevent decimal differences
  116
+                self.assertEqual(json.loads(g.json), json.loads(geom.json))
  117
+                self.assertEqual(json.loads(g.json), json.loads(geom.geojson))
116 118
             self.assertEqual(OGRGeometry(g.wkt), OGRGeometry(geom.json))
117 119
 
118 120
     def test02_points(self):
6  django/contrib/gis/geos/tests/test_geos.py
... ...
@@ -1,4 +1,5 @@
1 1
 import ctypes
  2
+import json
2 3
 import random
3 4
 
4 5
 from django.contrib.gis.geos import (GEOSException, GEOSIndexError, GEOSGeometry,
@@ -204,8 +205,9 @@ def test_json(self):
204 205
         for g in self.geometries.json_geoms:
205 206
             geom = GEOSGeometry(g.wkt)
206 207
             if not hasattr(g, 'not_equal'):
207  
-                self.assertEqual(g.json, geom.json)
208  
-                self.assertEqual(g.json, geom.geojson)
  208
+                # Loading jsons to prevent decimal differences
  209
+                self.assertEqual(json.loads(g.json), json.loads(geom.json))
  210
+                self.assertEqual(json.loads(g.json), json.loads(geom.geojson))
209 211
             self.assertEqual(GEOSGeometry(g.wkt), GEOSGeometry(geom.json))
210 212
 
211 213
     def test_fromfile(self):
32  django/contrib/gis/tests/test_spatialrefsys.py
@@ -8,9 +8,11 @@
8 8
 test_srs = ({'srid' : 4326,
9 9
              'auth_name' : ('EPSG', True),
10 10
              'auth_srid' : 4326,
11  
-             '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"]]',
12  
-             '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"]]',
13  
-             'proj4' : '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs ',
  11
+             # Only the beginning, because there are differences depending on installed libs
  12
+             'srtext' : 'GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84"',
  13
+             'proj4' : ['+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs ',
  14
+                        # +ellps=WGS84 has been removed in the 4326 proj string in proj-4.8
  15
+                        '+proj=longlat +datum=WGS84 +no_defs '],
14 16
              'spheroid' : 'WGS 84', 'name' : 'WGS 84',
15 17
              'geographic' : True, 'projected' : False, 'spatialite' : True,
16 18
              'ellipsoid' : (6378137.0, 6356752.3, 298.257223563), # From proj's "cs2cs -le" and Wikipedia (semi-minor only)
@@ -19,9 +21,9 @@
19 21
             {'srid' : 32140,
20 22
              'auth_name' : ('EPSG', False),
21 23
              'auth_srid' : 32140,
22  
-             '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"]]',
23  
-             '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]]',
24  
-             '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 ',
  24
+             'srtext' : 'PROJCS["NAD83 / Texas South Central",GEOGCS["NAD83",DATUM["North_American_Datum_1983",SPHEROID["GRS 1980"',
  25
+             '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 ',
  26
+                        '+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 '],
25 27
              'spheroid' : 'GRS 1980', 'name' : 'NAD83 / Texas South Central',
26 28
              'geographic' : False, 'projected' : True, 'spatialite' : False,
27 29
              'ellipsoid' : (6378137.0, 6356752.31414, 298.257222101), # From proj's "cs2cs -le" and Wikipedia (semi-minor only)
@@ -51,17 +53,12 @@ def test01_retrieve(self):
51 53
 
52 54
             # No proj.4 and different srtext on oracle backends :(
53 55
             if postgis:
54  
-                if connection.ops.spatial_version >= (1, 4, 0):
55  
-                    srtext = sd['srtext14']
56  
-                else:
57  
-                    srtext = sd['srtext']
58  
-                self.assertEqual(srtext, srs.wkt)
59  
-                self.assertEqual(sd['proj4'], srs.proj4text)
  56
+                self.assertTrue(srs.wkt.startswith(sd['srtext']))
  57
+                self.assertTrue(srs.proj4text in sd['proj4'])
60 58
 
61 59
     @no_mysql
62 60
     def test02_osr(self):
63 61
         "Testing getting OSR objects from SpatialRefSys model objects."
64  
-        from django.contrib.gis.gdal import GDAL_VERSION
65 62
         for sd in test_srs:
66 63
             sr = SpatialRefSys.objects.get(srid=sd['srid'])
67 64
             self.assertEqual(True, sr.spheroid.startswith(sd['spheroid']))
@@ -76,15 +73,10 @@ def test02_osr(self):
76 73
             # Testing the SpatialReference object directly.
77 74
             if postgis or spatialite:
78 75
                 srs = sr.srs
79  
-                if GDAL_VERSION <= (1, 8):
80  
-                    self.assertEqual(sd['proj4'], srs.proj4)
  76
+                self.assertTrue(srs.proj4 in sd['proj4'])
81 77
                 # No `srtext` field in the `spatial_ref_sys` table in SpatiaLite
82 78
                 if not spatialite:
83  
-                    if connection.ops.spatial_version >= (1, 4, 0):
84  
-                        srtext = sd['srtext14']
85  
-                    else:
86  
-                        srtext = sd['srtext']
87  
-                    self.assertEqual(srtext, srs.wkt)
  79
+                    self.assertTrue(srs.wkt.startswith(sd['srtext']))
88 80
 
89 81
     @no_mysql
90 82
     def test03_ellipsoid(self):

0 notes on commit 7e5ebcc

Please sign in to comment.
Something went wrong with that request. Please try again.