/[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

revision 332 by bh, Fri Sep 20 15:45:59 2002 UTC revision 585 by bh, Tue Apr 1 10:41:05 2003 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 20  import support Line 20  import support
20  support.initthuban()  support.initthuban()
21    
22  from Thuban.Model.messages import CHANGED, MAP_PROJECTION_CHANGED, \  from Thuban.Model.messages import CHANGED, MAP_PROJECTION_CHANGED, \
23       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.map import Map  from Thuban.Model.map import Map
28  from Thuban.Model.layer import Layer  from Thuban.Model.layer import Layer
29  from Thuban.Model.proj import Projection  from Thuban.Model.proj import Projection
# Line 63  class TestMapBase(unittest.TestCase, sup Line 66  class TestMapBase(unittest.TestCase, sup
66    
67          # Create a Map and subscribe to all interesting channels.          # Create a Map and subscribe to all interesting channels.
68          self.map = Map("Test Map")          self.map = Map("Test Map")
69          for channel in (CHANGED, MAP_PROJECTION_CHANGED, LAYERS_CHANGED,          for channel in (CHANGED,
70                          LAYER_VISIBILITY_CHANGED, LAYER_LEGEND_CHANGED):                          MAP_PROJECTION_CHANGED,
71                            MAP_LAYERS_CHANGED,
72                            MAP_LAYERS_ADDED,
73                            MAP_LAYERS_REMOVED,
74                            MAP_STACKING_CHANGED,
75                            LAYER_VISIBILITY_CHANGED,
76                            LAYER_LEGEND_CHANGED,
77                            LAYER_CHANGED):
78              self.map.Subscribe(channel, self.subscribe_with_params, channel)              self.map.Subscribe(channel, self.subscribe_with_params, channel)
79    
80      def tearDown(self):      def tearDown(self):
# Line 88  class TestMapAddLayer(TestMapBase): Line 98  class TestMapAddLayer(TestMapBase):
98                        os.path.join("..", "Data", "iceland", "roads-line.shp"))                        os.path.join("..", "Data", "iceland", "roads-line.shp"))
99          self.map.AddLayer(roads)          self.map.AddLayer(roads)
100          self.assertEquals(self.map.Layers(), [roads])          self.assertEquals(self.map.Layers(), [roads])
101          self.check_messages([(self.map, LAYERS_CHANGED)])          self.check_messages([(self.map, MAP_LAYERS_CHANGED),
102                                 (self.map, MAP_LAYERS_ADDED)])
103          self.assert_(self.map.WasModified())          self.assert_(self.map.WasModified())
104          self.assert_(self.map.HasLayers())          self.assert_(self.map.HasLayers())
105    
# Line 125  class TestMapWithContents(TestMapBase, s Line 136  class TestMapWithContents(TestMapBase, s
136          self.assert_(self.map.WasModified())          self.assert_(self.map.WasModified())
137          self.assertEquals(self.map.Layers(), [self.poly_layer])          self.assertEquals(self.map.Layers(), [self.poly_layer])
138          self.map.UnsetModified()          self.map.UnsetModified()
139          self.check_messages([(self.map, LAYERS_CHANGED),          self.check_messages([(self.map, MAP_LAYERS_CHANGED),
140                                 (self.map, MAP_LAYERS_REMOVED),
141                               (CHANGED,)])                               (CHANGED,)])
142    
143      def test_clear_layers(self):      def test_clear_layers(self):
# Line 133  class TestMapWithContents(TestMapBase, s Line 145  class TestMapWithContents(TestMapBase, s
145          self.map.ClearLayers()          self.map.ClearLayers()
146          self.assertEquals(self.map.Layers(), [])          self.assertEquals(self.map.Layers(), [])
147          self.assertEquals(self.map.LabelLayer().Labels(), [])          self.assertEquals(self.map.LabelLayer().Labels(), [])
148          self.check_messages([(LAYERS_CHANGED,),          self.check_messages([(MAP_LAYERS_CHANGED,),
149                               (self.map, LAYERS_CHANGED)])                               (self.map, MAP_LAYERS_CHANGED),
150                                 (self.map, MAP_LAYERS_REMOVED)])
151          self.assert_(self.map.WasModified())          self.assert_(self.map.WasModified())
152          self.failIf(self.map.HasLayers())          self.failIf(self.map.HasLayers())
153    
# Line 142  class TestMapWithContents(TestMapBase, s Line 155  class TestMapWithContents(TestMapBase, s
155          """Test Map.RaiseLayer"""          """Test Map.RaiseLayer"""
156          self.map.RaiseLayer(self.arc_layer)          self.map.RaiseLayer(self.arc_layer)
157          self.assertEquals(self.map.Layers(), [self.poly_layer, self.arc_layer])          self.assertEquals(self.map.Layers(), [self.poly_layer, self.arc_layer])
158          self.check_messages([(self.map, LAYERS_CHANGED)])          self.check_messages([(self.map, MAP_LAYERS_CHANGED),
159                                 (self.map, MAP_STACKING_CHANGED)])
160          self.assert_(self.map.WasModified())          self.assert_(self.map.WasModified())
161    
162      def test_raise_highest_layer(self):      def test_raise_highest_layer(self):
# Line 160  class TestMapWithContents(TestMapBase, s Line 174  class TestMapWithContents(TestMapBase, s
174          """Test Map.LowerLayer"""          """Test Map.LowerLayer"""
175          self.map.LowerLayer(self.poly_layer)          self.map.LowerLayer(self.poly_layer)
176          self.assertEquals(self.map.Layers(), [self.poly_layer, self.arc_layer])          self.assertEquals(self.map.Layers(), [self.poly_layer, self.arc_layer])
177          self.check_messages([(self.map, LAYERS_CHANGED)])          self.check_messages([(self.map, MAP_LAYERS_CHANGED),
178                                 (self.map, MAP_STACKING_CHANGED)])
179          self.assert_(self.map.WasModified())          self.assert_(self.map.WasModified())
180    
181      def test_lower_lowest_layer(self):      def test_lower_lowest_layer(self):
# Line 186  class TestMapWithContents(TestMapBase, s Line 201  class TestMapWithContents(TestMapBase, s
201          self.map.SetProjection(proj)          self.map.SetProjection(proj)
202          self.assertFloatSeqEqual(self.map.ProjectedBoundingBox(),          self.assertFloatSeqEqual(self.map.ProjectedBoundingBox(),
203                                   (608873.03380603762, 7019694.6517963577,                                   (608873.03380603762, 7019694.6517963577,
204                                    1173560.0288053728, 7447353.2203218574))                                    1173560.0288053728, 7447353.2203218574),
205                                     epsilon = 1e-5)
206    
207      def test_set_projection(self):      def test_set_projection(self):
208          """Test Map.SetProjection"""          """Test Map.SetProjection"""
# Line 199  class TestMapWithContents(TestMapBase, s Line 215  class TestMapWithContents(TestMapBase, s
215          """Test Map.TreeInfo"""          """Test Map.TreeInfo"""
216          proj = Projection(["zone=26", "proj=utm", "ellps=clrk66"])          proj = Projection(["zone=26", "proj=utm", "ellps=clrk66"])
217          self.map.SetProjection(proj)          self.map.SetProjection(proj)
218            # compute the extent string because there are platform
219            # differences in the way %g is handled:
220            # glibc: "%g" % 7.01969e+06 == "7.01969e+06"
221            # w32/VC: "%g" % 7.01969e+06 == "7.01969e+006"
222            extent = 'Extent (projected): (%g, %g, %g, %g)'\
223                     % (608873, 7.01969e+06, 1.17356e+06, 7.44735e+06)
224          self.assertEquals(self.map.TreeInfo(),          self.assertEquals(self.map.TreeInfo(),
225                            ('Map: Test Map',                            ('Map: Test Map',
226                             [('Extent (lat-lon):'                             [('Extent (lat-lon):'
227                               ' (-24.5465, 63.2868, -13.4958, 66.5638)'),                               ' (-24.5465, 63.2868, -13.4958, 66.5638)'),
228                              ('Extent (projected):'                              extent,
                           ' (608873, 7.01969e+06, 1.17356e+06, 7.44735e+06)'),  
229                              ('Projection',                              ('Projection',
230                               ['zone=26', 'proj=utm', 'ellps=clrk66']),                               ['zone=26', 'proj=utm', 'ellps=clrk66']),
231                              self.poly_layer,                              self.poly_layer,
232                              self.arc_layer]))                              self.arc_layer]))
233    
     def test_forwarding_fill(self):  
         """Test Map's forwarding of Layer.SetFill messages"""  
         self.poly_layer.SetFill(Color(0.0, 0.5, 1.0))  
         self.check_messages([(self.poly_layer, LAYER_LEGEND_CHANGED)])  
   
     def test_forwarding_stroke(self):  
         """Test Map's forwarding of Layer.SetStroke messages"""  
         self.poly_layer.SetStroke(Color(0.0, 0.5, 1.0))  
         self.check_messages([(self.poly_layer, LAYER_LEGEND_CHANGED)])  
   
     def test_forwarding_stroke_width(self):  
         """Test Map's forwarding of Layer.SetStrokeWidth messages"""  
         self.poly_layer.SetStrokeWidth(3)  
         self.check_messages([(self.poly_layer, LAYER_LEGEND_CHANGED)])  
   
234      def test_forwarding_visibility(self):      def test_forwarding_visibility(self):
235          """Test Map's forwarding of Layer.SetVisible messages"""          """Test Map's forwarding of Layer.SetVisible messages"""
236          self.poly_layer.SetVisible(0)          self.poly_layer.SetVisible(0)
# Line 238  class TestMapWithContents(TestMapBase, s Line 244  class TestMapWithContents(TestMapBase, s
244          UnsetModified clears the changed flag in the layer as well.          UnsetModified clears the changed flag in the layer as well.
245          """          """
246          self.failIf(self.map.WasModified())          self.failIf(self.map.WasModified())
247          self.poly_layer.SetFill(Color(0.0, 0.5, 1.0))          self.poly_layer.GetClassification().SetDefaultFill(Color(0.0, 0.5, 1.0))
248          self.assert_(self.map.WasModified())          self.assert_(self.map.WasModified())
249          self.map.UnsetModified()          self.map.UnsetModified()
250          self.failIf(self.map.WasModified())          self.failIf(self.map.WasModified())
251          self.failIf(self.poly_layer.WasModified())          self.failIf(self.poly_layer.WasModified())
252          self.check_messages([(self.poly_layer, LAYER_LEGEND_CHANGED),          self.check_messages([(self.poly_layer, LAYER_CHANGED),
253                               (CHANGED,)                               (CHANGED,)])
                              ])  
254    
255  if __name__ == "__main__":  if __name__ == "__main__":
256      unittest.main()      unittest.main()

Legend:
Removed from v.332  
changed lines
  Added in v.585

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26