/[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 1278 by jonathan, Fri Jun 20 17:46:58 2003 UTC revision 1538 by bh, Fri Aug 1 14:27:46 2003 UTC
# Line 23  import shapelib Line 23  import shapelib
23  import dbflib  import dbflib
24    
25  from Thuban.Model.session import Session  from Thuban.Model.session import Session
26  from Thuban.Model.layer import BaseLayer, Layer, RasterLayer, \  from Thuban.Model.layer import BaseLayer, Layer, RasterLayer
27       SHAPETYPE_POLYGON, SHAPETYPE_ARC, SHAPETYPE_POINT  from Thuban.Model.data import SHAPETYPE_POLYGON, SHAPETYPE_ARC, SHAPETYPE_POINT
28  from Thuban.Model.messages import LAYER_LEGEND_CHANGED, \  from Thuban.Model.messages import LAYER_LEGEND_CHANGED, \
29       LAYER_VISIBILITY_CHANGED, LAYER_SHAPESTORE_REPLACED, LAYER_CHANGED       LAYER_VISIBILITY_CHANGED, LAYER_SHAPESTORE_REPLACED, LAYER_CHANGED
 from Thuban.Model.color import Color  
30  from Thuban.Model.table import FIELDTYPE_DOUBLE, FIELDTYPE_STRING, MemoryTable  from Thuban.Model.table import FIELDTYPE_DOUBLE, FIELDTYPE_STRING, MemoryTable
31  from Thuban.Model.proj import Projection  from Thuban.Model.proj import Projection
32  from Thuban.Model.data import DerivedShapeStore  from Thuban.Model.data import DerivedShapeStore
33  from Thuban.Model.classification import Classification, ClassGroupSingleton  from Thuban.Model.classification import Classification, ClassGroupSingleton, \
34         ClassGroupRange
35    
36  import Thuban.Model.resource  import Thuban.Model.resource
37    
# Line 217  class TestLayer(unittest.TestCase, suppo Line 217  class TestLayer(unittest.TestCase, suppo
217              layer.SetShapeStore(derived)              layer.SetShapeStore(derived)
218              self.assert_(layer.ShapeStore() is derived)              self.assert_(layer.ShapeStore() is derived)
219    
220              # check that an exception is raised when the number              self.assertEquals(layer.ShapeType(), SHAPETYPE_ARC)
221              # of shapes differ from the number of rows in a table.              self.assertEquals(layer.NumShapes(), 839)
222              layer2 = Layer("Test Layer",              shape = layer.Shape(32)
223                             self.open_shapefile("political.shp"))              self.assertFloatTuplesEqual(shape.Points(),
224              store2 = layer2.ShapeStore()                                      [(-15.082174301147461, 66.27738189697265),
225              self.assertRaises(ValueError,                                       (-15.026350021362305, 66.27339172363281)])
226                                DerivedShapeStore, store2, store.Table())              self.assertFloatSeqEqual(layer.BoundingBox(),
227                                         [-24.450359344482422, 63.426830291748047,
228                                          -13.55668830871582, 66.520111083984375])
229                self.assertEquals(layer.ShapesInRegion((-24.0, 64.0,
230                                                        -23.75, 64.25)),
231                                  [613, 726, 838])
232    
233                self.assertFloatSeqEqual(layer.ShapesBoundingBox([32]),
234                                         [-15.082174301147461, 66.27339172363281,
235                                          -15.026350021362305, 66.27738189697265])
236    
237          finally:          finally:
238              store = derived = None              store = derived = None
             layer2.Destroy()  
             store2 = None  
239    
240    
241  class SetShapeStoreTests(unittest.TestCase, support.SubscriberMixin):  class SetShapeStoreTests(unittest.TestCase, support.SubscriberMixin):
# Line 241  class SetShapeStoreTests(unittest.TestCa Line 248  class SetShapeStoreTests(unittest.TestCa
248                                            "cultural_landmark-point.dbf")                                            "cultural_landmark-point.dbf")
249          self.store = self.session.OpenShapefile(self.shapefilename)          self.store = self.session.OpenShapefile(self.shapefilename)
250          self.layer = Layer("test layer", self.store)          self.layer = Layer("test layer", self.store)
251          self.classification = Classification(field = "CLPTLABEL")          self.classification = Classification()
252          self.classification.AppendGroup(ClassGroupSingleton("FARM"))          self.classification.AppendGroup(ClassGroupSingleton("FARM"))
253            self.layer.SetClassificationColumn("CLPTLABEL")
254          self.layer.SetClassification(self.classification)          self.layer.SetClassification(self.classification)
255          self.layer.UnsetModified()          self.layer.UnsetModified()
256          self.layer.Subscribe(LAYER_SHAPESTORE_REPLACED,          self.layer.Subscribe(LAYER_SHAPESTORE_REPLACED,
# Line 264  class SetShapeStoreTests(unittest.TestCa Line 272  class SetShapeStoreTests(unittest.TestCa
272          """          """
273          cls = self.layer.GetClassification()          cls = self.layer.GetClassification()
274          self.assert_(cls is self.classification)          self.assert_(cls is self.classification)
275          self.assertEquals(cls.GetField(), "CLPTLABEL")          field = self.layer.GetClassificationColumn()
276          self.assertEquals(cls.GetFieldType(), FIELDTYPE_STRING)          self.assertEquals(field, "CLPTLABEL")
277            self.assertEquals(self.layer.GetFieldType(field), FIELDTYPE_STRING)
278          self.assertEquals(self.layer.GetClassification().GetNumGroups(), 1)          self.assertEquals(self.layer.GetClassification().GetNumGroups(), 1)
279          self.failIf(self.layer.WasModified())          self.failIf(self.layer.WasModified())
280    
# Line 308  class SetShapeStoreTests(unittest.TestCa Line 317  class SetShapeStoreTests(unittest.TestCa
317                               (self.layer, LAYER_SHAPESTORE_REPLACED)])                               (self.layer, LAYER_SHAPESTORE_REPLACED)])
318    
319    
320  class TestLayerLegend(unittest.TestCase, support.SubscriberMixin):  class TestLayerModification(unittest.TestCase, support.SubscriberMixin):
321    
322      """Test cases for Layer method that modify the layer.      """Test cases for Layer method that modify the layer.
323      """      """
# Line 328  class TestLayerLegend(unittest.TestCase, Line 337  class TestLayerLegend(unittest.TestCase,
337          self.layer.Subscribe(LAYER_VISIBILITY_CHANGED,          self.layer.Subscribe(LAYER_VISIBILITY_CHANGED,
338                               self.subscribe_with_params,                               self.subscribe_with_params,
339                               LAYER_VISIBILITY_CHANGED)                               LAYER_VISIBILITY_CHANGED)
340            self.layer.Subscribe(LAYER_CHANGED, self.subscribe_with_params,
341                                 LAYER_CHANGED)
342    
343      def tearDown(self):      def tearDown(self):
344          """Clear the list of received messages and explictly destroy self.layer          """Clear the list of received messages and explictly destroy self.layer
# Line 338  class TestLayerLegend(unittest.TestCase, Line 349  class TestLayerLegend(unittest.TestCase,
349          self.session = None          self.session = None
350          self.clear_messages()          self.clear_messages()
351    
352      def test_initial_settings(self):      def test_sanity(self):
353          """Test Layer's initial legend attributes"""          """TestLayerModification Sanity Checks"""
354          # test default settings          # test default settings
355          self.failIf(self.layer.WasModified())          self.failIf(self.layer.WasModified())
         #self.assertEquals(self.layer.fill, None)  
         #self.assertEquals(self.layer.stroke.hex(), "#000000")  
         #self.assertEquals(self.layer.stroke_width, 1)  
356          self.assertEquals(self.layer.Visible(), 1)          self.assertEquals(self.layer.Visible(), 1)
357          # no messages should have been produced          # no messages should have been produced
358          self.check_messages([])          self.check_messages([])
# Line 359  class TestLayerLegend(unittest.TestCase, Line 367  class TestLayerLegend(unittest.TestCase,
367          # the layer.          # the layer.
368          self.failIf(self.layer.WasModified())          self.failIf(self.layer.WasModified())
369    
370            def test_set_classification(self):
371            """Test Layer.SetClassification"""
372            classification = Classification()
373            classification.AppendGroup(ClassGroupRange((0.0, 0.1)))
374    
375            self.layer.SetClassification(classification)
376            self.layer.SetClassificationColumn("AREA")
377    
378            self.check_messages([(self.layer, LAYER_CHANGED),
379                                 (self.layer, LAYER_CHANGED)])
380            self.failUnless(self.layer.WasModified())
381    
382            self.clear_messages()
383            self.layer.UnsetModified()
384    
385            # change only the classification column. This should issue a
386            # LAYER_CHANGED message as well.
387            self.layer.SetClassificationColumn("PERIMETER")
388    
389            self.check_messages([(self.layer, LAYER_CHANGED)])
390            self.failUnless(self.layer.WasModified())
391    
392    
393  #  #
394  # the tree info now contains Color objects which are difficult to test  # the tree info now contains Color objects which are difficult to test
395  #  #

Legend:
Removed from v.1278  
changed lines
  Added in v.1538

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26