handle deletions correctly
This commit is contained in:
parent
e0985c3802
commit
161408dbf4
@ -322,11 +322,13 @@ class PropertyStack(PropertyManager):
|
|||||||
|
|
||||||
def receiveEvent(self, layer, changes):
|
def receiveEvent(self, layer, changes):
|
||||||
changesToForward = {name: value for name, value in changes.items() if layer == self._getTopLayer(name)}
|
changesToForward = {name: value for name, value in changes.items() if layer == self._getTopLayer(name)}
|
||||||
# deletions need to be handled separately: only send them if deleted in all layers
|
# deletions need to be handled separately:
|
||||||
|
# * send a deletion if the key was deleted in all layers
|
||||||
|
# * send lower value if the key is still present in a lower layer
|
||||||
deletionsToForward = {
|
deletionsToForward = {
|
||||||
name: value
|
name: PropertyDeleted if self._getTopLayer(name, False) is None else self[name]
|
||||||
for name, value in changes.items()
|
for name, value in changes.items()
|
||||||
if value is PropertyDeleted and self._getTopLayer(name, False) is None
|
if value is PropertyDeleted
|
||||||
}
|
}
|
||||||
self._fireCallbacks({**changesToForward, **deletionsToForward})
|
self._fireCallbacks({**changesToForward, **deletionsToForward})
|
||||||
|
|
||||||
|
@ -215,3 +215,14 @@ class PropertyStackTest(TestCase):
|
|||||||
ps.wire(mock.method)
|
ps.wire(mock.method)
|
||||||
del low_pm["testkey"]
|
del low_pm["testkey"]
|
||||||
mock.method.assert_called_once_with({"testkey": PropertyDeleted})
|
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"})
|
||||||
|
Loading…
Reference in New Issue
Block a user