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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 395 - (hide annotations)
Mon Feb 10 15:28:02 2003 UTC (22 years ago) by jonathan
Original Path: trunk/thuban/test/test_map.py
File MIME type: text/x-python
File size: 8966 byte(s)
fix tests to work with new code changes.

1 bh 332 # 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 bh 343 1173560.0288053728, 7447353.2203218574),
190     epsilon = 1e-5)
191 bh 332
192     def test_set_projection(self):
193     """Test Map.SetProjection"""
194     proj = Projection(["zone=26", "proj=utm", "ellps=clrk66"])
195     self.map.SetProjection(proj)
196     self.check_messages([(self.map, MAP_PROJECTION_CHANGED)])
197     self.assert_(self.map.WasModified())
198    
199     def test_tree_info(self):
200     """Test Map.TreeInfo"""
201     proj = Projection(["zone=26", "proj=utm", "ellps=clrk66"])
202     self.map.SetProjection(proj)
203 bh 337 # compute the extent string because there are platform
204     # differences in the way %g is handled:
205     # glibc: "%g" % 7.01969e+06 == "7.01969e+06"
206     # w32/VC: "%g" % 7.01969e+06 == "7.01969e+006"
207     extent = 'Extent (projected): (%g, %g, %g, %g)'\
208     % (608873, 7.01969e+06, 1.17356e+06, 7.44735e+06)
209 bh 332 self.assertEquals(self.map.TreeInfo(),
210     ('Map: Test Map',
211     [('Extent (lat-lon):'
212     ' (-24.5465, 63.2868, -13.4958, 66.5638)'),
213 bh 337 extent,
214 bh 332 ('Projection',
215     ['zone=26', 'proj=utm', 'ellps=clrk66']),
216     self.poly_layer,
217     self.arc_layer]))
218    
219     def test_forwarding_visibility(self):
220     """Test Map's forwarding of Layer.SetVisible messages"""
221     self.poly_layer.SetVisible(0)
222     self.check_messages([(self.poly_layer, LAYER_VISIBILITY_CHANGED)])
223    
224     def test_unset_modified(self):
225     """Test Map.UnsetModified.
226    
227     Test whether a change to a layer results in the map being
228     considered modified and test whether then calling the map's
229     UnsetModified clears the changed flag in the layer as well.
230     """
231     self.failIf(self.map.WasModified())
232 jonathan 395 self.poly_layer.classification.SetDefaultFill(Color(0.0, 0.5, 1.0))
233 bh 332 self.assert_(self.map.WasModified())
234     self.map.UnsetModified()
235     self.failIf(self.map.WasModified())
236     self.failIf(self.poly_layer.WasModified())
237     self.check_messages([(self.poly_layer, LAYER_LEGEND_CHANGED),
238     (CHANGED,)
239     ])
240    
241     if __name__ == "__main__":
242     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