/[thuban]/branches/WIP-pyshapelib-bramz/test/test_shapefilestore.py
ViewVC logotype

Annotation of /branches/WIP-pyshapelib-bramz/test/test_shapefilestore.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1675 - (hide annotations)
Thu Aug 28 13:09:48 2003 UTC (21 years, 6 months ago) by bh
Original Path: trunk/thuban/test/test_shapefilestore.py
File MIME type: text/x-python
File size: 8327 byte(s)
Make this callable as a program to
execute the tests

1 bh 1537 # Copyright (C) 2003 by Intevation GmbH
2     # Authors:
3     # Bernhard Herzog <[email protected]>
4     #
5     # This program is free software under the GPL (>=v2)
6     # Read the file COPYING coming with the software for details.
7    
8     """Test cases for ShapefileStore"""
9    
10     __version__ = "$Revision$"
11     # $Source$
12     # $Id$
13    
14     import os
15     import unittest
16    
17     import support
18     support.initthuban()
19    
20     from Thuban.Model.data import ShapefileStore
21     from Thuban.Model.session import Session
22     from Thuban.Model.data import SHAPETYPE_POLYGON, SHAPETYPE_ARC, SHAPETYPE_POINT
23 bh 1559 from Thuban.Model.data import RAW_SHAPEFILE
24 bh 1537
25    
26     class TestShapefileStore(unittest.TestCase):
27    
28     """Test cases for ShapefileStore"""
29    
30     def setUp(self):
31     """Initialize self.session"""
32     self.session = Session("Test Session")
33     self.filename = os.path.join("..", "Data", "iceland",
34     "roads-line.shp")
35     self.store = ShapefileStore(self.session, self.filename)
36    
37     def tearDown(self):
38     """Call self.session.Destroy() and reset self.session to None"""
39     self.session.Destroy()
40     self.session = None
41    
42     def test_accessors(self):
43     """Test ShapefileStore accessors"""
44     self.assertEquals(self.store.FileName(),
45     os.path.abspath(self.filename))
46    
47     # The filetype of a shapefile is "shapefile"
48     self.assertEquals(self.store.FileType(), "shapefile")
49    
50 bh 1559 def test_raw_format(self):
51     """Test ShapefileStore raw shape format"""
52     self.assertEquals(self.store.RawShapeFormat(), RAW_SHAPEFILE)
53    
54     # For shapefiles the raw format means just the shape id as an
55     # int
56     self.assertEquals(self.store.Shape(5).RawData(), 5)
57    
58 bh 1537 def test_dependencies(self):
59     """Test ShapefileStore and ShapeTable dependencies"""
60     # The shapestore itself depends on nothing else
61     self.assertEquals(self.store.Dependencies(), ())
62    
63     # The shapestore's table depends on the shapestore
64     self.assertEquals(self.store.Table().Dependencies(), (self.store,))
65    
66    
67     def test_orig_shapestore(self):
68     """Test ShapefileStore.OrigShapeStore()"""
69     self.assertEquals(self.store.OrigShapeStore(), None)
70    
71    
72    
73     class ShapefileStoreTests(unittest.TestCase, support.FloatComparisonMixin):
74    
75 bh 1577 """Base class for the ShapefileStore tests"""
76 bh 1537
77 bh 1577
78 bh 1537 class TestShapefileStoreArc(ShapefileStoreTests):
79    
80     """Test cases for ShapefileStore with arc shapes"""
81    
82     def setUp(self):
83     """Initialize self.session"""
84     self.session = Session("Test Session")
85     self.filename = os.path.join("..", "Data", "iceland",
86     "roads-line.shp")
87     self.store = ShapefileStore(self.session, self.filename)
88    
89     def tearDown(self):
90     """Call self.session.Destroy() and reset self.session to None"""
91     self.session.Destroy()
92     self.session = None
93    
94     def test_shape_type(self):
95     """Test ShapefileStore.ShapeType() with arc shapes"""
96     self.assertEquals(self.store.ShapeType(), SHAPETYPE_ARC)
97    
98     def test_boundingbox(self):
99     """Test ShapefileStore.BoundingBox() with arc shapes"""
100     self.assertFloatSeqEqual(self.store.BoundingBox(),
101     [-24.450359344482422, 63.426830291748047,
102     -13.55668830871582, 66.520111083984375])
103    
104     def test_num_shapes(self):
105     """Test ShapefileStore.NumShapes() with arc shapes"""
106     self.assertEquals(self.store.NumShapes(), 839)
107    
108     def test_shapes_in_region(self):
109     """Test ShapefileStore.ShapesInRegion() with arc shapes"""
110 bh 1593 shapes = self.store.ShapesInRegion((-24.0, 64.0, -23.75, 64.25))
111     self.assertEquals([s.ShapeID() for s in shapes], [613, 726, 838])
112 bh 1537
113     def test_shape(self):
114     """Test ShapefileStore.Shape() with arc shapes"""
115 bh 1551 self.assertPointListEquals(self.store.Shape(32).Points(),
116     [[(-15.0821743011474, 66.2773818969726),
117     (-15.0263500213623, 66.2733917236328)]])
118 bh 1537
119 bh 1593 def test_shape_shapeid(self):
120     """Test ShapefileStore.Shape(i).ShapeID()"""
121     self.assertEquals(self.store.Shape(5).ShapeID(), 5)
122 bh 1537
123 bh 1593
124 bh 1537 class TestShapefileStorePolygon(ShapefileStoreTests):
125    
126     """Test cases for ShapefileStore with plygon shapes"""
127    
128     def setUp(self):
129     """Initialize self.session"""
130     self.session = Session("Test Session")
131     """Test ShapeStore with polygon shapes"""
132     self.filename = os.path.join("..", "Data", "iceland",
133     "political.shp")
134     self.store = ShapefileStore(self.session, self.filename)
135    
136     def tearDown(self):
137     """Call self.session.Destroy() and reset self.session to None"""
138     self.session.Destroy()
139     self.session = None
140    
141     def test_shape_type(self):
142     """Test ShapeStore.ShapeType() with polygon shapes"""
143     self.assertEquals(self.store.ShapeType(), SHAPETYPE_POLYGON)
144    
145     def test_boundingbox(self):
146     """Test ShapefileStore.BoundingBox() with polygon shapes"""
147     self.assertFloatSeqEqual(self.store.BoundingBox(),
148     [-24.546524047851562, 63.286754608154297,
149     -13.495815277099609, 66.563774108886719])
150    
151     def test_num_shapes(self):
152     """Test ShapefileStore.NumShapes() with polygon shapes"""
153     self.assertEquals(self.store.NumShapes(), 156)
154    
155     def test_shapes_in_region(self):
156     """Test ShapefileStore.ShapesInRegion() with polygon shapes"""
157 bh 1593 shapes = self.store.ShapesInRegion((-24.0, 64.0, -23.9, 64.1))
158     self.assertEquals([s.ShapeID() for s in shapes],
159 bh 1537 [91, 92, 144, 146, 148, 150, 152, 153])
160    
161     def test_shape(self):
162     """Test ShapefileStore.Shape() with polygon shapes"""
163 bh 1551 self.assertPointListEquals(self.store.Shape(4).Points(),
164     [[(-22.40639114379882, 64.714111328125),
165     (-22.41621208190918, 64.716003417968),
166     (-22.40605163574218, 64.719200134277),
167     (-22.40639114379882, 64.714111328125)]])
168 bh 1537
169     class TestShapefileStorePoint(ShapefileStoreTests):
170    
171     """Test cases for ShapefileStore with plygon shapes"""
172    
173     def setUp(self):
174     """Initialize self.session"""
175     self.session = Session("Test Session")
176     """Test ShapeStore with point shapes"""
177     self.filename = os.path.join("..", "Data", "iceland",
178     "cultural_landmark-point.shp")
179     self.store = ShapefileStore(self.session, self.filename)
180    
181     def tearDown(self):
182     """Call self.session.Destroy() and reset self.session to None"""
183     self.session.Destroy()
184     self.session = None
185    
186     def test_shape_type(self):
187     """Test ShapeStore.ShapeType() with point shapes"""
188     self.assertEquals(self.store.ShapeType(), SHAPETYPE_POINT)
189    
190     def test_boundingbox(self):
191     """Test ShapefileStore.BoundingBox() with point shapes"""
192     self.assertFloatSeqEqual(self.store.BoundingBox(),
193     [-23.806047439575195, 63.405960083007812,
194     -15.12291431427002, 66.36572265625])
195    
196     def test_num_shapes(self):
197     """Test ShapefileStore.NumShapes() with point shapes"""
198     self.assertEquals(self.store.NumShapes(), 34)
199    
200     def test_shapes_in_region(self):
201     """Test ShapefileStore.ShapesInRegion() with point shapes"""
202 bh 1593 shapes = self.store.ShapesInRegion((-24.0, 64.0, -23.80, 64.1))
203     self.assertEquals([s.ShapeID() for s in shapes],
204 bh 1537 [0, 1, 2, 3, 4, 5, 27, 28, 29, 30, 31])
205    
206 bh 1593 def test_all_shapes(self):
207     """Test ShapefileStore.AllShapes()"""
208     # This test is probably not needed for other shape types as it's
209     # not specific to the type or the data at all.
210     self.assertEquals([s.ShapeID() for s in self.store.AllShapes()],
211     range(self.store.NumShapes()))
212    
213 bh 1537 def test_shape(self):
214     """Test ShapefileStore.Shape() with point shapes"""
215 bh 1551 self.assertPointListEquals(self.store.Shape(0).Points(),
216     [[(-22.711074829101562, 66.36572265625)]])
217 bh 1675
218     if __name__ == "__main__":
219     support.run_tests()
220    

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26