source: TI02-CSML/trunk/services/3rdParty/GeoTypes-0.6.0/tests/OGGeometryCollection_Test.py @ 2194

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI02-CSML/trunk/services/3rdParty/GeoTypes-0.6.0/tests/OGGeometryCollection_Test.py@2194
Revision 2194, 3.4 KB checked in by lawrence, 13 years ago (diff)

Adding various specs and 3rd party code of interest for the CSML
services development.

Line 
1
2################################################################################
3# Copyright (c) QinetiQ Plc 2003
4#
5# Licensed under the LGPL. For full license details see the LICENSE file.
6################################################################################
7
8import unittest
9import os
10
11import TestConfig
12
13if not os.environ.get('USECOVERAGE') == '1':
14    import _OGGeometryCollection
15    from _OGGeometryCollection import *
16
17from _OGGeometry import OGGeometry
18from _OGPoint import OGPoint, OGpointFromValues
19
20from CollectionClassTestBase import CollectionClassTestBase
21
22class OGGeometryCollectionTest(CollectionClassTestBase):   
23
24    _last_num = 0
25   
26    def getEnumClass(self):
27        x = float(OGGeometryCollectionTest._last_num + 1)
28        y = float(OGGeometryCollectionTest._last_num + 2)
29        OGGeometryCollectionTest._last_num = OGGeometryCollectionTest._last_num + 2
30       
31        return OGpointFromValues(x,y)
32       
33    def getCollectionClass(self):
34        return OGGeometryCollection()
35
36    testEqualities = CollectionClassTestBase._testEqualities
37    testContainerMethods = CollectionClassTestBase._testContainerMethods
38   
39    def testConstructor(self):
40        geom = OGGeometryCollection(-1) # with SRID
41        assert geom.SRID() == -1
42
43        geom = OGGeometryCollection() # No SRID
44        assert geom.SRID() == OGGeometry.default_srid
45        assert len(geom) == 0       
46
47    def testFactoryMethods(self):
48
49        points = []
50        # make a tuple of points.
51        for p in xrange(0,10):
52            points.append(self.getEnumClass())
53
54        geom = OGgeometryCollectionFromOGGeometries(*points)
55        assert len(geom) == 10, str(len(geom)) + " != 10 "
56       
57    def testOpenGISMethods(self):
58        geom = OGGeometryCollection()
59        geom.append(OGpointFromValues(1.0,2.0))       
60        geom.append(OGpointFromValues(3.0,4.0))
61
62        assert geom.NumGeometries() == 2
63        assert geom.GeometryN(0) == OGpointFromValues(1.0,2.0)
64
65    def testReprs(self):
66        geom = OGGeometryCollection()
67        geom.append(OGpointFromValues(1.0,2.0))       
68        geom.append(OGpointFromValues(3.0,4.0))
69
70        assert str(geom) == "GeometryFromText('GEOMETRYCOLLECTION (POINT(1.000000 2.000000),POINT(3.000000 4.000000))',128)"
71        assert repr(geom) == "(1.000000 2.000000,3.000000 4.000000)"
72       
73       
74    def testzzz_CoverageAssertion(self):
75            try:
76                coverage.stop()
77            except:
78                return 1
79
80            x = coverage.analysis(_OGGeometryCollection)
81            assert x[2]==[], "Coverage is less than 100%"
82
83
84def testSuite():
85    return unittest.makeSuite(OGGeometryCollectionTest,'test')
86
87if __name__ == "__main__":
88    if os.environ.get('USECOVERAGE') == '1':
89        try:
90            import coverage
91            coverage.erase()
92            coverage.start()
93            COVERAGE = 1
94            import _OGGeometryCollection
95            from _OGGeometryCollection import *
96
97
98        except:
99            print "Error setting up coverage checking"
100            COVERAGE = 0
101    else:
102        COVERAGE = 0
103
104    if os.environ.get('USEPYCHECK') == '1':
105        try:
106            import pychecker.checker
107        except:
108            print "Pychecker not installed on this machine"
109
110    unittest.TextTestRunner().run(testSuite())
111
112    if COVERAGE:
113        coverage.stop()
114        x = coverage.analysis(_OGGeometryCollection)
115        print "\n"
116        coverage.report(_OGGeometryCollection)
Note: See TracBrowser for help on using the repository browser.