28 |
from Thuban.Model.messages import LAYER_LEGEND_CHANGED, \ |
from Thuban.Model.messages import LAYER_LEGEND_CHANGED, \ |
29 |
LAYER_VISIBILITY_CHANGED |
LAYER_VISIBILITY_CHANGED |
30 |
from Thuban.Model.color import Color |
from Thuban.Model.color import Color |
31 |
from Thuban.Model.table import FIELDTYPE_DOUBLE |
from Thuban.Model.table import FIELDTYPE_DOUBLE, FIELDTYPE_STRING, MemoryTable |
32 |
from Thuban.Model.proj import Projection |
from Thuban.Model.proj import Projection |
33 |
from Thuban.Model.data import DerivedShapeStore |
from Thuban.Model.data import DerivedShapeStore |
34 |
|
from Thuban.Model.classification import Classification, ClassGroupSingleton |
35 |
|
|
36 |
class TestLayer(unittest.TestCase, support.FileTestMixin, |
class TestLayer(unittest.TestCase, support.FileTestMixin, |
37 |
support.FloatComparisonMixin): |
support.FloatComparisonMixin): |
205 |
store = derived = None |
store = derived = None |
206 |
|
|
207 |
|
|
208 |
|
class SetShapeStoreTests(unittest.TestCase): |
209 |
|
|
210 |
|
def setUp(self): |
211 |
|
"""Create a layer with a classification as self.layer""" |
212 |
|
self.session = Session("Test session for %s" % self.__class__) |
213 |
|
self.shapefilename = os.path.join("..", "Data", "iceland", |
214 |
|
"cultural_landmark-point.dbf") |
215 |
|
self.store = self.session.OpenShapefile(self.shapefilename) |
216 |
|
self.layer = Layer("test layer", self.store) |
217 |
|
self.classification = Classification(field = "CLPTLABEL") |
218 |
|
self.classification.AppendGroup(ClassGroupSingleton("FARM")) |
219 |
|
self.layer.SetClassification(self.classification) |
220 |
|
|
221 |
|
def tearDown(self): |
222 |
|
self.layer.Destroy() |
223 |
|
self.session.Destroy() |
224 |
|
self.session = self.layer = self.store = self.classification = None |
225 |
|
|
226 |
|
def test_sanity(self): |
227 |
|
"""SetShapeStoreTests sanity check""" |
228 |
|
cls = self.layer.GetClassification() |
229 |
|
self.assert_(cls is self.classification) |
230 |
|
self.assertEquals(cls.GetField(), "CLPTLABEL") |
231 |
|
self.assertEquals(cls.GetFieldType(), FIELDTYPE_STRING) |
232 |
|
self.assertEquals(self.layer.GetClassification().GetNumGroups(), 1) |
233 |
|
|
234 |
|
def test_set_shape_store_different_field_name(self): |
235 |
|
"""Test Layer.SetShapeStore() with different column name""" |
236 |
|
memtable = MemoryTable([("FOO", FIELDTYPE_STRING)], |
237 |
|
[("bla",)] * self.layer.ShapeStore().Table().NumRows()) |
238 |
|
self.layer.SetShapeStore(DerivedShapeStore(self.store, memtable)) |
239 |
|
# The classification should contain only the default group now. |
240 |
|
self.assertEquals(self.layer.GetClassification().GetNumGroups(), 0) |
241 |
|
|
242 |
|
def test_set_shape_store_same_field(self): |
243 |
|
"""Test Layer.SetShapeStore() with same column name and type""" |
244 |
|
memtable = MemoryTable([("CLPTLABEL", FIELDTYPE_STRING)], |
245 |
|
[("bla",)] * self.layer.ShapeStore().Table().NumRows()) |
246 |
|
self.layer.SetShapeStore(DerivedShapeStore(self.store, memtable)) |
247 |
|
# The classification should be the same as before |
248 |
|
self.assert_(self.layer.GetClassification() is self.classification) |
249 |
|
|
250 |
|
def test_set_shape_store_same_field_different_type(self): |
251 |
|
"""Test Layer.SetShapeStore() with same column name but different type |
252 |
|
""" |
253 |
|
memtable = MemoryTable([("CLPTLABEL", FIELDTYPE_DOUBLE)], |
254 |
|
[(0.0,)] * self.layer.ShapeStore().Table().NumRows()) |
255 |
|
self.layer.SetShapeStore(DerivedShapeStore(self.store, memtable)) |
256 |
|
# The classification should contain only the default group now. |
257 |
|
self.assertEquals(self.layer.GetClassification().GetNumGroups(), 0) |
258 |
|
|
259 |
|
|
260 |
class TestLayerLegend(unittest.TestCase, support.SubscriberMixin): |
class TestLayerLegend(unittest.TestCase, support.SubscriberMixin): |
261 |
|
|
262 |
"""Test cases for Layer method that modify the layer. |
"""Test cases for Layer method that modify the layer. |