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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/thuban/test/test_map.py revision 584 by jonathan, Tue Apr 1 10:22:35 2003 UTC branches/WIP-pyshapelib-bramz/test/test_map.py revision 2734 by bramz, Thu Mar 1 12:42:59 2007 UTC
# Line 1  Line 1 
1  # Copyright (c) 2002 by Intevation GmbH  # Copyright (c) 2002, 2003 by Intevation GmbH
2  # Authors:  # Authors:
3  # Bernhard Herzog <[email protected]>  # Bernhard Herzog <[email protected]>
4  #  #
# Line 19  import unittest Line 19  import unittest
19  import support  import support
20  support.initthuban()  support.initthuban()
21    
22  from Thuban.Model.messages import *  from Thuban.Model.messages import CHANGED, MAP_PROJECTION_CHANGED, \
23  #CHANGED, MAP_PROJECTION_CHANGED, \ MAP_LAYERS_CHANGED, LAYER_VISIBILITY_CHANGED, LAYER_LEGEND_CHANGED       MAP_LAYERS_CHANGED, MAP_LAYERS_ADDED, MAP_LAYERS_REMOVED,\
24         MAP_STACKING_CHANGED, LAYER_VISIBILITY_CHANGED, LAYER_LEGEND_CHANGED, \
25         LAYER_CHANGED
26    
27    from Thuban.Model.session import Session
28  from Thuban.Model.map import Map  from Thuban.Model.map import Map
29  from Thuban.Model.layer import Layer  from Thuban.Model.layer import Layer
30  from Thuban.Model.proj import Projection  from Thuban.Model.proj import Projection
# Line 75  class TestMapBase(unittest.TestCase, sup Line 79  class TestMapBase(unittest.TestCase, sup
79              self.map.Subscribe(channel, self.subscribe_with_params, channel)              self.map.Subscribe(channel, self.subscribe_with_params, channel)
80    
81      def tearDown(self):      def tearDown(self):
82          """Destroy self.map and clear the message list"""          """Destroy self.map and self.session and clear the message list"""
83            if hasattr(self, "session"):
84                self.session.Destroy()
85                self.session = None
86          self.map.Destroy()          self.map.Destroy()
87            self.map = None
88          self.clear_messages()          self.clear_messages()
89    
90    
# Line 87  class TestMapAddLayer(TestMapBase): Line 95  class TestMapAddLayer(TestMapBase):
95      def test_add_layer(self):      def test_add_layer(self):
96          """Test Map.AddLayer"""          """Test Map.AddLayer"""
97          # make sure the created Map is unmodified          # make sure the created Map is unmodified
98            session = self.session = Session("Test session for %s" %self.__class__)
99          self.failIf(self.map.WasModified())          self.failIf(self.map.WasModified())
100          self.failIf(self.map.HasLayers())          self.failIf(self.map.HasLayers())
101    
102          # add a layer and check the result          # add a layer and check the result
103          roads = Layer("Roads",          filename = os.path.join("..", "Data", "iceland", "roads-line.shp")
104                        os.path.join("..", "Data", "iceland", "roads-line.shp"))          roads = Layer("Roads", session.OpenShapefile(filename))
105          self.map.AddLayer(roads)          self.map.AddLayer(roads)
106          self.assertEquals(self.map.Layers(), [roads])          self.assertEquals(self.map.Layers(), [roads])
107          self.check_messages([(self.map, MAP_LAYERS_CHANGED),          self.check_messages([(self.map, MAP_LAYERS_CHANGED),
# Line 116  class TestMapWithContents(TestMapBase, s Line 125  class TestMapWithContents(TestMapBase, s
125          received messages is empty.          received messages is empty.
126          """          """
127          TestMapBase.setUp(self)          TestMapBase.setUp(self)
128            self.session = Session("Test session for %s" % self.__class__)
129            open_shp = self.session.OpenShapefile
130          self.arc_layer = Layer("Roads",          self.arc_layer = Layer("Roads",
131                                 os.path.join("..", "Data", "iceland",                                 open_shp(os.path.join("..", "Data", "iceland",
132                                              "roads-line.shp"))                                                       "roads-line.shp")))
133          self.poly_layer = Layer("Political",          self.poly_layer = Layer("Political",
134                                  os.path.join("..", "Data", "iceland",                                  open_shp(os.path.join("..", "Data", "iceland",
135                                               "political.shp"))                                                        "political.shp")))
136          self.map.AddLayer(self.arc_layer)          self.map.AddLayer(self.arc_layer)
137          self.map.AddLayer(self.poly_layer)          self.map.AddLayer(self.poly_layer)
138          self.map.UnsetModified()          self.map.UnsetModified()
139          self.clear_messages()          self.clear_messages()
140    
141        def tearDown(self):
142            TestMapBase.tearDown(self)
143            self.session = None
144            self.map = None
145            self.poly_layer = self.arc_layer = None
146    
147      def test_remove_layer(self):      def test_remove_layer(self):
148          """Test Map.RemoveLayer"""          """Test Map.RemoveLayer"""
149          self.map.RemoveLayer(self.arc_layer)          self.map.RemoveLayer(self.arc_layer)
# Line 156  class TestMapWithContents(TestMapBase, s Line 173  class TestMapWithContents(TestMapBase, s
173                               (self.map, MAP_STACKING_CHANGED)])                               (self.map, MAP_STACKING_CHANGED)])
174          self.assert_(self.map.WasModified())          self.assert_(self.map.WasModified())
175    
176        def test_raise_layer_top(self):
177            """Test Map.MoveLayerToTop"""
178            open_shp = self.session.OpenShapefile
179            dummy = Layer("Roads",
180                          open_shp(os.path.join("..", "Data", "iceland",
181                                                "roads-line.shp")))
182            self.map.AddLayer(dummy)
183            self.clear_messages()
184    
185            self.map.MoveLayerToTop(self.poly_layer)
186            self.assertEquals(self.map.Layers(),
187                              [self.arc_layer, dummy, self.poly_layer])
188            self.check_messages([(self.map, MAP_LAYERS_CHANGED),
189                                 (self.map, MAP_STACKING_CHANGED)])
190            self.assert_(self.map.WasModified())
191    
192            self.map.RemoveLayer(dummy)
193    
194        def test_lower_layer_bottom(self):
195            """Test Map.MoveLayerToBottom"""
196            open_shp = self.session.OpenShapefile
197            dummy = Layer("Roads",
198                          open_shp(os.path.join("..", "Data", "iceland",
199                                                "roads-line.shp")))
200            self.map.AddLayer(dummy)
201            self.clear_messages()
202    
203            self.map.MoveLayerToBottom(dummy)
204            self.assertEquals(self.map.Layers(),
205                              [dummy, self.arc_layer, self.poly_layer])
206            self.check_messages([(self.map, MAP_LAYERS_CHANGED),
207                                 (self.map, MAP_STACKING_CHANGED)])
208            self.assert_(self.map.WasModified())
209    
210            self.map.RemoveLayer(dummy)
211    
212      def test_raise_highest_layer(self):      def test_raise_highest_layer(self):
213          """Test Map.RaiseLayer with highest layer          """Test Map.RaiseLayer with highest layer
214    
# Line 205  class TestMapWithContents(TestMapBase, s Line 258  class TestMapWithContents(TestMapBase, s
258          """Test Map.SetProjection"""          """Test Map.SetProjection"""
259          proj = Projection(["zone=26", "proj=utm", "ellps=clrk66"])          proj = Projection(["zone=26", "proj=utm", "ellps=clrk66"])
260          self.map.SetProjection(proj)          self.map.SetProjection(proj)
261          self.check_messages([(self.map, MAP_PROJECTION_CHANGED)])          self.check_messages([(self.map, None, MAP_PROJECTION_CHANGED)])
262          self.assert_(self.map.WasModified())          self.assert_(self.map.WasModified())
263    
264      def test_tree_info(self):      def test_tree_info(self):
# Line 226  class TestMapWithContents(TestMapBase, s Line 279  class TestMapWithContents(TestMapBase, s
279                              ('Projection',                              ('Projection',
280                               ['zone=26', 'proj=utm', 'ellps=clrk66']),                               ['zone=26', 'proj=utm', 'ellps=clrk66']),
281                              self.poly_layer,                              self.poly_layer,
282                              self.arc_layer]))                              self.arc_layer,
283                                self.map.LabelLayer()]))
284    
285      def test_forwarding_visibility(self):      def test_forwarding_visibility(self):
286          """Test Map's forwarding of Layer.SetVisible messages"""          """Test Map's forwarding of Layer.SetVisible messages"""
# Line 250  class TestMapWithContents(TestMapBase, s Line 304  class TestMapWithContents(TestMapBase, s
304                               (CHANGED,)])                               (CHANGED,)])
305    
306  if __name__ == "__main__":  if __name__ == "__main__":
307      unittest.main()      support.run_tests()
308    

Legend:
Removed from v.584  
changed lines
  Added in v.2734

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26