27 |
SHAPETYPE_POLYGON, SHAPETYPE_ARC, SHAPETYPE_POINT |
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 |
|
|
243 |
self.layer = Layer("test layer", self.store) |
self.layer = Layer("test layer", self.store) |
244 |
self.classification = Classification() |
self.classification = Classification() |
245 |
self.classification.AppendGroup(ClassGroupSingleton("FARM")) |
self.classification.AppendGroup(ClassGroupSingleton("FARM")) |
246 |
self.layer.SetClassificationField("CLPTLABEL") |
self.layer.SetClassificationColumn("CLPTLABEL") |
247 |
self.layer.SetClassification(self.classification) |
self.layer.SetClassification(self.classification) |
248 |
self.layer.UnsetModified() |
self.layer.UnsetModified() |
249 |
self.layer.Subscribe(LAYER_SHAPESTORE_REPLACED, |
self.layer.Subscribe(LAYER_SHAPESTORE_REPLACED, |
265 |
""" |
""" |
266 |
cls = self.layer.GetClassification() |
cls = self.layer.GetClassification() |
267 |
self.assert_(cls is self.classification) |
self.assert_(cls is self.classification) |
268 |
field = self.layer.GetClassificationField() |
field = self.layer.GetClassificationColumn() |
269 |
self.assertEquals(field, "CLPTLABEL") |
self.assertEquals(field, "CLPTLABEL") |
270 |
self.assertEquals(self.layer.GetFieldType(field), FIELDTYPE_STRING) |
self.assertEquals(self.layer.GetFieldType(field), FIELDTYPE_STRING) |
271 |
self.assertEquals(self.layer.GetClassification().GetNumGroups(), 1) |
self.assertEquals(self.layer.GetClassification().GetNumGroups(), 1) |
310 |
(self.layer, LAYER_SHAPESTORE_REPLACED)]) |
(self.layer, LAYER_SHAPESTORE_REPLACED)]) |
311 |
|
|
312 |
|
|
313 |
class TestLayerLegend(unittest.TestCase, support.SubscriberMixin): |
class TestLayerModification(unittest.TestCase, support.SubscriberMixin): |
314 |
|
|
315 |
"""Test cases for Layer method that modify the layer. |
"""Test cases for Layer method that modify the layer. |
316 |
""" |
""" |
330 |
self.layer.Subscribe(LAYER_VISIBILITY_CHANGED, |
self.layer.Subscribe(LAYER_VISIBILITY_CHANGED, |
331 |
self.subscribe_with_params, |
self.subscribe_with_params, |
332 |
LAYER_VISIBILITY_CHANGED) |
LAYER_VISIBILITY_CHANGED) |
333 |
|
self.layer.Subscribe(LAYER_CHANGED, self.subscribe_with_params, |
334 |
|
LAYER_CHANGED) |
335 |
|
|
336 |
def tearDown(self): |
def tearDown(self): |
337 |
"""Clear the list of received messages and explictly destroy self.layer |
"""Clear the list of received messages and explictly destroy self.layer |
342 |
self.session = None |
self.session = None |
343 |
self.clear_messages() |
self.clear_messages() |
344 |
|
|
345 |
def test_initial_settings(self): |
def test_sanity(self): |
346 |
"""Test Layer's initial legend attributes""" |
"""TestLayerModification Sanity Checks""" |
347 |
# test default settings |
# test default settings |
348 |
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) |
|
349 |
self.assertEquals(self.layer.Visible(), 1) |
self.assertEquals(self.layer.Visible(), 1) |
350 |
# no messages should have been produced |
# no messages should have been produced |
351 |
self.check_messages([]) |
self.check_messages([]) |
360 |
# the layer. |
# the layer. |
361 |
self.failIf(self.layer.WasModified()) |
self.failIf(self.layer.WasModified()) |
362 |
|
|
363 |
|
def test_set_classification(self): |
364 |
|
"""Test Layer.SetClassification""" |
365 |
|
classification = Classification() |
366 |
|
classification.AppendGroup(ClassGroupRange((0.0, 0.1))) |
367 |
|
|
368 |
|
self.layer.SetClassification(classification) |
369 |
|
self.layer.SetClassificationColumn("AREA") |
370 |
|
|
371 |
|
self.check_messages([(self.layer, LAYER_CHANGED), |
372 |
|
(self.layer, LAYER_CHANGED)]) |
373 |
|
self.failUnless(self.layer.WasModified()) |
374 |
|
|
375 |
|
self.clear_messages() |
376 |
|
self.layer.UnsetModified() |
377 |
|
|
378 |
|
# change only the classification column. This should issue a |
379 |
|
# LAYER_CHANGED message as well. |
380 |
|
self.layer.SetClassificationColumn("PERIMETER") |
381 |
|
|
382 |
|
self.check_messages([(self.layer, LAYER_CHANGED)]) |
383 |
|
self.failUnless(self.layer.WasModified()) |
384 |
|
|
385 |
|
|
386 |
# |
# |
387 |
# the tree info now contains Color objects which are difficult to test |
# the tree info now contains Color objects which are difficult to test |
388 |
# |
# |