simplify api by abstracting layer changes
This commit is contained in:
parent
6af0ad0262
commit
3d20e3ed80
@ -353,10 +353,12 @@ class PropertyCarousel(PropertyDelegator):
|
||||
return self.emptyLayer
|
||||
|
||||
def addLayer(self, key, value):
|
||||
if key in self.layers and self.layers[key] is self.pm:
|
||||
self.layers[key] = value
|
||||
# switch after introducing the new value
|
||||
self.switch(key)
|
||||
else:
|
||||
self.layers[key] = value
|
||||
|
||||
def hasLayer(self, key):
|
||||
return key in self.layers
|
||||
|
||||
def removeLayer(self, key):
|
||||
if key in self.layers and self.layers[key] is self.pm:
|
||||
|
@ -84,7 +84,7 @@ class SdrProfileCarousel(PropertyCarousel):
|
||||
for profile_id, profile in changes.items():
|
||||
if profile is PropertyDeleted:
|
||||
self.removeLayer(profile_id)
|
||||
elif not self.hasLayer(profile_id):
|
||||
else:
|
||||
self.addLayer(profile_id, profile)
|
||||
|
||||
def _getDefaultLayer(self):
|
||||
|
@ -77,12 +77,6 @@ class PropertyCarouselTest(TestCase):
|
||||
with self.assertRaises(KeyError):
|
||||
pc.switch("doesntmatter")
|
||||
|
||||
def testHasLayer(self):
|
||||
pc = PropertyCarousel()
|
||||
pc.addLayer("testkey", PropertyLayer())
|
||||
self.assertTrue(pc.hasLayer("testkey"))
|
||||
self.assertFalse(pc.hasLayer("otherkey"))
|
||||
|
||||
def testRemoveLayer(self):
|
||||
pc = PropertyCarousel()
|
||||
pl = PropertyLayer(testkey="testvalue")
|
||||
@ -117,3 +111,15 @@ class PropertyCarouselTest(TestCase):
|
||||
pc = PropertyCarousel()
|
||||
with self.assertRaises(PropertyWriteError):
|
||||
pc["testkey"] = "testvalue"
|
||||
|
||||
def testSendsChangesIfActiveLayerIsReplaced(self):
|
||||
pc = PropertyCarousel()
|
||||
pl = PropertyLayer(testkey="testvalue")
|
||||
pc.addLayer("x", pl)
|
||||
pc.switch("x")
|
||||
self.assertEqual(pc["testkey"], "testvalue")
|
||||
mock = Mock()
|
||||
pc.wire(mock.method)
|
||||
pl = PropertyLayer(testkey="othervalue")
|
||||
pc.addLayer("x", pl)
|
||||
mock.method.assert_called_once_with({"testkey": "othervalue"})
|
||||
|
Loading…
Reference in New Issue
Block a user