Ticket #18919: 18919-2.diff

File 18919-2.diff, 3.5 KB (added by Claude Paroz, 12 years ago)

Use more modern assertions

  • django/contrib/gis/geos/geometry.py

    diff --git a/django/contrib/gis/geos/geometry.py b/django/contrib/gis/geos/geometry.py
    index 4e5409d..8051526 100644
    a b class GEOSGeometry(GEOSBase, ListMixin):  
    465465    def ogr(self):
    466466        "Returns the OGR Geometry for this Geometry."
    467467        if gdal.HAS_GDAL:
     468            # Only ewkb keeps the 3D data
     469            wkb = self.ewkb if GEOS_PREPARE and self.hasz else self.wkb
    468470            if self.srid:
    469                 return gdal.OGRGeometry(self.wkb, self.srid)
     471                return gdal.OGRGeometry(wkb, self.srid)
    470472            else:
    471                 return gdal.OGRGeometry(self.wkb)
     473                return gdal.OGRGeometry(wkb)
    472474        else:
    473475            raise GEOSException('GDAL required to convert to an OGRGeometry.')
    474476
    class GEOSGeometry(GEOSBase, ListMixin):  
    513515            raise GEOSException("GDAL library is not available to transform() geometry.")
    514516
    515517        # Creating an OGR Geometry, which is then transformed.
    516         g = gdal.OGRGeometry(self.wkb, srid)
     518        g = self.ogr
    517519        g.transform(ct)
    518520        # Getting a new GEOS pointer
    519521        ptr = wkb_r().read(g.wkb)
  • django/contrib/gis/geos/tests/test_geos.py

    diff --git a/django/contrib/gis/geos/tests/test_geos.py b/django/contrib/gis/geos/tests/test_geos.py
    index 7300ab9..3800b2e 100644
    a b class GEOSTest(unittest.TestCase, TestDataMixin):  
    829829    def test_gdal(self):
    830830        "Testing `ogr` and `srs` properties."
    831831        g1 = fromstr('POINT(5 23)')
    832         self.assertEqual(True, isinstance(g1.ogr, gdal.OGRGeometry))
    833         self.assertEqual(g1.srs, None)
     832        self.assertIsInstance(g1.ogr, gdal.OGRGeometry)
     833        self.assertIsNone(g1.srs)
     834
     835        if GEOS_PREPARE:
     836            g1_3d = fromstr('POINT(5 23 8)')
     837            self.assertIsInstance(g1_3d.ogr, gdal.OGRGeometry)
     838            self.assertEqual(g1_3d.ogr.z, 8)
    834839
    835840        g2 = fromstr('LINESTRING(0 0, 5 5, 23 23)', srid=4326)
    836         self.assertEqual(True, isinstance(g2.ogr, gdal.OGRGeometry))
    837         self.assertEqual(True, isinstance(g2.srs, gdal.SpatialReference))
     841        self.assertIsInstance(g2.ogr, gdal.OGRGeometry)
     842        self.assertIsInstance(g2.srs, gdal.SpatialReference)
    838843        self.assertEqual(g2.hex, g2.ogr.hex)
    839844        self.assertEqual('WGS 84', g2.srs.name)
    840845
    class GEOSTest(unittest.TestCase, TestDataMixin):  
    847852        self.assertNotEqual(poly._ptr, cpy1._ptr)
    848853        self.assertNotEqual(poly._ptr, cpy2._ptr)
    849854
    850     @unittest.skipUnless(gdal.HAS_GDAL, "gdal is required")
     855    @unittest.skipUnless(gdal.HAS_GDAL, "gdal is required to transform geometries")
    851856    def test_transform(self):
    852857        "Testing `transform` method."
    853858        orig = GEOSGeometry('POINT (-104.609 38.255)', 4326)
    class GEOSTest(unittest.TestCase, TestDataMixin):  
    872877            self.assertAlmostEqual(trans.x, p.x, prec)
    873878            self.assertAlmostEqual(trans.y, p.y, prec)
    874879
     880    @unittest.skipUnless(gdal.HAS_GDAL, "gdal is required to transform geometries")
     881    def test_transform_3d(self):
     882        p3d = GEOSGeometry('POINT (5 23 100)', 4326)
     883        p3d.transform(2774)
     884        if GEOS_PREPARE:
     885            self.assertAlmostEqual(p3d.z, 0)
     886        else:
     887            self.assertIsNone(p3d.z)
     888
    875889    def test_transform_noop(self):
    876890        """ Testing `transform` method (SRID match) """
    877891        # transform() should no-op if source & dest SRIDs match,
Back to Top