/[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 1537 - (hide annotations)
Fri Aug 1 14:27:43 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: 7660 byte(s)
New. Tests for ShapefileStore.

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    
24    
25     class TestShapefileStore(unittest.TestCase):
26    
27     """Test cases for ShapefileStore"""
28    
29     def setUp(self):
30     """Initialize self.session"""
31     self.session = Session("Test Session")
32     self.filename = os.path.join("..", "Data", "iceland",
33     "roads-line.shp")
34     self.store = ShapefileStore(self.session, self.filename)
35    
36     def tearDown(self):
37     """Call self.session.Destroy() and reset self.session to None"""
38     self.session.Destroy()
39     self.session = None
40    
41     def test_accessors(self):
42     """Test ShapefileStore accessors"""
43     self.assertEquals(self.store.FileName(),
44     os.path.abspath(self.filename))
45    
46     # The filetype of a shapefile is "shapefile"
47     self.assertEquals(self.store.FileType(), "shapefile")
48    
49     def test_dependencies(self):
50     """Test ShapefileStore and ShapeTable dependencies"""
51     # The shapestore itself depends on nothing else
52     self.assertEquals(self.store.Dependencies(), ())
53    
54     # The shapestore's table depends on the shapestore
55     self.assertEquals(self.store.Table().Dependencies(), (self.store,))
56    
57    
58     def test_orig_shapestore(self):
59     """Test ShapefileStore.OrigShapeStore()"""
60     self.assertEquals(self.store.OrigShapeStore(), None)
61    
62    
63    
64     class ShapefileStoreTests(unittest.TestCase, support.FloatComparisonMixin):
65    
66     def assertFloatTuplesEqual(self, test, value):
67     """Assert equality of two lists of tuples of float"""
68     for i in range(len(test)):
69     self.assertFloatSeqEqual(test[i], value[i])
70    
71    
72     class TestShapefileStoreArc(ShapefileStoreTests):
73    
74     """Test cases for ShapefileStore with arc shapes"""
75    
76     def setUp(self):
77     """Initialize self.session"""
78     self.session = Session("Test Session")
79     self.filename = os.path.join("..", "Data", "iceland",
80     "roads-line.shp")
81     self.store = ShapefileStore(self.session, self.filename)
82    
83     def tearDown(self):
84     """Call self.session.Destroy() and reset self.session to None"""
85     self.session.Destroy()
86     self.session = None
87    
88     def test_shape_type(self):
89     """Test ShapefileStore.ShapeType() with arc shapes"""
90     self.assertEquals(self.store.ShapeType(), SHAPETYPE_ARC)
91    
92     def test_boundingbox(self):
93     """Test ShapefileStore.BoundingBox() with arc shapes"""
94     self.assertFloatSeqEqual(self.store.BoundingBox(),
95     [-24.450359344482422, 63.426830291748047,
96     -13.55668830871582, 66.520111083984375])
97    
98     def test_num_shapes(self):
99     """Test ShapefileStore.NumShapes() with arc shapes"""
100     self.assertEquals(self.store.NumShapes(), 839)
101    
102     def test_shapes_in_region(self):
103     """Test ShapefileStore.ShapesInRegion() with arc shapes"""
104     self.assertEquals(self.store.ShapesInRegion((-24.0, 64.0,
105     -23.75, 64.25)),
106     [613, 726, 838])
107    
108     def test_shape(self):
109     """Test ShapefileStore.Shape() with arc shapes"""
110     self.assertFloatTuplesEqual(self.store.Shape(32).Points(),
111     [(-15.082174301147461, 66.27738189697265),
112     (-15.026350021362305, 66.27339172363281)])
113    
114    
115     class TestShapefileStorePolygon(ShapefileStoreTests):
116    
117     """Test cases for ShapefileStore with plygon shapes"""
118    
119     def setUp(self):
120     """Initialize self.session"""
121     self.session = Session("Test Session")
122     """Test ShapeStore with polygon shapes"""
123     self.filename = os.path.join("..", "Data", "iceland",
124     "political.shp")
125     self.store = ShapefileStore(self.session, self.filename)
126    
127     def tearDown(self):
128     """Call self.session.Destroy() and reset self.session to None"""
129     self.session.Destroy()
130     self.session = None
131    
132     def test_shape_type(self):
133     """Test ShapeStore.ShapeType() with polygon shapes"""
134     self.assertEquals(self.store.ShapeType(), SHAPETYPE_POLYGON)
135    
136     def test_boundingbox(self):
137     """Test ShapefileStore.BoundingBox() with polygon shapes"""
138     self.assertFloatSeqEqual(self.store.BoundingBox(),
139     [-24.546524047851562, 63.286754608154297,
140     -13.495815277099609, 66.563774108886719])
141    
142     def test_num_shapes(self):
143     """Test ShapefileStore.NumShapes() with polygon shapes"""
144     self.assertEquals(self.store.NumShapes(), 156)
145    
146     def test_shapes_in_region(self):
147     """Test ShapefileStore.ShapesInRegion() with polygon shapes"""
148     self.assertEquals(self.store.ShapesInRegion((-24.0, 64.0,
149     -23.9, 64.1)),
150     [91, 92, 144, 146, 148, 150, 152, 153])
151    
152     def test_shape(self):
153     """Test ShapefileStore.Shape() with polygon shapes"""
154     self.assertFloatTuplesEqual(self.store.Shape(4).Points(),
155     [(-22.406391143798828, 64.714111328125),
156     (-22.41621208190918, 64.71600341796875),
157     (-22.406051635742188, 64.719200134277344),
158     (-22.406391143798828, 64.714111328125)])
159    
160     class TestShapefileStorePoint(ShapefileStoreTests):
161    
162     """Test cases for ShapefileStore with plygon shapes"""
163    
164     def setUp(self):
165     """Initialize self.session"""
166     self.session = Session("Test Session")
167     """Test ShapeStore with point shapes"""
168     self.filename = os.path.join("..", "Data", "iceland",
169     "cultural_landmark-point.shp")
170     self.store = ShapefileStore(self.session, self.filename)
171    
172     def tearDown(self):
173     """Call self.session.Destroy() and reset self.session to None"""
174     self.session.Destroy()
175     self.session = None
176    
177     def test_shape_type(self):
178     """Test ShapeStore.ShapeType() with point shapes"""
179     self.assertEquals(self.store.ShapeType(), SHAPETYPE_POINT)
180    
181     def test_boundingbox(self):
182     """Test ShapefileStore.BoundingBox() with point shapes"""
183     self.assertFloatSeqEqual(self.store.BoundingBox(),
184     [-23.806047439575195, 63.405960083007812,
185     -15.12291431427002, 66.36572265625])
186    
187     def test_num_shapes(self):
188     """Test ShapefileStore.NumShapes() with point shapes"""
189     self.assertEquals(self.store.NumShapes(), 34)
190    
191     def test_shapes_in_region(self):
192     """Test ShapefileStore.ShapesInRegion() with point shapes"""
193     self.assertEquals(self.store.ShapesInRegion((-24.0, 64.0,
194     -23.80, 64.1)),
195     [0, 1, 2, 3, 4, 5, 27, 28, 29, 30, 31])
196    
197     def test_shape(self):
198     """Test ShapefileStore.Shape() with point shapes"""
199     self.assertFloatTuplesEqual(self.store.Shape(0).Points(),
200     [(-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