web/lib/django/contrib/gis/geos/tests/test_geos.py
changeset 29 cc9b7e14412b
parent 0 0d40e90630ef
equal deleted inserted replaced
28:b758351d191f 29:cc9b7e14412b
    68     def test01b_hex(self):
    68     def test01b_hex(self):
    69         "Testing HEX output."
    69         "Testing HEX output."
    70         for g in hex_wkt:
    70         for g in hex_wkt:
    71             geom = fromstr(g.wkt)
    71             geom = fromstr(g.wkt)
    72             self.assertEqual(g.hex, geom.hex)
    72             self.assertEqual(g.hex, geom.hex)
       
    73 
       
    74     def test01b_hexewkb(self):
       
    75         "Testing (HEX)EWKB output."
       
    76         from binascii import a2b_hex
       
    77 
       
    78         pnt_2d = Point(0, 1, srid=4326)
       
    79         pnt_3d = Point(0, 1, 2, srid=4326)
       
    80         
       
    81         # OGC-compliant HEX will not have SRID nor Z value.
       
    82         self.assertEqual(ogc_hex, pnt_2d.hex)
       
    83         self.assertEqual(ogc_hex, pnt_3d.hex)
       
    84 
       
    85         # HEXEWKB should be appropriate for its dimension -- have to use an
       
    86         # a WKBWriter w/dimension set accordingly, else GEOS will insert
       
    87         # garbage into 3D coordinate if there is none.  Also, GEOS has a
       
    88         # a bug in versions prior to 3.1 that puts the X coordinate in
       
    89         # place of Z; an exception should be raised on those versions.
       
    90         self.assertEqual(hexewkb_2d, pnt_2d.hexewkb)
       
    91         if GEOS_PREPARE:
       
    92             self.assertEqual(hexewkb_3d, pnt_3d.hexewkb)
       
    93             self.assertEqual(True, GEOSGeometry(hexewkb_3d).hasz)
       
    94         else:
       
    95             try:
       
    96                 hexewkb = pnt_3d.hexewkb
       
    97             except GEOSException:
       
    98                 pass
       
    99             else:
       
   100                 self.fail('Should have raised GEOSException.')
       
   101 
       
   102         # Same for EWKB.
       
   103         self.assertEqual(buffer(a2b_hex(hexewkb_2d)), pnt_2d.ewkb)
       
   104         if GEOS_PREPARE:
       
   105             self.assertEqual(buffer(a2b_hex(hexewkb_3d)), pnt_3d.ewkb)
       
   106         else:
       
   107             try:
       
   108                 ewkb = pnt_3d.ewkb
       
   109             except GEOSException:
       
   110                 pass
       
   111             else:
       
   112                 self.fail('Should have raised GEOSException')
       
   113         
       
   114         # Redundant sanity check.
       
   115         self.assertEqual(4326, GEOSGeometry(hexewkb_2d).srid)
    73 
   116 
    74     def test01c_kml(self):
   117     def test01c_kml(self):
    75         "Testing KML output."
   118         "Testing KML output."
    76         for tg in wkt_out:
   119         for tg in wkt_out:
    77             geom = fromstr(tg.wkt)
   120             geom = fromstr(tg.wkt)
   776         self.assertEqual(g2.hex, g2.ogr.hex)
   819         self.assertEqual(g2.hex, g2.ogr.hex)
   777         self.assertEqual('WGS 84', g2.srs.name)
   820         self.assertEqual('WGS 84', g2.srs.name)
   778 
   821 
   779     def test22_copy(self):
   822     def test22_copy(self):
   780         "Testing use with the Python `copy` module."
   823         "Testing use with the Python `copy` module."
   781         import copy
   824         import django.utils.copycompat as copy
   782         poly = GEOSGeometry('POLYGON((0 0, 0 23, 23 23, 23 0, 0 0), (5 5, 5 10, 10 10, 10 5, 5 5))')
   825         poly = GEOSGeometry('POLYGON((0 0, 0 23, 23 23, 23 0, 0 0), (5 5, 5 10, 10 10, 10 5, 5 5))')
   783         cpy1 = copy.copy(poly)
   826         cpy1 = copy.copy(poly)
   784         cpy2 = copy.deepcopy(poly)
   827         cpy2 = copy.deepcopy(poly)
   785         self.assertNotEqual(poly._ptr, cpy1._ptr)
   828         self.assertNotEqual(poly._ptr, cpy1._ptr)
   786         self.assertNotEqual(poly._ptr, cpy2._ptr)
   829         self.assertNotEqual(poly._ptr, cpy2._ptr)