def testPropertyChange(self): layer = PropertyLayer() stack = PropertyStack() stack.addLayer(0, layer) mock = Mock() stack.wire(mock.method) layer["testkey"] = "testvalue" mock.method.assert_called_once_with("testkey", "testvalue")
def testDeletionEvent(self): ps = PropertyStack() pm = PropertyLayer(testkey="testvalue") ps.addLayer(0, pm) mock = Mock() ps.wire(mock.method) del ps["testkey"] mock.method.assert_called_once_with({"testkey": PropertyDeleted})
def testChangeEventWhenKeyDeleted(self): ps = PropertyStack() low_pm = PropertyLayer(testkey="lowvalue") high_pm = PropertyLayer(testkey="highvalue") ps.addLayer(0, high_pm) ps.addLayer(1, low_pm) mock = Mock() ps.wire(mock.method) del high_pm["testkey"] mock.method.assert_called_once_with({"testkey": "lowvalue"})
def testDeletionWithSecondLayer(self): ps = PropertyStack() low_pm = PropertyLayer(testkey="testvalue") high_pm = PropertyLayer() ps.addLayer(0, high_pm) ps.addLayer(1, low_pm) mock = Mock() ps.wire(mock.method) del low_pm["testkey"] mock.method.assert_called_once_with({"testkey": PropertyDeleted})
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 testPropertyChangeEventPriority(self): low_layer = PropertyLayer() high_layer = PropertyLayer() low_layer["testkey"] = "initial low value" high_layer["testkey"] = "initial high value" stack = PropertyStack() stack.addLayer(1, low_layer) stack.addLayer(0, high_layer) mock = Mock() stack.wire(mock.method) low_layer["testkey"] = "modified low value" mock.method.assert_not_called() high_layer["testkey"] = "modified high value" mock.method.assert_called_once_with("testkey", "modified high value")
def testReplaceLayerNoEventWhenValueUnchanged(self): fixed = PropertyLayer() fixed["testkey"] = "fixed value" first_layer = PropertyLayer() first_layer["testkey"] = "same value" second_layer = PropertyLayer() second_layer["testkey"] = "same value" stack = PropertyStack() stack.addLayer(1, fixed) stack.addLayer(0, first_layer) mock = Mock() stack.wire(mock.method) mock.method.assert_not_called() stack.replaceLayer(0, second_layer) mock.method.assert_not_called()