26 |
from Thuban.Model.layer import BaseLayer, Layer, RasterLayer, \ |
from Thuban.Model.layer import BaseLayer, Layer, RasterLayer, \ |
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_VISIBILITY_CHANGED, LAYER_SHAPESTORE_REPLACED, LAYER_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, support.SubscriberMixin): |
209 |
|
|
210 |
|
def setUp(self): |
211 |
|
"""Create a layer with a classification as self.layer""" |
212 |
|
self.clear_messages() |
213 |
|
self.session = Session("Test session for %s" % self.__class__) |
214 |
|
self.shapefilename = os.path.join("..", "Data", "iceland", |
215 |
|
"cultural_landmark-point.dbf") |
216 |
|
self.store = self.session.OpenShapefile(self.shapefilename) |
217 |
|
self.layer = Layer("test layer", self.store) |
218 |
|
self.classification = Classification(field = "CLPTLABEL") |
219 |
|
self.classification.AppendGroup(ClassGroupSingleton("FARM")) |
220 |
|
self.layer.SetClassification(self.classification) |
221 |
|
self.layer.UnsetModified() |
222 |
|
self.layer.Subscribe(LAYER_SHAPESTORE_REPLACED, |
223 |
|
self.subscribe_with_params, |
224 |
|
LAYER_SHAPESTORE_REPLACED) |
225 |
|
self.layer.Subscribe(LAYER_CHANGED, |
226 |
|
self.subscribe_with_params, LAYER_CHANGED) |
227 |
|
|
228 |
|
def tearDown(self): |
229 |
|
self.clear_messages() |
230 |
|
self.layer.Destroy() |
231 |
|
self.session.Destroy() |
232 |
|
self.session = self.layer = self.store = self.classification = None |
233 |
|
|
234 |
|
def test_sanity(self): |
235 |
|
"""SetShapeStoreTests sanity check |
236 |
|
|
237 |
|
Test the initial state of the test case instances after setUp. |
238 |
|
""" |
239 |
|
cls = self.layer.GetClassification() |
240 |
|
self.assert_(cls is self.classification) |
241 |
|
self.assertEquals(cls.GetField(), "CLPTLABEL") |
242 |
|
self.assertEquals(cls.GetFieldType(), FIELDTYPE_STRING) |
243 |
|
self.assertEquals(self.layer.GetClassification().GetNumGroups(), 1) |
244 |
|
self.failIf(self.layer.WasModified()) |
245 |
|
|
246 |
|
def test_set_shape_store_modified_flag(self): |
247 |
|
"""Test whether Layer.SetShapeStore() sets the modified flag""" |
248 |
|
memtable = MemoryTable([("FOO", FIELDTYPE_STRING)], |
249 |
|
[("bla",)] * self.layer.ShapeStore().Table().NumRows()) |
250 |
|
self.layer.SetShapeStore(DerivedShapeStore(self.store, memtable)) |
251 |
|
|
252 |
|
self.assert_(self.layer.WasModified()) |
253 |
|
|
254 |
|
def test_set_shape_store_different_field_name(self): |
255 |
|
"""Test Layer.SetShapeStore() with different column name""" |
256 |
|
memtable = MemoryTable([("FOO", FIELDTYPE_STRING)], |
257 |
|
[("bla",)] * self.layer.ShapeStore().Table().NumRows()) |
258 |
|
self.layer.SetShapeStore(DerivedShapeStore(self.store, memtable)) |
259 |
|
# The classification should contain only the default group now. |
260 |
|
self.assertEquals(self.layer.GetClassification().GetNumGroups(), 0) |
261 |
|
self.check_messages([(self.layer, LAYER_CHANGED), |
262 |
|
(self.layer, LAYER_SHAPESTORE_REPLACED)]) |
263 |
|
|
264 |
|
def test_set_shape_store_same_field(self): |
265 |
|
"""Test Layer.SetShapeStore() with same column name and type""" |
266 |
|
memtable = MemoryTable([("CLPTLABEL", FIELDTYPE_STRING)], |
267 |
|
[("bla",)] * self.layer.ShapeStore().Table().NumRows()) |
268 |
|
self.layer.SetShapeStore(DerivedShapeStore(self.store, memtable)) |
269 |
|
# The classification should be the same as before |
270 |
|
self.assert_(self.layer.GetClassification() is self.classification) |
271 |
|
self.check_messages([(self.layer, LAYER_SHAPESTORE_REPLACED)]) |
272 |
|
|
273 |
|
def test_set_shape_store_same_field_different_type(self): |
274 |
|
"""Test Layer.SetShapeStore() with same column name but different type |
275 |
|
""" |
276 |
|
memtable = MemoryTable([("CLPTLABEL", FIELDTYPE_DOUBLE)], |
277 |
|
[(0.0,)] * self.layer.ShapeStore().Table().NumRows()) |
278 |
|
self.layer.SetShapeStore(DerivedShapeStore(self.store, memtable)) |
279 |
|
# The classification should contain only the default group now. |
280 |
|
self.assertEquals(self.layer.GetClassification().GetNumGroups(), 0) |
281 |
|
self.check_messages([(self.layer, LAYER_CHANGED), |
282 |
|
(self.layer, LAYER_SHAPESTORE_REPLACED)]) |
283 |
|
|
284 |
|
|
285 |
class TestLayerLegend(unittest.TestCase, support.SubscriberMixin): |
class TestLayerLegend(unittest.TestCase, support.SubscriberMixin): |
286 |
|
|
287 |
"""Test cases for Layer method that modify the layer. |
"""Test cases for Layer method that modify the layer. |