Ejemplo n.º 1
0
 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")
Ejemplo n.º 2
0
 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})
Ejemplo n.º 3
0
 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"})
Ejemplo n.º 4
0
 def testPassesProperty(self):
     pm = PropertyLayer()
     pm["testkey"] = "testvalue"
     mock = Mock()
     mock.apply.return_value = True
     pf = PropertyFilter(pm, mock)
     self.assertEqual(pf["testkey"], "testvalue")
Ejemplo n.º 5
0
 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")
Ejemplo n.º 6
0
 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")
Ejemplo n.º 7
0
 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"]
Ejemplo n.º 8
0
 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")
Ejemplo n.º 9
0
 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")
Ejemplo n.º 10
0
 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")
Ejemplo n.º 11
0
 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"]
Ejemplo n.º 12
0
    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()
Ejemplo n.º 13
0
 def testPassesProperty(self):
     pm = PropertyLayer()
     pm["testkey"] = "testvalue"
     pf = PropertyFilter(pm, "testkey")
     self.assertEqual(pf["testkey"], "testvalue")
Ejemplo n.º 14
0
 def testForwardsWrite(self):
     pm = PropertyLayer()
     pf = PropertyFilter(pm, "testkey")
     pf["testkey"] = "testvalue"
     self.assertTrue("testkey" in pm)
     self.assertEqual(pm["testkey"], "testvalue")