From f49c770b2dc40a4e23c6fe5f3ced62ba80a8502c Mon Sep 17 00:00:00 2001 From: Justin Bronn Date: Tue, 22 Apr 2008 18:14:29 +0000 Subject: [PATCH] gis: Updated KML tests for PostGIS 1.3.3 and GDAL tests to not perform `close_rings` test for versions 1.4.1 and below. git-svn-id: http://code.djangoproject.com/svn/django/branches/gis@7441 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/gis/tests/geoapp/tests.py | 14 +++++++++++++- django/contrib/gis/tests/test_gdal_geom.py | 10 ++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/django/contrib/gis/tests/geoapp/tests.py b/django/contrib/gis/tests/geoapp/tests.py index df2cfce80d..be4eb2ac7f 100644 --- a/django/contrib/gis/tests/geoapp/tests.py +++ b/django/contrib/gis/tests/geoapp/tests.py @@ -1,6 +1,7 @@ import os, unittest from models import Country, City, State, Feature from django.contrib.gis import gdal +from django.contrib.gis.db.backend import SpatialBackend from django.contrib.gis.geos import * from django.contrib.gis.measure import Distance from django.contrib.gis.tests.utils import no_oracle, no_postgis, oracle, postgis @@ -123,11 +124,22 @@ class GeoModelTest(unittest.TestCase): qs = City.objects.all() self.assertRaises(TypeError, qs.kml, 'name') + # The reference KML depends on the version of PostGIS used + # (the output stopped including altitude in 1.3.3). + major, minor1, minor2 = SpatialBackend.version + ref_kml1 = '-104.609252,38.255001,0' + ref_kml2 = '-104.609252,38.255001' + if major == 1: + if minor1 > 3 or (minor1 == 3 and minor2 >= 3): ref_kml = ref_kml2 + else: ref_kml = ref_kml1 + else: + ref_kml = ref_kml2 + # Ensuring the KML is as expected. ptown1 = City.objects.kml('point', precision=9).get(name='Pueblo') ptown2 = City.objects.kml(precision=9).get(name='Pueblo') for ptown in [ptown1, ptown2]: - self.assertEqual('-104.609252,38.255001,0', ptown.kml) + self.assertEqual(ref_kml, ptown.kml) def test03b_gml(self): "Testing GML output from the database using GeoManager.gml()." diff --git a/django/contrib/gis/tests/test_gdal_geom.py b/django/contrib/gis/tests/test_gdal_geom.py index aa4e325116..37fa2e7071 100644 --- a/django/contrib/gis/tests/test_gdal_geom.py +++ b/django/contrib/gis/tests/test_gdal_geom.py @@ -1,6 +1,7 @@ import unittest from django.contrib.gis.gdal import OGRGeometry, OGRGeomType, \ - OGRException, OGRIndexError, SpatialReference, CoordTransform + OGRException, OGRIndexError, SpatialReference, CoordTransform, \ + gdal_version from django.contrib.gis.tests.geometries import * class OGRGeomTest(unittest.TestCase): @@ -196,7 +197,12 @@ class OGRGeomTest(unittest.TestCase): self.fail('Should have raised an OGRException!') print "\nEND - expecting IllegalArgumentException; safe to ignore.\n" - # Closing the rings + # Closing the rings -- doesn't work on GDAL versions 1.4.1 and below: + # http://trac.osgeo.org/gdal/ticket/1673 + major, minor1, minor2 = gdal_version().split('.') + if major == '1': + iminor1 = int(minor1) + if iminor1 < 4 or (iminor1 == 4 and minor2.startswith('1')): return poly.close_rings() self.assertEqual(10, poly.point_count) # Two closing points should've been added self.assertEqual(OGRGeometry('POINT(2.5 2.5)'), poly.centroid)