def test_mixed_listeners(self): def listener3(value): self.listenerVal3 = value def listener4(value): self.listenerVal4 = value sample = Sample() metaRpm = ChannelMeta(name='RPM') metaEngineTemp = ChannelMeta(name='EngineTemp') sample.channel_metas = [metaRpm, metaEngineTemp] sample.samples = [SampleValue(1111, metaRpm)] dataBus = DataBus() dataBus.addChannelListener('RPM', listener3) dataBus.addChannelListener('EngineTemp', listener4) dataBus.update_samples(sample) dataBus.notify_listeners(None) #ensure we don't set the wrong listener self.assertEqual(self.listenerVal3, 1111) self.assertEqual(self.listenerVal4, None) sample.samples = [SampleValue(1111, metaRpm), SampleValue(199, metaEngineTemp)] dataBus.update_samples(sample) dataBus.notify_listeners(None) #ensure we don't affect unrelated channels self.assertEqual(self.listenerVal3, 1111) self.assertEqual(self.listenerVal4, 199)
def test_no_listener(self): sample = Sample() meta = ChannelMeta(name='EngineTemp') sample.channel_metas = [meta] sample.samples = [SampleValue(200, meta)] dataBus = DataBus() dataBus.update_samples(sample) dataBus.notify_listeners(None)
def test_meta_listener(self): dataBus = DataBus() def metaListener(channel): self.channelMeta = channel metas = ChannelMetaCollection() metas.channel_metas = [ChannelMeta(name='RPM')] dataBus.addMetaListener(metaListener) dataBus.update_channel_meta(metas) dataBus.notify_listeners(None) self.assertEqual(self.channelMeta['RPM'], metas.channel_metas[0])
def test_update_value(self): dataBus = DataBus() sample = Sample() meta = ChannelMeta(name='RPM') sample.channel_metas = [meta] sample.samples = [SampleValue(1234, meta)] dataBus.update_samples(sample) dataBus.notify_listeners(None) value = dataBus.getData('RPM') self.assertEqual(value, 1234)
def test_listener(self): def listener(value): self.listenerVal0 = value sample = Sample() meta = ChannelMeta(name='RPM') sample.channel_metas = [meta] sample.samples = [SampleValue(1111, meta)] dataBus = DataBus() dataBus.addChannelListener('RPM', listener) dataBus.update_samples(sample) dataBus.notify_listeners(None) self.assertEqual(self.listenerVal0, 1111)