/[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 1577 - (hide annotations)
Mon Aug 11 12:08:28 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: 7834 byte(s)
(ShapefileStoreTests.assertPointListEquals): Removed. It's now in
FloatComparisonMixin

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     self.assertEquals(self.store.ShapesInRegion((-24.0, 64.0,
111     -23.75, 64.25)),
112     [613, 726, 838])
113    
114     def test_shape(self):
115     """Test ShapefileStore.Shape() with arc shapes"""
116 bh 1551 self.assertPointListEquals(self.store.Shape(32).Points(),
117     [[(-15.0821743011474, 66.2773818969726),
118     (-15.0263500213623, 66.2733917236328)]])
119 bh 1537
120    
121     class TestShapefileStorePolygon(ShapefileStoreTests):
122    
123     """Test cases for ShapefileStore with plygon shapes"""
124    
125     def setUp(self):
126     """Initialize self.session"""
127     self.session = Session("Test Session")
128     """Test ShapeStore with polygon shapes"""
129     self.filename = os.path.join("..", "Data", "iceland",
130     "political.shp")
131     self.store = ShapefileStore(self.session, self.filename)
132    
133     def tearDown(self):
134     """Call self.session.Destroy() and reset self.session to None"""
135     self.session.Destroy()
136     self.session = None
137    
138     def test_shape_type(self):
139     """Test ShapeStore.ShapeType() with polygon shapes"""
140     self.assertEquals(self.store.ShapeType(), SHAPETYPE_POLYGON)
141    
142     def test_boundingbox(self):
143     """Test ShapefileStore.BoundingBox() with polygon shapes"""
144     self.assertFloatSeqEqual(self.store.BoundingBox(),
145     [-24.546524047851562, 63.286754608154297,
146     -13.495815277099609, 66.563774108886719])
147    
148     def test_num_shapes(self):
149     """Test ShapefileStore.NumShapes() with polygon shapes"""
150     self.assertEquals(self.store.NumShapes(), 156)
151    
152     def test_shapes_in_region(self):
153     """Test ShapefileStore.ShapesInRegion() with polygon shapes"""
154     self.assertEquals(self.store.ShapesInRegion((-24.0, 64.0,
155     -23.9, 64.1)),
156     [91, 92, 144, 146, 148, 150, 152, 153])
157    
158     def test_shape(self):
159     """Test ShapefileStore.Shape() with polygon shapes"""
160 bh 1551 self.assertPointListEquals(self.store.Shape(4).Points(),
161     [[(-22.40639114379882, 64.714111328125),
162     (-22.41621208190918, 64.716003417968),
163     (-22.40605163574218, 64.719200134277),
164     (-22.40639114379882, 64.714111328125)]])
165 bh 1537
166     class TestShapefileStorePoint(ShapefileStoreTests):
167    
168     """Test cases for ShapefileStore with plygon shapes"""
169    
170     def setUp(self):
171     """Initialize self.session"""
172     self.session = Session("Test Session")
173     """Test ShapeStore with point shapes"""
174     self.filename = os.path.join("..", "Data", "iceland",
175     "cultural_landmark-point.shp")
176     self.store = ShapefileStore(self.session, self.filename)
177    
178     def tearDown(self):
179     """Call self.session.Destroy() and reset self.session to None"""
180     self.session.Destroy()
181     self.session = None
182    
183     def test_shape_type(self):
184     """Test ShapeStore.ShapeType() with point shapes"""
185     self.assertEquals(self.store.ShapeType(), SHAPETYPE_POINT)
186    
187     def test_boundingbox(self):
188     """Test ShapefileStore.BoundingBox() with point shapes"""
189     self.assertFloatSeqEqual(self.store.BoundingBox(),
190     [-23.806047439575195, 63.405960083007812,
191     -15.12291431427002, 66.36572265625])
192    
193     def test_num_shapes(self):
194     """Test ShapefileStore.NumShapes() with point shapes"""
195     self.assertEquals(self.store.NumShapes(), 34)
196    
197     def test_shapes_in_region(self):
198     """Test ShapefileStore.ShapesInRegion() with point shapes"""
199     self.assertEquals(self.store.ShapesInRegion((-24.0, 64.0,
200     -23.80, 64.1)),
201     [0, 1, 2, 3, 4, 5, 27, 28, 29, 30, 31])
202    
203     def test_shape(self):
204     """Test ShapefileStore.Shape() with point shapes"""
205 bh 1551 self.assertPointListEquals(self.store.Shape(0).Points(),
206     [[(-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