~ubuntu-branches/ubuntu/quantal/python-django/quantal-security

« back to all changes in this revision

Viewing changes to django/contrib/gis/geos/tests/test_geos.py

  • Committer: Bazaar Package Importer
  • Author(s): Chris Lamb
  • Date: 2010-05-21 07:52:55 UTC
  • mfrom: (1.3.6 upstream)
  • mto: This revision was merged to the branch mainline in revision 28.
  • Revision ID: james.westby@ubuntu.com-20100521075255-ii78v1dyfmyu3uzx
Tags: upstream-1.2
ImportĀ upstreamĀ versionĀ 1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
71
71
            geom = fromstr(g.wkt)
72
72
            self.assertEqual(g.hex, geom.hex)
73
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)
 
116
 
74
117
    def test01c_kml(self):
75
118
        "Testing KML output."
76
119
        for tg in wkt_out:
778
821
 
779
822
    def test22_copy(self):
780
823
        "Testing use with the Python `copy` module."
781
 
        import copy
 
824
        import django.utils.copycompat as copy
782
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
826
        cpy1 = copy.copy(poly)
784
827
        cpy2 = copy.deepcopy(poly)