def testLayerRemoval(self): om = PropertyStack() low_pm = PropertyLayer() high_pm = PropertyLayer() low_pm["testkey"] = "low value" high_pm["testkey"] = "high value" om.addLayer(1, low_pm) om.addLayer(0, high_pm) self.assertEqual(om["testkey"], "high value") om.removeLayer(high_pm) self.assertEqual(om["testkey"], "low value")
def testUnwiresEventsOnRemoval(self): layer = PropertyLayer() layer["testkey"] = "before" stack = PropertyStack() stack.addLayer(0, layer) mock = Mock() stack.wire(mock.method) stack.removeLayer(layer) mock.method.assert_called_once_with("testkey", None) mock.reset_mock() layer["testkey"] = "after" mock.method.assert_not_called()
def testEventOnLayerRemoval(self): low_layer = PropertyLayer() high_layer = PropertyLayer() stack = PropertyStack() stack.addLayer(1, low_layer) stack.addLayer(0, high_layer) low_layer["testkey"] = "low value" high_layer["testkey"] = "high value" mock = Mock() stack.wireProperty("testkey", mock.method) mock.method.assert_called_once_with("high value") mock.reset_mock() stack.removeLayer(high_layer) mock.method.assert_called_once_with("low value")
def testNoneOnKeyRemoval(self): low_layer = PropertyLayer() high_layer = PropertyLayer() stack = PropertyStack() stack.addLayer(1, low_layer) stack.addLayer(0, high_layer) low_layer["testkey"] = "low value" high_layer["testkey"] = "high value" high_layer["unique key"] = "unique value" mock = Mock() stack.wireProperty("unique key", mock.method) mock.method.assert_called_once_with("unique value") mock.reset_mock() stack.removeLayer(high_layer) mock.method.assert_called_once_with(PropertyDeleted)