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, FIELDTYPE_STRING, MemoryTable |
from Thuban.Model.table import FIELDTYPE_DOUBLE, FIELDTYPE_STRING, MemoryTable |
32 |
from Thuban.Model.proj import Projection |
from Thuban.Model.proj import Projection |
205 |
store = derived = None |
store = derived = None |
206 |
|
|
207 |
|
|
208 |
class SetShapeStoreTests(unittest.TestCase): |
class SetShapeStoreTests(unittest.TestCase, support.SubscriberMixin): |
209 |
|
|
210 |
def setUp(self): |
def setUp(self): |
211 |
"""Create a layer with a classification as self.layer""" |
"""Create a layer with a classification as self.layer""" |
212 |
|
self.clear_messages() |
213 |
self.session = Session("Test session for %s" % self.__class__) |
self.session = Session("Test session for %s" % self.__class__) |
214 |
self.shapefilename = os.path.join("..", "Data", "iceland", |
self.shapefilename = os.path.join("..", "Data", "iceland", |
215 |
"cultural_landmark-point.dbf") |
"cultural_landmark-point.dbf") |
218 |
self.classification = Classification(field = "CLPTLABEL") |
self.classification = Classification(field = "CLPTLABEL") |
219 |
self.classification.AppendGroup(ClassGroupSingleton("FARM")) |
self.classification.AppendGroup(ClassGroupSingleton("FARM")) |
220 |
self.layer.SetClassification(self.classification) |
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): |
def tearDown(self): |
229 |
|
self.clear_messages() |
230 |
self.layer.Destroy() |
self.layer.Destroy() |
231 |
self.session.Destroy() |
self.session.Destroy() |
232 |
self.session = self.layer = self.store = self.classification = None |
self.session = self.layer = self.store = self.classification = None |
233 |
|
|
234 |
def test_sanity(self): |
def test_sanity(self): |
235 |
"""SetShapeStoreTests sanity check""" |
"""SetShapeStoreTests sanity check |
236 |
|
|
237 |
|
Test the initial state of the test case instances after setUp. |
238 |
|
""" |
239 |
cls = self.layer.GetClassification() |
cls = self.layer.GetClassification() |
240 |
self.assert_(cls is self.classification) |
self.assert_(cls is self.classification) |
241 |
self.assertEquals(cls.GetField(), "CLPTLABEL") |
self.assertEquals(cls.GetField(), "CLPTLABEL") |
242 |
self.assertEquals(cls.GetFieldType(), FIELDTYPE_STRING) |
self.assertEquals(cls.GetFieldType(), FIELDTYPE_STRING) |
243 |
self.assertEquals(self.layer.GetClassification().GetNumGroups(), 1) |
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): |
def test_set_shape_store_different_field_name(self): |
255 |
"""Test Layer.SetShapeStore() with different column name""" |
"""Test Layer.SetShapeStore() with different column name""" |
258 |
self.layer.SetShapeStore(DerivedShapeStore(self.store, memtable)) |
self.layer.SetShapeStore(DerivedShapeStore(self.store, memtable)) |
259 |
# The classification should contain only the default group now. |
# The classification should contain only the default group now. |
260 |
self.assertEquals(self.layer.GetClassification().GetNumGroups(), 0) |
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): |
def test_set_shape_store_same_field(self): |
265 |
"""Test Layer.SetShapeStore() with same column name and type""" |
"""Test Layer.SetShapeStore() with same column name and type""" |
268 |
self.layer.SetShapeStore(DerivedShapeStore(self.store, memtable)) |
self.layer.SetShapeStore(DerivedShapeStore(self.store, memtable)) |
269 |
# The classification should be the same as before |
# The classification should be the same as before |
270 |
self.assert_(self.layer.GetClassification() is self.classification) |
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): |
def test_set_shape_store_same_field_different_type(self): |
274 |
"""Test Layer.SetShapeStore() with same column name but different type |
"""Test Layer.SetShapeStore() with same column name but different type |
278 |
self.layer.SetShapeStore(DerivedShapeStore(self.store, memtable)) |
self.layer.SetShapeStore(DerivedShapeStore(self.store, memtable)) |
279 |
# The classification should contain only the default group now. |
# The classification should contain only the default group now. |
280 |
self.assertEquals(self.layer.GetClassification().GetNumGroups(), 0) |
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): |