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

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI02-CSML/trunk/services/3rdParty/GeoTypes-0.6.0/tests/OGLineString_Test.py@2194
Revision 2194, 5.2 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 _OGLineString
14    from _OGLineString import *
15
16from _OGGeometry import OGGeometry
17from _OGPoint import OGPoint, OGpointFromValues
18
19class OGLineStringTest(unittest.TestCase):   
20
21    def testConstructor(self):
22        linestring = OGLineString(-1) # with SRID
23        assert linestring.SRID() == -1
24
25        linestring = OGLineString() # No SRID
26        assert linestring.SRID() == OGGeometry.default_srid
27        assert len(linestring) == 0
28       
29    def testEqualities(self):
30        linestring1 = OGLineString()
31        linestring1.append(OGPoint())
32       
33        linestring2 = OGLineString()
34        linestring2.append(OGPoint())
35
36        assert linestring1 == linestring2
37       
38        linestring2.append(OGpointFromValues(1.0,2.0))
39        assert linestring1 != linestring2       
40
41    def testContainerMethods(self):   
42        linestring = OGLineString()
43
44        # append
45        linestring.append(OGpointFromValues(1.0,2.0))
46        assert len(linestring) == 1
47       
48        linestring.append(OGpointFromValues(3.0,4.0))
49        assert len(linestring) == 2
50
51        # index
52        assert linestring[0] == OGpointFromValues(1.0,2.0)
53        assert linestring[1] == OGpointFromValues(3.0,4.0)
54
55        # extend
56        linestring1 = OGLineString()
57        linestring1.append(OGpointFromValues(2.0,3.0))
58        linestring1.append(OGpointFromValues(4.0,5.0))
59        assert len(linestring1) == 2
60
61        linestring.extend(linestring1)
62        assert len(linestring) == 4
63
64        # insert
65        linestring.insert(0,OGpointFromValues(6.0,7.0))
66        assert linestring[0] == OGpointFromValues(6.0,7.0)
67
68        # pop
69        l = len(linestring)
70        linestring.append(OGpointFromValues(1.0,2.0))
71        assert len(linestring) == l+1
72        assert linestring.pop() == OGpointFromValues(1.0,2.0)
73        assert len(linestring) == l
74
75        # __contains__
76        p = OGpointFromValues(100.0,200.0)
77        linestring.append(p)
78        assert p in linestring
79
80        # remove
81        linestring.remove(p)
82        assert p not in linestring
83
84        # __setitem__, __getitem
85        p = OGpointFromValues(100.0,200.0)
86        linestring[2] = p
87        assert linestring[2] == p
88
89        # __delitem__
90        del linestring[2]
91        assert linestring[2] != p
92
93        # __iter__
94        for geo in linestring:
95            assert geo.__class__ == OGPoint
96       
97    def testFactoryMethods(self):
98        linestring = OGlineStringFromOGPoints(OGpointFromValues(1.0,2.0),
99                                              OGpointFromValues(2.0,3.0))
100        assert len(linestring) == 2
101               
102        linestring = OGlineStringFromSequence(((1.0,2.0),(2.0,3.0)))
103        assert len(linestring) == 2
104
105    def test_count(self):
106        linestring1 = OGLineString()
107        linestring1.append(OGpointFromValues(2.0,3.0))
108
109        assert linestring1.count(OGpointFromValues(2.0,3.0)) == 1
110        assert linestring1.count(OGpointFromValues(2.0,4.0)) == 0
111       
112    def test_index(self):
113        linestring1 = OGLineString()
114        linestring1.append(OGpointFromValues(2.0,3.0))
115
116        assert linestring1.index(OGpointFromValues(2.0,3.0)) == 0
117        try:
118            linestring1.index(OGpointFromValues(2.0,4.0))
119            assert 0, "Should have raised an exception"
120        except ValueError:
121            pass
122           
123    def test_og_str(self):
124        linestring1 = OGLineString()
125        linestring1.append(OGpointFromValues(2.0,3.0))
126        assert linestring1._og_str() == "LINESTRING (2.000000 3.000000)", linestring1._og_str()
127       
128    def test_repr(self):
129        linestring1 = OGLineString()
130        linestring1.append(OGpointFromValues(2.0,3.0))
131        assert repr(linestring1) == "(2.000000 3.000000)", repr(linestring1)
132
133    def test_bad_eq(self):
134        linestring1 = OGLineString()
135        assert not linestring1 == 1
136       
137    def testzzz_CoverageAssertion(self):
138            try:
139                coverage.stop()
140            except:
141                return 1
142
143            x = coverage.analysis(_OGLineString)
144            assert x[2]==[], "Coverage is less than 100%"
145
146
147def testSuite():
148    return unittest.makeSuite(OGLineStringTest,'test')
149
150if __name__ == "__main__":
151    if os.environ.get('USECOVERAGE') == '1':
152        try:
153            import coverage
154            coverage.erase()
155            coverage.start()
156            COVERAGE = 1
157            import _OGLineString
158            from _OGLineString import *
159
160        except:
161            print "Error setting up coverage checking"
162            COVERAGE = 0
163    else:
164        COVERAGE = 0
165
166    if os.environ.get('USEPYCHECK') == '1':
167        try:
168            import pychecker.checker
169        except:
170            print "Pychecker not installed on this machine"
171
172    unittest.TextTestRunner().run(testSuite())
173
174    if COVERAGE:
175        coverage.stop()
176        x = coverage.analysis(_OGLineString)
177        print "\n"
178        coverage.report(_OGLineString)
Note: See TracBrowser for help on using the repository browser.