Esempio n. 1
0
    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)
Esempio n. 2
0
    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)
Esempio n. 3
0
    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))
Esempio n. 4
0
    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)
Esempio n. 5
0
    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)
Esempio n. 6
0
    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)
Esempio n. 7
0
    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)
Esempio n. 8
0
 def start_thread():
     kernel.run(start_curio)
Esempio n. 9
0
def run(*args, **kwargs):
    '''
    Replacement for the Curio run() function that uses ZMQSelector.
    '''
    from curio import kernel
    return kernel.run(selector=ZMQSelector(), *args, **kwargs)
Esempio n. 10
0
 def test_activate_updates(self, port):
     self.l.port = port
     async def child():
         await self.l.activate_updates()
     kernel.run(child)
Esempio n. 11
0
def run(*args, **kwargs):
    '''
    Replacement for the Curio run() function that uses ZMQSelector.
    '''
    from curio import kernel
    return kernel.run(selector=ZMQSelector(), *args, **kwargs)