def testForwardsPropertyEvent(self): pm = PropertyLayer() pf = PropertyFilter(pm, "testkey") mock = Mock() pf.wireProperty("testkey", mock.method) pm["testkey"] = "testvalue" mock.method.assert_called_once_with("testvalue")
def testPropagatesDeletion(self): pm = PropertyLayer(testkey="somevalue") filter_mock = Mock() filter_mock.apply.return_value = True pf = PropertyFilter(pm, filter_mock) mock = Mock() pf.wire(mock.method) del pf["testkey"] mock.method.assert_called_once_with({"testkey": PropertyDeleted})
def testForwardsEvent(self): pm = PropertyLayer() mock = Mock() mock.apply.return_value = True pf = PropertyFilter(pm, mock) mock = Mock() pf.wire(mock.method) pm["testkey"] = "testvalue" mock.method.assert_called_once_with({"testkey": "testvalue"})
def testPassesProperty(self): pm = PropertyLayer() pm["testkey"] = "testvalue" mock = Mock() mock.apply.return_value = True pf = PropertyFilter(pm, mock) self.assertEqual(pf["testkey"], "testvalue")
def testRejectsWrite(self): pm = PropertyLayer() pm["testkey"] = "old value" pf = PropertyFilter(pm, "otherkey") with self.assertRaises(KeyError): pf["testkey"] = "new value" self.assertEqual(pm["testkey"], "old value")
def testOverwrite(self): pm = PropertyLayer() pm["testkey"] = "old value" pf = PropertyFilter(pm, "testkey") pf["testkey"] = "new value" self.assertEqual(pm["testkey"], "new value") self.assertEqual(pf["testkey"], "new value")
def testMissesProperty(self): pm = PropertyLayer() pm["testkey"] = "testvalue" pf = PropertyFilter(pm, "other_key") self.assertFalse("testkey" in pf) with self.assertRaises(KeyError): x = pf["testkey"]
def testForwardsWrite(self): pm = PropertyLayer() mock = Mock() mock.apply.return_value = True pf = PropertyFilter(pm, mock) pf["testkey"] = "testvalue" self.assertTrue("testkey" in pm) self.assertEqual(pm["testkey"], "testvalue")
def testRejectsWrite(self): pm = PropertyLayer() pm["testkey"] = "old value" mock = Mock() mock.apply.return_value = False pf = PropertyFilter(pm, mock) with self.assertRaises(KeyError): pf["testkey"] = "new value" self.assertEqual(pm["testkey"], "old value")
def testOverwrite(self): pm = PropertyLayer() pm["testkey"] = "old value" mock = Mock() mock.apply.return_value = True pf = PropertyFilter(pm, mock) pf["testkey"] = "new value" self.assertEqual(pm["testkey"], "new value") self.assertEqual(pf["testkey"], "new value")
def testMissesProperty(self): pm = PropertyLayer() pm["testkey"] = "testvalue" mock = Mock() mock.apply.return_value = False pf = PropertyFilter(pm, mock) self.assertFalse("testkey" in pf) with self.assertRaises(KeyError): x = pf["testkey"]
def __init__(self, id, props): self.id = id self.commandMapper = None self.props = PropertyStack() # layer 0 reserved for profile properties self.profileCarousel = SdrProfileCarousel(props) # prevent profile names from overriding the device name self.props.addLayer( 0, PropertyFilter(self.profileCarousel, ByLambda(lambda x: x != "name"))) # props from our device config self.props.addLayer(1, props) # the sdr_id is constant, so we put it in a separate layer # this is used to detect device changes, that are then sent to the client self.props.addLayer(2, PropertyLayer(sdr_id=id).readonly()) # finally, accept global config properties from the top-level config self.props.addLayer(3, Config.get()) self.sdrProps = self.props.filter(*self.getEventNames()) self.wireEvents() self.port = getAvailablePort() self.monitor = None self.clients = [] self.spectrumClients = [] self.spectrumThread = None self.spectrumLock = threading.Lock() self.process = None self.modificationLock = threading.Lock() self.state = SdrSourceState.STOPPED self.enabled = "enabled" not in props or props["enabled"] props.filter("enabled").wire(self._handleEnableChanged) self.failed = False self.busyState = SdrBusyState.IDLE self.validateProfiles() if self.isAlwaysOn() and self.isEnabled(): self.start()
def testPassesProperty(self): pm = PropertyLayer() pm["testkey"] = "testvalue" pf = PropertyFilter(pm, "testkey") self.assertEqual(pf["testkey"], "testvalue")
def testForwardsWrite(self): pm = PropertyLayer() pf = PropertyFilter(pm, "testkey") pf["testkey"] = "testvalue" self.assertTrue("testkey" in pm) self.assertEqual(pm["testkey"], "testvalue")