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

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

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

revision 331 by bh, Fri Sep 20 14:34:23 2002 UTC revision 599 by bh, Thu Apr 3 11:37:13 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  import shapelib  import shapelib
23    import dbflib
24    
25  from Thuban.Model.layer import Layer, SHAPETYPE_POLYGON, SHAPETYPE_ARC, \  from Thuban.Model.layer import Layer, SHAPETYPE_POLYGON, SHAPETYPE_ARC, \
26       SHAPETYPE_POINT       SHAPETYPE_POINT
# Line 53  class TestLayer(unittest.TestCase, suppo Line 54  class TestLayer(unittest.TestCase, suppo
54                                    -13.55668830871582, 66.520111083984375])                                    -13.55668830871582, 66.520111083984375])
55          self.assertEquals(layer.ShapesInRegion((-24.0, 64.0, -23.75, 64.25)),          self.assertEquals(layer.ShapesInRegion((-24.0, 64.0, -23.75, 64.25)),
56                            [613, 726, 838])                            [613, 726, 838])
57            layer.Destroy()
58    
59      def test_polygon_layer(self):      def test_polygon_layer(self):
60          """Test Layer with polygon shapes"""          """Test Layer with polygon shapes"""
# Line 72  class TestLayer(unittest.TestCase, suppo Line 74  class TestLayer(unittest.TestCase, suppo
74                                    -13.495815277099609, 66.563774108886719])                                    -13.495815277099609, 66.563774108886719])
75          self.assertEquals(layer.ShapesInRegion((-24.0, 64.0, -23.9, 64.1)),          self.assertEquals(layer.ShapesInRegion((-24.0, 64.0, -23.9, 64.1)),
76                            [91, 92, 144, 146, 148, 150, 152, 153])                            [91, 92, 144, 146, 148, 150, 152, 153])
77            layer.Destroy()
78    
79      def test_point_layer(self):      def test_point_layer(self):
80          """Test Layer with point shapes"""          """Test Layer with point shapes"""
# Line 89  class TestLayer(unittest.TestCase, suppo Line 92  class TestLayer(unittest.TestCase, suppo
92                                    -15.12291431427002, 66.36572265625])                                    -15.12291431427002, 66.36572265625])
93          self.assertEquals(layer.ShapesInRegion((-24.0, 64.0, -23.80, 64.1)),          self.assertEquals(layer.ShapesInRegion((-24.0, 64.0, -23.80, 64.1)),
94                            [0, 1, 2, 3, 4, 5, 27, 28, 29, 30, 31])                            [0, 1, 2, 3, 4, 5, 27, 28, 29, 30, 31])
95            layer.Destroy()
96    
97      def test_empty_layer(self):      def test_empty_layer(self):
98          """Test Layer with empty shape file"""          """Test Layer with empty shape file"""
# Line 96  class TestLayer(unittest.TestCase, suppo Line 100  class TestLayer(unittest.TestCase, suppo
100          shapefilename = self.temp_file_name("layer_empty.shp")          shapefilename = self.temp_file_name("layer_empty.shp")
101          shp = shapelib.create(shapefilename, shapelib.SHPT_POLYGON)          shp = shapelib.create(shapefilename, shapelib.SHPT_POLYGON)
102          shp.close()          shp.close()
103            # create an empty DBF file too because Thuban can't cope yet
104            # with missing DBF file.
105            dbffilename = self.temp_file_name("layer_empty.dbf")
106            dbf = dbflib.create(dbffilename)
107            dbf.add_field("NAME", dbflib.FTString, 20, 0)
108    
109            # Now try to open it.
110          layer = Layer("Empty Layer", shapefilename)          layer = Layer("Empty Layer", shapefilename)
111          self.assertEquals(layer.BoundingBox(), None)          self.assertEquals(layer.BoundingBox(), None)
112          self.assertEquals(layer.LatLongBoundingBox(), None)          self.assertEquals(layer.LatLongBoundingBox(), None)
113          self.assertEquals(layer.NumShapes(), 0)          self.assertEquals(layer.NumShapes(), 0)
114            layer.Destroy()
115    
116    
117  class TestLayerLegend(unittest.TestCase, support.SubscriberMixin):  class TestLayerLegend(unittest.TestCase, support.SubscriberMixin):
# Line 133  class TestLayerLegend(unittest.TestCase, Line 144  class TestLayerLegend(unittest.TestCase,
144          """Test Layer's initial legend attributes"""          """Test Layer's initial legend attributes"""
145          # test default settings          # test default settings
146          self.failIf(self.layer.WasModified())          self.failIf(self.layer.WasModified())
147          self.assertEquals(self.layer.fill, None)          #self.assertEquals(self.layer.fill, None)
148          self.assertEquals(self.layer.stroke.hex(), "#000000")          #self.assertEquals(self.layer.stroke.hex(), "#000000")
149          self.assertEquals(self.layer.stroke_width, 1)          #self.assertEquals(self.layer.stroke_width, 1)
150          self.assertEquals(self.layer.Visible(), 1)          self.assertEquals(self.layer.Visible(), 1)
151          # no messages should have been produced          # no messages should have been produced
152          self.check_messages([])          self.check_messages([])
153    
     def test_fill(self):  
         """Test Layer's fill attribute"""  
         # modify the fill  
         self.layer.SetFill(Color(0.5, 1.0, 0.75))  
         self.check_messages([(self.layer, LAYER_LEGEND_CHANGED)])  
         self.assertEquals(self.layer.fill.hex().lower(), "#7fffbf")  
         self.assert_(self.layer.WasModified())  
   
     def test_stroke(self):  
         """Test Layer's stroke attribute"""  
         self.layer.SetStroke(Color(0.5, 1.0, 0.75))  
         self.assertEquals(self.layer.stroke.hex().lower(), "#7fffbf")  
         self.check_messages([(self.layer, LAYER_LEGEND_CHANGED)])  
         self.assert_(self.layer.WasModified())  
   
     def test_stroke_width(self):  
         """Test Layer's stroke_width attribute"""  
         self.layer.SetStrokeWidth(3.0)  
         self.assertEquals(self.layer.stroke_width, 3.0)  
         self.check_messages([(self.layer, LAYER_LEGEND_CHANGED)])  
         self.assert_(self.layer.WasModified())  
   
154      def test_visibility(self):      def test_visibility(self):
155          """Test Layer visibility"""          """Test Layer visibility"""
156          self.layer.SetVisible(0)          self.layer.SetVisible(0)
# Line 172  class TestLayerLegend(unittest.TestCase, Line 161  class TestLayerLegend(unittest.TestCase,
161          # the layer.          # the layer.
162          self.failIf(self.layer.WasModified())          self.failIf(self.layer.WasModified())
163    
164      def test_tree_info(self):      
165          """Test Layer.TreeInfo"""  #
166          self.assertEquals(self.layer.TreeInfo(),  # the tree info now contains Color objects which are difficult to test
167                            ("Layer 'Test Layer'",  #
168                             ['Shown',  #   def test_tree_info(self):
169                              'Shapes: 156',  #       """Test Layer.TreeInfo"""
170                              ('Extent (lat-lon):'  #       self.assertEquals(self.layer.TreeInfo(),
171                               ' (-24.5465, 63.2868, -13.4958, 66.5638)'),  #                         ("Layer 'Test Layer'",
172                              'Shapetype: Polygon',  #                          ['Shown',
173                              'Fill: None',  #                           'Shapes: 156',
174                              'Outline: (0.000, 0.000, 0.000)']))  #                           ('Extent (lat-lon):'
175    #                            ' (-24.5465, 63.2868, -13.4958, 66.5638)'),
176    #                           'Shapetype: Polygon',
177    #                           'Fill: None',
178    #                           'Outline: (0.000, 0.000, 0.000)']))
179    
180    
181  if __name__ == "__main__":  if __name__ == "__main__":
182      unittest.main()      support.run_tests()

Legend:
Removed from v.331  
changed lines
  Added in v.599

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26