web/lib/django/contrib/gis/geos/tests/test_geos.py
changeset 29 cc9b7e14412b
parent 0 0d40e90630ef
--- a/web/lib/django/contrib/gis/geos/tests/test_geos.py	Wed May 19 17:43:59 2010 +0200
+++ b/web/lib/django/contrib/gis/geos/tests/test_geos.py	Tue May 25 02:43:45 2010 +0200
@@ -71,6 +71,49 @@
             geom = fromstr(g.wkt)
             self.assertEqual(g.hex, geom.hex)
 
+    def test01b_hexewkb(self):
+        "Testing (HEX)EWKB output."
+        from binascii import a2b_hex
+
+        pnt_2d = Point(0, 1, srid=4326)
+        pnt_3d = Point(0, 1, 2, srid=4326)
+        
+        # OGC-compliant HEX will not have SRID nor Z value.
+        self.assertEqual(ogc_hex, pnt_2d.hex)
+        self.assertEqual(ogc_hex, pnt_3d.hex)
+
+        # HEXEWKB should be appropriate for its dimension -- have to use an
+        # a WKBWriter w/dimension set accordingly, else GEOS will insert
+        # garbage into 3D coordinate if there is none.  Also, GEOS has a
+        # a bug in versions prior to 3.1 that puts the X coordinate in
+        # place of Z; an exception should be raised on those versions.
+        self.assertEqual(hexewkb_2d, pnt_2d.hexewkb)
+        if GEOS_PREPARE:
+            self.assertEqual(hexewkb_3d, pnt_3d.hexewkb)
+            self.assertEqual(True, GEOSGeometry(hexewkb_3d).hasz)
+        else:
+            try:
+                hexewkb = pnt_3d.hexewkb
+            except GEOSException:
+                pass
+            else:
+                self.fail('Should have raised GEOSException.')
+
+        # Same for EWKB.
+        self.assertEqual(buffer(a2b_hex(hexewkb_2d)), pnt_2d.ewkb)
+        if GEOS_PREPARE:
+            self.assertEqual(buffer(a2b_hex(hexewkb_3d)), pnt_3d.ewkb)
+        else:
+            try:
+                ewkb = pnt_3d.ewkb
+            except GEOSException:
+                pass
+            else:
+                self.fail('Should have raised GEOSException')
+        
+        # Redundant sanity check.
+        self.assertEqual(4326, GEOSGeometry(hexewkb_2d).srid)
+
     def test01c_kml(self):
         "Testing KML output."
         for tg in wkt_out:
@@ -778,7 +821,7 @@
 
     def test22_copy(self):
         "Testing use with the Python `copy` module."
-        import copy
+        import django.utils.copycompat as copy
         poly = GEOSGeometry('POLYGON((0 0, 0 23, 23 23, 23 0, 0 0), (5 5, 5 10, 10 10, 10 5, 5 5))')
         cpy1 = copy.copy(poly)
         cpy2 = copy.deepcopy(poly)