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

Contents of /branches/WIP-pyshapelib-bramz/test/test_map.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 332 - (show annotations)
Fri Sep 20 15:45:59 2002 UTC (22 years, 5 months ago) by bh
Original Path: trunk/thuban/test/test_map.py
File MIME type: text/x-python
File size: 9327 byte(s)
New. Test cases for Thuban.Model.map

1 # Copyright (c) 2002 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 Thuban for details.
7
8 """
9 Test the Map class
10 """
11
12 __version__ = "$Revision$"
13 # $Source$
14 # $Id$
15
16 import os
17 import unittest
18
19 import support
20 support.initthuban()
21
22 from Thuban.Model.messages import CHANGED, MAP_PROJECTION_CHANGED, \
23 LAYERS_CHANGED, LAYER_VISIBILITY_CHANGED, LAYER_LEGEND_CHANGED
24 from Thuban.Model.map import Map
25 from Thuban.Model.layer import Layer
26 from Thuban.Model.proj import Projection
27 from Thuban.Model.color import Color
28
29
30 class TestMapSimple(unittest.TestCase):
31
32 """Very simple test cases for Map"""
33
34 def test_initial_state(self):
35 """Test Map's initial state"""
36 map = Map("Test Map")
37 self.assertEquals(map.Title(), "Test Map")
38 self.assertEquals(map.Layers(), [])
39 label_layer = map.LabelLayer()
40 self.assertEquals(label_layer.Title(), "Labels")
41 self.assertEquals(label_layer.Labels(), [])
42 self.failIf(map.WasModified())
43 map.Destroy()
44
45 def test_empty_map(self):
46 """Test empty Map"""
47 map = Map("Test Map")
48 self.assertEquals(map.BoundingBox(), None)
49 self.assertEquals(map.ProjectedBoundingBox(), None)
50 self.failIf(map.HasLayers())
51 map.Destroy()
52
53
54 class TestMapBase(unittest.TestCase, support.SubscriberMixin):
55
56 """Base class for Map test cases that test messages"""
57
58 def setUp(self):
59 """
60 Clear the message list, create self.map and subscribe to its messages
61 """
62 self.clear_messages()
63
64 # Create a Map and subscribe to all interesting channels.
65 self.map = Map("Test Map")
66 for channel in (CHANGED, MAP_PROJECTION_CHANGED, LAYERS_CHANGED,
67 LAYER_VISIBILITY_CHANGED, LAYER_LEGEND_CHANGED):
68 self.map.Subscribe(channel, self.subscribe_with_params, channel)
69
70 def tearDown(self):
71 """Destroy self.map and clear the message list"""
72 self.map.Destroy()
73 self.clear_messages()
74
75
76 class TestMapAddLayer(TestMapBase):
77
78 """Simple test cases involving messages"""
79
80 def test_add_layer(self):
81 """Test Map.AddLayer"""
82 # make sure the created Map is unmodified
83 self.failIf(self.map.WasModified())
84 self.failIf(self.map.HasLayers())
85
86 # add a layer and check the result
87 roads = Layer("Roads",
88 os.path.join("..", "Data", "iceland", "roads-line.shp"))
89 self.map.AddLayer(roads)
90 self.assertEquals(self.map.Layers(), [roads])
91 self.check_messages([(self.map, LAYERS_CHANGED)])
92 self.assert_(self.map.WasModified())
93 self.assert_(self.map.HasLayers())
94
95
96 class TestMapWithContents(TestMapBase, support.FloatComparisonMixin):
97
98 """More complex Map test cases with messages that.
99
100 All test cases here start with a non-empty map.
101 """
102
103 def setUp(self):
104 """Extend the inherited method to also fill the Map.
105
106 Put some layers into the map created by the inherited method and
107 reset its modified flag. Make also sure that the list of
108 received messages is empty.
109 """
110 TestMapBase.setUp(self)
111 self.arc_layer = Layer("Roads",
112 os.path.join("..", "Data", "iceland",
113 "roads-line.shp"))
114 self.poly_layer = Layer("Political",
115 os.path.join("..", "Data", "iceland",
116 "political.shp"))
117 self.map.AddLayer(self.arc_layer)
118 self.map.AddLayer(self.poly_layer)
119 self.map.UnsetModified()
120 self.clear_messages()
121
122 def test_remove_layer(self):
123 """Test Map.RemoveLayer"""
124 self.map.RemoveLayer(self.arc_layer)
125 self.assert_(self.map.WasModified())
126 self.assertEquals(self.map.Layers(), [self.poly_layer])
127 self.map.UnsetModified()
128 self.check_messages([(self.map, LAYERS_CHANGED),
129 (CHANGED,)])
130
131 def test_clear_layers(self):
132 """Test Map.ClearLayers"""
133 self.map.ClearLayers()
134 self.assertEquals(self.map.Layers(), [])
135 self.assertEquals(self.map.LabelLayer().Labels(), [])
136 self.check_messages([(LAYERS_CHANGED,),
137 (self.map, LAYERS_CHANGED)])
138 self.assert_(self.map.WasModified())
139 self.failIf(self.map.HasLayers())
140
141 def test_raise_layer(self):
142 """Test Map.RaiseLayer"""
143 self.map.RaiseLayer(self.arc_layer)
144 self.assertEquals(self.map.Layers(), [self.poly_layer, self.arc_layer])
145 self.check_messages([(self.map, LAYERS_CHANGED)])
146 self.assert_(self.map.WasModified())
147
148 def test_raise_highest_layer(self):
149 """Test Map.RaiseLayer with highest layer
150
151 Attempting to raise the highest layer should not modify the map.
152 In particular it should not send any messages.
153 """
154 self.map.RaiseLayer(self.poly_layer)
155 self.assertEquals(self.map.Layers(), [self.arc_layer, self.poly_layer])
156 self.check_messages([])
157 self.failIf(self.map.WasModified())
158
159 def test_lower_layer(self):
160 """Test Map.LowerLayer"""
161 self.map.LowerLayer(self.poly_layer)
162 self.assertEquals(self.map.Layers(), [self.poly_layer, self.arc_layer])
163 self.check_messages([(self.map, LAYERS_CHANGED)])
164 self.assert_(self.map.WasModified())
165
166 def test_lower_lowest_layer(self):
167 """Test Map.LowerLayer with lowest layer.
168
169 Attempting to lower the lowest layer should not modify the map.
170 In particular it should not send any messages.
171 """
172 self.map.LowerLayer(self.arc_layer)
173 self.assertEquals(self.map.Layers(), [self.arc_layer, self.poly_layer])
174 self.check_messages([])
175 self.failIf(self.map.WasModified())
176
177 def test_bounding_box(self):
178 """Test Map.BoundingBox"""
179 self.assertFloatSeqEqual(self.map.BoundingBox(),
180 (-24.546524047851562, 63.286754608154297,
181 -13.495815277099609, 66.563774108886719))
182
183 def test_projected_bounding_box(self):
184 """Test Map.ProjectedBoundingBox"""
185 proj = Projection(["zone=26", "proj=utm", "ellps=clrk66"])
186 self.map.SetProjection(proj)
187 self.assertFloatSeqEqual(self.map.ProjectedBoundingBox(),
188 (608873.03380603762, 7019694.6517963577,
189 1173560.0288053728, 7447353.2203218574))
190
191 def test_set_projection(self):
192 """Test Map.SetProjection"""
193 proj = Projection(["zone=26", "proj=utm", "ellps=clrk66"])
194 self.map.SetProjection(proj)
195 self.check_messages([(self.map, MAP_PROJECTION_CHANGED)])
196 self.assert_(self.map.WasModified())
197
198 def test_tree_info(self):
199 """Test Map.TreeInfo"""
200 proj = Projection(["zone=26", "proj=utm", "ellps=clrk66"])
201 self.map.SetProjection(proj)
202 self.assertEquals(self.map.TreeInfo(),
203 ('Map: Test Map',
204 [('Extent (lat-lon):'
205 ' (-24.5465, 63.2868, -13.4958, 66.5638)'),
206 ('Extent (projected):'
207 ' (608873, 7.01969e+06, 1.17356e+06, 7.44735e+06)'),
208 ('Projection',
209 ['zone=26', 'proj=utm', 'ellps=clrk66']),
210 self.poly_layer,
211 self.arc_layer]))
212
213 def test_forwarding_fill(self):
214 """Test Map's forwarding of Layer.SetFill messages"""
215 self.poly_layer.SetFill(Color(0.0, 0.5, 1.0))
216 self.check_messages([(self.poly_layer, LAYER_LEGEND_CHANGED)])
217
218 def test_forwarding_stroke(self):
219 """Test Map's forwarding of Layer.SetStroke messages"""
220 self.poly_layer.SetStroke(Color(0.0, 0.5, 1.0))
221 self.check_messages([(self.poly_layer, LAYER_LEGEND_CHANGED)])
222
223 def test_forwarding_stroke_width(self):
224 """Test Map's forwarding of Layer.SetStrokeWidth messages"""
225 self.poly_layer.SetStrokeWidth(3)
226 self.check_messages([(self.poly_layer, LAYER_LEGEND_CHANGED)])
227
228 def test_forwarding_visibility(self):
229 """Test Map's forwarding of Layer.SetVisible messages"""
230 self.poly_layer.SetVisible(0)
231 self.check_messages([(self.poly_layer, LAYER_VISIBILITY_CHANGED)])
232
233 def test_unset_modified(self):
234 """Test Map.UnsetModified.
235
236 Test whether a change to a layer results in the map being
237 considered modified and test whether then calling the map's
238 UnsetModified clears the changed flag in the layer as well.
239 """
240 self.failIf(self.map.WasModified())
241 self.poly_layer.SetFill(Color(0.0, 0.5, 1.0))
242 self.assert_(self.map.WasModified())
243 self.map.UnsetModified()
244 self.failIf(self.map.WasModified())
245 self.failIf(self.poly_layer.WasModified())
246 self.check_messages([(self.poly_layer, LAYER_LEGEND_CHANGED),
247 (CHANGED,)
248 ])
249
250 if __name__ == "__main__":
251 unittest.main()

Properties

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26