def test_set_brightness(self, port, brightness): self.l.port = port async def child(): await self.l.set_brightness(brightness) kernel.run(child) self.l.send_message.ask_called_once() args, kwargs = self.l.send_message.call_args assert args[1] == self.write.get_bytes(port, 0, brightness)
def test_play_sound(self, port, sound): self.l.port = port async def child(): await self.l.play_sound(sound) kernel.run(child) self.l.send_message.ask_called_once() args, kwargs = self.l.send_message.call_args assert args[1] == self.write.get_bytes(port, 1, sound.value)
def test_set_speed(self, cls, port, speed): self._create_motor(cls) self.m.port = port async def child(): await self.m.set_speed(speed) kernel.run(child) self.m.send_message.ask_called_once() args, kwargs = self.m.send_message.call_args assert args[1] == self.write.get_bytes(port, 0, self.m._convert_speed_to_val(speed))
def test_ramp_speed(self, cls, port, speed): self._create_motor(cls) self.m.port = port async def child(): await self.m.ramp_speed(speed, 200) await self.m.ramp_in_progress_task.join() async def main(): t = await spawn(child()) await t.join() assert self.m.speed == speed kernel.run(main)
def test_ramp_cancel_speed(self, cls, port, speed): self._create_motor(cls) self.m.port = port async def child(): await self.m.ramp_speed(speed, 2000) await sleep(0.1) await self.m.set_speed(speed+10) async def main(): t = await spawn(child()) await t.join() assert self.m.speed == speed+10 kernel.run(main)
def test_rotate(self, cls, port, angle, speed): self._create_motor(cls) self.m.port = port max_power = 50 async def child(): await self.m.rotate(angle, speed, max_power) async def main(): t = await spawn(child()) await t.join() kernel.run(main) args, kwargs = self.m.send_message.call_args assert args[1] == self.write.get_bytes_for_rotate(port, angle, self.m._convert_speed_to_val(speed), max_power)
def test_run_hub(self, data): Hub.hubs = [] sensor_name = 'sensor' sensor = data.draw(st.sampled_from(self.sensor_list)) capabilities = self._draw_capabilities(data, sensor) hub_type = data.draw(st.sampled_from(self.hub_list)) TestHub, stop_evt = self._get_hub_class(hub_type, sensor, sensor_name, capabilities) hub = TestHub('test_hub') # Start the hub #kernel.run(self._emit_control(TestHub)) with patch('Adafruit_BluefruitLE.get_provider') as ble,\ patch('bricknil.ble_queue.USE_BLEAK', False) as use_bleak: ble.return_value = MockBLE(hub) sensor_obj = getattr(hub, sensor_name) sensor_obj.send_message = Mock(side_effect=coroutine( lambda x, y: "the awaitable should return this")) kernel.run(self._emit_control, data, hub, stop_evt, ble(), sensor_obj)
def start_thread(): kernel.run(start_curio)
def run(*args, **kwargs): ''' Replacement for the Curio run() function that uses ZMQSelector. ''' from curio import kernel return kernel.run(selector=ZMQSelector(), *args, **kwargs)
def test_activate_updates(self, port): self.l.port = port async def child(): await self.l.activate_updates() kernel.run(child)
def run(*args, **kwargs): ''' Replacement for the Curio run() function that uses ZMQSelector. ''' from curio import kernel return kernel.run(selector=ZMQSelector(), *args, **kwargs)