/[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 1559 - (hide annotations)
Thu Aug 7 17:32:20 2003 UTC (21 years, 7 months ago) by bh
Original Path: trunk/thuban/test/test_shapefilestore.py
File MIME type: text/x-python
File size: 8106 byte(s)
update ChangeLog

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 1551 def assertPointListEquals(self, test, value):
76     """Assert equality of two lists of lists of tuples of float"""
77 bh 1537 for i in range(len(test)):
78 bh 1551 self.assertEquals(len(test[i]), len(value[i]))
79     for j in range(len(test[i])):
80     self.assertFloatSeqEqual(test[i][j], value[i][j])
81 bh 1537
82     class TestShapefileStoreArc(ShapefileStoreTests):
83    
84     """Test cases for ShapefileStore with arc shapes"""
85    
86     def setUp(self):
87     """Initialize self.session"""
88     self.session = Session("Test Session")
89     self.filename = os.path.join("..", "Data", "iceland",
90     "roads-line.shp")
91     self.store = ShapefileStore(self.session, self.filename)
92    
93     def tearDown(self):
94     """Call self.session.Destroy() and reset self.session to None"""
95     self.session.Destroy()
96     self.session = None
97    
98     def test_shape_type(self):
99     """Test ShapefileStore.ShapeType() with arc shapes"""
100     self.assertEquals(self.store.ShapeType(), SHAPETYPE_ARC)
101    
102     def test_boundingbox(self):
103     """Test ShapefileStore.BoundingBox() with arc shapes"""
104     self.assertFloatSeqEqual(self.store.BoundingBox(),
105     [-24.450359344482422, 63.426830291748047,
106     -13.55668830871582, 66.520111083984375])
107    
108     def test_num_shapes(self):
109     """Test ShapefileStore.NumShapes() with arc shapes"""
110     self.assertEquals(self.store.NumShapes(), 839)
111    
112     def test_shapes_in_region(self):
113     """Test ShapefileStore.ShapesInRegion() with arc shapes"""
114     self.assertEquals(self.store.ShapesInRegion((-24.0, 64.0,
115     -23.75, 64.25)),
116     [613, 726, 838])
117    
118     def test_shape(self):
119     """Test ShapefileStore.Shape() with arc shapes"""
120 bh 1551 self.assertPointListEquals(self.store.Shape(32).Points(),
121     [[(-15.0821743011474, 66.2773818969726),
122     (-15.0263500213623, 66.2733917236328)]])
123 bh 1537
124    
125     class TestShapefileStorePolygon(ShapefileStoreTests):
126    
127     """Test cases for ShapefileStore with plygon shapes"""
128    
129     def setUp(self):
130     """Initialize self.session"""
131     self.session = Session("Test Session")
132     """Test ShapeStore with polygon shapes"""
133     self.filename = os.path.join("..", "Data", "iceland",
134     "political.shp")
135     self.store = ShapefileStore(self.session, self.filename)
136    
137     def tearDown(self):
138     """Call self.session.Destroy() and reset self.session to None"""
139     self.session.Destroy()
140     self.session = None
141    
142     def test_shape_type(self):
143     """Test ShapeStore.ShapeType() with polygon shapes"""
144     self.assertEquals(self.store.ShapeType(), SHAPETYPE_POLYGON)
145    
146     def test_boundingbox(self):
147     """Test ShapefileStore.BoundingBox() with polygon shapes"""
148     self.assertFloatSeqEqual(self.store.BoundingBox(),
149     [-24.546524047851562, 63.286754608154297,
150     -13.495815277099609, 66.563774108886719])
151    
152     def test_num_shapes(self):
153     """Test ShapefileStore.NumShapes() with polygon shapes"""
154     self.assertEquals(self.store.NumShapes(), 156)
155    
156     def test_shapes_in_region(self):
157     """Test ShapefileStore.ShapesInRegion() with polygon shapes"""
158     self.assertEquals(self.store.ShapesInRegion((-24.0, 64.0,
159     -23.9, 64.1)),
160     [91, 92, 144, 146, 148, 150, 152, 153])
161    
162     def test_shape(self):
163     """Test ShapefileStore.Shape() with polygon shapes"""
164 bh 1551 self.assertPointListEquals(self.store.Shape(4).Points(),
165     [[(-22.40639114379882, 64.714111328125),
166     (-22.41621208190918, 64.716003417968),
167     (-22.40605163574218, 64.719200134277),
168     (-22.40639114379882, 64.714111328125)]])
169 bh 1537
170     class TestShapefileStorePoint(ShapefileStoreTests):
171    
172     """Test cases for ShapefileStore with plygon shapes"""
173    
174     def setUp(self):
175     """Initialize self.session"""
176     self.session = Session("Test Session")
177     """Test ShapeStore with point shapes"""
178     self.filename = os.path.join("..", "Data", "iceland",
179     "cultural_landmark-point.shp")
180     self.store = ShapefileStore(self.session, self.filename)
181    
182     def tearDown(self):
183     """Call self.session.Destroy() and reset self.session to None"""
184     self.session.Destroy()
185     self.session = None
186    
187     def test_shape_type(self):
188     """Test ShapeStore.ShapeType() with point shapes"""
189     self.assertEquals(self.store.ShapeType(), SHAPETYPE_POINT)
190    
191     def test_boundingbox(self):
192     """Test ShapefileStore.BoundingBox() with point shapes"""
193     self.assertFloatSeqEqual(self.store.BoundingBox(),
194     [-23.806047439575195, 63.405960083007812,
195     -15.12291431427002, 66.36572265625])
196    
197     def test_num_shapes(self):
198     """Test ShapefileStore.NumShapes() with point shapes"""
199     self.assertEquals(self.store.NumShapes(), 34)
200    
201     def test_shapes_in_region(self):
202     """Test ShapefileStore.ShapesInRegion() with point shapes"""
203     self.assertEquals(self.store.ShapesInRegion((-24.0, 64.0,
204     -23.80, 64.1)),
205     [0, 1, 2, 3, 4, 5, 27, 28, 29, 30, 31])
206    
207     def test_shape(self):
208     """Test ShapefileStore.Shape() with point shapes"""
209 bh 1551 self.assertPointListEquals(self.store.Shape(0).Points(),
210     [[(-22.711074829101562, 66.36572265625)]])

Properties

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26