Fixed brittle tests that broke with release of GDAL 1.8.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@15806 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Justin Bronn 2011-03-14 21:15:34 +00:00
parent 7d71a9e45f
commit ab7ada16ed
3 changed files with 13 additions and 14 deletions

View File

@ -1,6 +1,6 @@
from django.contrib.gis.gdal import OGRGeometry, OGRGeomType, \ from django.contrib.gis.gdal import OGRGeometry, OGRGeomType, \
OGRException, OGRIndexError, SpatialReference, CoordTransform, \ OGRException, OGRIndexError, SpatialReference, CoordTransform, \
gdal_version GDAL_VERSION
from django.utils import unittest from django.utils import unittest
from django.contrib.gis.geometry.test_data import TestDataMixin from django.contrib.gis.geometry.test_data import TestDataMixin
@ -74,7 +74,12 @@ class OGRGeomTest(unittest.TestCase, TestDataMixin):
"Testing GML output." "Testing GML output."
for g in self.geometries.wkt_out: for g in self.geometries.wkt_out:
geom = OGRGeometry(g.wkt) geom = OGRGeometry(g.wkt)
self.assertEqual(g.gml, geom.gml) exp_gml = g.gml
if GDAL_VERSION >= (1, 8):
# In GDAL 1.8, the non-conformant GML tag <gml:GeometryCollection> was
# replaced with <gml:MultiGeometry>.
exp_gml = exp_gml.replace('GeometryCollection', 'MultiGeometry')
self.assertEqual(exp_gml, geom.gml)
def test01c_hex(self): def test01c_hex(self):
"Testing HEX input/output." "Testing HEX input/output."
@ -237,10 +242,7 @@ class OGRGeomTest(unittest.TestCase, TestDataMixin):
# Closing the rings -- doesn't work on GDAL versions 1.4.1 and below: # Closing the rings -- doesn't work on GDAL versions 1.4.1 and below:
# http://trac.osgeo.org/gdal/ticket/1673 # http://trac.osgeo.org/gdal/ticket/1673
major, minor1, minor2 = gdal_version().split('.') if GDAL_VERSION <= (1, 4, 1): return
if major == '1':
iminor1 = int(minor1)
if iminor1 < 4 or (iminor1 == 4 and minor2.startswith('1')): return
poly.close_rings() poly.close_rings()
self.assertEqual(10, poly.point_count) # Two closing points should've been added self.assertEqual(10, poly.point_count) # Two closing points should've been added
self.assertEqual(OGRGeometry('POINT(2.5 2.5)'), poly.centroid) self.assertEqual(OGRGeometry('POINT(2.5 2.5)'), poly.centroid)

View File

@ -17,15 +17,13 @@ srlist = (TestSRS('GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,29
attr=(('DATUM', 'WGS_1984'), (('SPHEROID', 1), '6378137'),('primem|authority', 'EPSG'),), attr=(('DATUM', 'WGS_1984'), (('SPHEROID', 1), '6378137'),('primem|authority', 'EPSG'),),
), ),
TestSRS('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"]]', TestSRS('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"]]',
proj='+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=None, epsg=32140, projected=True, geographic=False, local=False,
epsg=32140, projected=True, geographic=False, local=False,
lin_name='metre', ang_name='degree', lin_units=1.0, ang_units=0.0174532925199, lin_name='metre', ang_name='degree', lin_units=1.0, ang_units=0.0174532925199,
auth={'PROJCS' : ('EPSG', '32140'), 'spheroid' : ('EPSG', '7019'), 'unit' : ('EPSG', '9001'),}, auth={'PROJCS' : ('EPSG', '32140'), 'spheroid' : ('EPSG', '7019'), 'unit' : ('EPSG', '9001'),},
attr=(('DATUM', 'North_American_Datum_1983'),(('SPHEROID', 2), '298.257222101'),('PROJECTION','Lambert_Conformal_Conic_2SP'),), attr=(('DATUM', 'North_American_Datum_1983'),(('SPHEROID', 2), '298.257222101'),('PROJECTION','Lambert_Conformal_Conic_2SP'),),
), ),
TestSRS('PROJCS["NAD_1983_StatePlane_Texas_South_Central_FIPS_4204_Feet",GEOGCS["GCS_North_American_1983",DATUM["North_American_Datum_1983",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Lambert_Conformal_Conic_2SP"],PARAMETER["False_Easting",1968500.0],PARAMETER["False_Northing",13123333.33333333],PARAMETER["Central_Meridian",-99.0],PARAMETER["Standard_Parallel_1",28.38333333333333],PARAMETER["Standard_Parallel_2",30.28333333333334],PARAMETER["Latitude_Of_Origin",27.83333333333333],UNIT["Foot_US",0.3048006096012192]]', TestSRS('PROJCS["NAD_1983_StatePlane_Texas_South_Central_FIPS_4204_Feet",GEOGCS["GCS_North_American_1983",DATUM["North_American_Datum_1983",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Lambert_Conformal_Conic_2SP"],PARAMETER["False_Easting",1968500.0],PARAMETER["False_Northing",13123333.33333333],PARAMETER["Central_Meridian",-99.0],PARAMETER["Standard_Parallel_1",28.38333333333333],PARAMETER["Standard_Parallel_2",30.28333333333334],PARAMETER["Latitude_Of_Origin",27.83333333333333],UNIT["Foot_US",0.3048006096012192]]',
proj='+proj=lcc +lat_1=28.38333333333333 +lat_2=30.28333333333334 +lat_0=27.83333333333333 +lon_0=-99 +x_0=600000 +y_0=3999999.999999999 +ellps=GRS80 +datum=NAD83 +to_meter=0.3048006096012192 +no_defs ', proj=None, epsg=None, projected=True, geographic=False, local=False,
epsg=None, projected=True, geographic=False, local=False,
lin_name='Foot_US', ang_name='Degree', lin_units=0.3048006096012192, ang_units=0.0174532925199, lin_name='Foot_US', ang_name='Degree', lin_units=0.3048006096012192, ang_units=0.0174532925199,
auth={'PROJCS' : (None, None),}, auth={'PROJCS' : (None, None),},
attr=(('PROJCS|GeOgCs|spheroid', 'GRS_1980'),(('projcs', 9), 'UNIT'), (('projcs', 11), None),), attr=(('PROJCS|GeOgCs|spheroid', 'GRS_1980'),(('projcs', 9), 'UNIT'), (('projcs', 11), None),),
@ -74,7 +72,6 @@ class SpatialRefTest(unittest.TestCase):
def test04_proj(self): def test04_proj(self):
"Test PROJ.4 import and export." "Test PROJ.4 import and export."
for s in srlist: for s in srlist:
if s.proj: if s.proj:
srs1 = SpatialReference(s.wkt) srs1 = SpatialReference(s.wkt)
@ -89,7 +86,6 @@ class SpatialRefTest(unittest.TestCase):
srs2 = SpatialReference(s.epsg) srs2 = SpatialReference(s.epsg)
srs3 = SpatialReference(str(s.epsg)) srs3 = SpatialReference(str(s.epsg))
srs4 = SpatialReference('EPSG:%d' % s.epsg) srs4 = SpatialReference('EPSG:%d' % s.epsg)
#self.assertEqual(srs1.wkt, srs2.wkt)
for srs in (srs1, srs2, srs3, srs4): for srs in (srs1, srs2, srs3, srs4):
for attr, expected in s.attr: for attr, expected in s.attr:
self.assertEqual(expected, srs[attr]) self.assertEqual(expected, srs[attr])
@ -158,7 +154,6 @@ class SpatialRefTest(unittest.TestCase):
self.assertEqual('WGS_1984', s1['DATUM']) self.assertEqual('WGS_1984', s1['DATUM'])
self.assertEqual('EPSG', s1['AUTHORITY']) self.assertEqual('EPSG', s1['AUTHORITY'])
self.assertEqual(4326, int(s1['AUTHORITY', 1])) self.assertEqual(4326, int(s1['AUTHORITY', 1]))
#for i in range(7): self.assertEqual(0, int(s1['TOWGS84', i]))
self.assertEqual(None, s1['FOOBAR']) self.assertEqual(None, s1['FOOBAR'])
def suite(): def suite():

View File

@ -1,4 +1,5 @@
from django.db import connection from django.db import connection
from django.contrib.gis.gdal import GDAL_VERSION
from django.contrib.gis.tests.utils import mysql, no_mysql, oracle, postgis, spatialite from django.contrib.gis.tests.utils import mysql, no_mysql, oracle, postgis, spatialite
from django.utils import unittest from django.utils import unittest
@ -78,7 +79,8 @@ class SpatialRefSysTest(unittest.TestCase):
# Testing the SpatialReference object directly. # Testing the SpatialReference object directly.
if postgis or spatialite: if postgis or spatialite:
srs = sr.srs srs = sr.srs
self.assertEqual(sd['proj4'], srs.proj4) if GDAL_VERSION <= (1, 8):
self.assertEqual(sd['proj4'], srs.proj4)
# No `srtext` field in the `spatial_ref_sys` table in SpatiaLite # No `srtext` field in the `spatial_ref_sys` table in SpatiaLite
if not spatialite: if not spatialite:
if connection.ops.spatial_version >= (1, 4, 0): if connection.ops.spatial_version >= (1, 4, 0):