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

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI02-CSML/trunk/services/3rdParty/GeoTypes-0.6.0/tests/OGMultiPolygon_Test.py@2194
Revision 2194, 5.1 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
10import TestConfig
11
12if not os.environ.get('USECOVERAGE') == '1':
13    import _OGMultiPolygon
14    from _OGMultiPolygon import *
15
16from _OGGeometry import OGGeometry
17from _OGPolygon import OGPolygon, OGpolygonFromSequence
18
19from CollectionClassTestBase import CollectionClassTestBase
20
21class OGMultiPolygonTest(CollectionClassTestBase):   
22
23    _last_num = 0
24
25    testEqualities = CollectionClassTestBase._testEqualities
26    testContainerMethods = CollectionClassTestBase._testContainerMethods
27
28    def getEnumClass(self):
29        x1 = float(OGMultiPolygonTest._last_num + 1)
30        y1 = float(OGMultiPolygonTest._last_num + 2)
31        OGMultiPolygonTest._last_num = OGMultiPolygonTest._last_num + 2
32        x2 = float(OGMultiPolygonTest._last_num + 1)
33        y2 = float(OGMultiPolygonTest._last_num + 2)
34        OGMultiPolygonTest._last_num = OGMultiPolygonTest._last_num + 2
35        x3 = float(OGMultiPolygonTest._last_num + 1)
36        y3 = float(OGMultiPolygonTest._last_num + 2)
37        OGMultiPolygonTest._last_num = OGMultiPolygonTest._last_num + 2
38        x4 = float(OGMultiPolygonTest._last_num + 1)
39        y4 = float(OGMultiPolygonTest._last_num + 2)
40        OGMultiPolygonTest._last_num = OGMultiPolygonTest._last_num + 2
41        x5 = float(OGMultiPolygonTest._last_num + 1)
42        y5 = float(OGMultiPolygonTest._last_num + 2)
43        OGMultiPolygonTest._last_num = OGMultiPolygonTest._last_num + 2
44        x6 = float(OGMultiPolygonTest._last_num + 1)
45        y6 = float(OGMultiPolygonTest._last_num + 2)
46        OGMultiPolygonTest._last_num = OGMultiPolygonTest._last_num + 2
47
48        return OGpolygonFromSequence(
49            ( # start of Polygon 1
50            ((x1,y1),(x2,y2),(x3,y3)),
51            ((x4,y4),(x5,y5),(x6,y6))
52            ))
53                               
54    def getCollectionClass(self):
55        return OGMultiPolygon()
56   
57    def testConstructor(self):
58        geom = OGMultiPolygon(-1) # with SRID
59        assert geom.SRID() == -1
60
61        geom = OGMultiPolygon() # No SRID
62        assert geom.SRID() == OGGeometry.default_srid
63        assert len(geom) == 0       
64
65    def testFactoryMethods(self):
66
67        polygons = []
68        # make a tuple of points.
69        for p in xrange(0,10):
70            polygons.append(self.getEnumClass())
71
72        geom = OGmultiPolygonFromOGPolygons(*polygons)
73        assert len(geom) == 10, str(len(geom)) + " != 10 "
74
75       
76        geom1 = OGmultiPolygonFromSequence(
77            ( # MultiPolygon
78              ( # Polygon
79               ( # linearring
80                (133.000000, 134.000000),(135.000000, 136.000000),(137.000000, 138.000000)
81                ),
82                (               
83                (139.000000, 140.000000),(141.000000, 142.000000),(143.000000, 144.000000)
84                )
85               ,) # comma important because it must be a tuple
86              ,) # comma important because it must be a tuple
87            )
88       
89
90    def testReprs(self):
91        geom = OGmultiPolygonFromSequence(
92            ( # MultiPolygon
93              ( # Polygon
94               ( # linearring
95                (133.000000, 134.000000),(135.000000, 136.000000),(137.000000, 138.000000)
96                ),
97                (               
98                (139.000000, 140.000000),(141.000000, 142.000000),(143.000000, 144.000000)
99                )
100               ,) # comma important because it must be a tuple
101              ,) # comma important because it must be a tuple
102            )
103
104        assert str(geom) == "GeometryFromText('MULTIPOLYGON (((133.000000 134.000000,135.000000 136.000000,137.000000 138.000000),(139.000000 140.000000,141.000000 142.000000,143.000000 144.000000)))',128)"
105        assert repr(geom) == "(((133.000000 134.000000,135.000000 136.000000,137.000000 138.000000),(139.000000 140.000000,141.000000 142.000000,143.000000 144.000000)))"
106
107       
108       
109    def testzzz_CoverageAssertion(self):
110            try:
111                coverage.stop()
112            except:
113                return 1
114
115            x = coverage.analysis(_OGMultiPolygon)
116            assert x[2]==[], "Coverage is less than 100%"
117
118
119def testSuite():
120    return unittest.makeSuite(OGMultiPolygonTest,'test')
121
122if __name__ == "__main__":
123    if os.environ.get('USECOVERAGE') == '1':
124        try:
125            import coverage
126            coverage.erase()
127            coverage.start()
128            COVERAGE = 1
129            import _OGMultiPolygon
130            from _OGMultiPolygon import *
131
132
133        except:
134            print "Error setting up coverage checking"
135            COVERAGE = 0
136    else:
137        COVERAGE = 0
138
139    if os.environ.get('USEPYCHECK') == '1':
140        try:
141            import pychecker.checker
142        except:
143            print "Pychecker not installed on this machine"
144
145    unittest.TextTestRunner().run(testSuite())
146
147    if COVERAGE:
148        coverage.stop()
149        x = coverage.analysis(_OGMultiPolygon)
150        print "\n"
151        coverage.report(_OGMultiPolygon)
Note: See TracBrowser for help on using the repository browser.