Ejemplo n.º 1
0
    def test_board_led(self, mocker):
        # allow the instantiation of EsploraSerial to proceed without a real serial connection
        mocker.patch('serial.Serial')

        # instantiate necessary objects
        # instantiate necessary objects
        my_serial = EsploraSerial("/dev/ttyACM0")
        my_server = Esp4sHttpServer(my_serial)

        # test for LED Off
        class Request:
            def __init__(self):
                self._match_info = None

            @property
            def match_info(self):
                return {'off_on': 'Off'}

        r = Request()
        yield from my_server.board_led(r)
        assert my_server.command == 'L0\r\n'

        # test for LED On
        class Request:
            def __init__(self):
                self._match_info = None

            @property
            def match_info(self):
                return {'off_on': 'On'}

        r = Request()
        yield from my_server.board_led(r)
        assert my_server.command == 'L1\r\n'
Ejemplo n.º 2
0
    def test_sound(self, monkeypatch, mocker):
        # allow the instantiation of EsploraSerial to proceed without a real serial connection
        mocker.patch('serial.Serial')

        # instantiate necessary objects
        my_serial = EsploraSerial("/dev/ttyACM0")
        my_server = Esp4sHttpServer(my_serial)

        @asyncio.coroutine
        def mockreturn(readline):
            return b'55'

        monkeypatch.setattr(EsploraSerial, 'readline', mockreturn)

        class Request:
            def __init__(self):
                self._match_info = None

            @property
            def match_info(self):
                return {'sound': 'sound'}

        r = Request()

        status_text = yield from my_server.sound(r, True)
        assert status_text == '55'
Ejemplo n.º 3
0
    def test_temp_units(self, mocker):
        mocker.patch('serial.Serial')

        # instantiate necessary objects
        my_serial = EsploraSerial("/dev/ttyACM0")
        my_server = Esp4sHttpServer(my_serial)

        class Request:
            def __init__(self):
                self._match_info = None

            @property
            def match_info(self):
                return {'temp_units': 'Celcius'}

        r = Request()

        status_text = yield from my_server.temp_units(r)
        assert my_server.command == 'U0\r\n'

        class Request:
            def __init__(self):
                self._match_info = None

            @property
            def match_info(self):
                return {'temp_units': 'Fahrenheit'}

        r = Request()

        yield from my_server.temp_units(r)
        assert my_server.command == 'U1\r\n'
Ejemplo n.º 4
0
    def test_board_orientation(self, mocker):
        mocker.patch('serial.Serial')

        # instantiate necessary objects
        my_serial = EsploraSerial("/dev/ttyACM0")
        my_server = Esp4sHttpServer(my_serial)

        class Request:
            def __init__(self):
                self._match_info = None

            @property
            def match_info(self):
                return {'orientation': 'Joystick_On_Left'}

        r = Request()

        yield from my_server.board_orientation(r)
        assert my_server.command == 'O1\r\n'

        class Request:
            def __init__(self):
                self._match_info = None

            @property
            def match_info(self):
                return {'orientation': 'Joystick_On_Right'}

        r = Request()

        yield from my_server.board_orientation(r)
        assert my_server.command == 'O2\r\n'
Ejemplo n.º 5
0
    def test_tinker_out(self, mocker):
        # allow the instantiation of EsploraSerial to proceed without a real serial connection
        mocker.patch('serial.Serial')

        # instantiate necessary objects
        my_serial = EsploraSerial("/dev/ttyACM0")
        my_server = Esp4sHttpServer(my_serial)

        class Request:
            def __init__(self):
                self._match_info = None

            @property
            def match_info(self):
                return {'tk_chan': 'A', 'value': '123'}

        r = Request()
        yield from my_server.tinker_out(r)
        assert my_server.command == 'J123\r\n'

        class Request:
            def __init__(self):
                self._match_info = None

            @property
            def match_info(self):
                return {'tk_chan': 'B', 'value': '456'}

        r = Request()
        yield from my_server.tinker_out(r)
        assert my_server.command == 'K456\r\n'
Ejemplo n.º 6
0
    def test_tone2(self, mocker):
        # allow the instantiation of EsploraSerial to proceed without a real serial connection
        mocker.patch('serial.Serial')

        # instantiate necessary objects
        my_serial = EsploraSerial("/dev/ttyACM0")
        my_server = Esp4sHttpServer(my_serial)

        class Request:
            def __init__(self):
                self._match_info = None

            @property
            def match_info(self):
                return {'frequency': '1000'}

        r = Request()
        yield from my_server.tone2(r)
        assert my_server.command == 'T1000\r\n'
Ejemplo n.º 7
0
    def test_play_tone(self, mocker):
        # allow the instantiation of EsploraSerial to proceed without a real serial connection
        mocker.patch('serial.Serial')

        # instantiate necessary objects
        my_serial = EsploraSerial("/dev/ttyACM0")
        my_server = Esp4sHttpServer(my_serial)

        # test for LED Off
        class Request:
            def __init__(self):
                self._match_info = None

            @property
            def match_info(self):
                return {'notes': 'G_Sharp--A_Flat'}

        r = Request()
        yield from my_server.play_tone(r)
        assert my_server.command == 'T831\r\n'
Ejemplo n.º 8
0
    def test_leds(self, mocker):
        # allow the instantiation of EsploraSerial to proceed without a real serial connection
        mocker.patch('serial.Serial')

        # instantiate necessary objects
        my_serial = EsploraSerial("/dev/ttyACM0")
        my_server = Esp4sHttpServer(my_serial)

        # test for LED Off
        class Request:
            def __init__(self):
                self._match_info = None

            @property
            def match_info(self):
                return {'leds': 'red', 'intensity': '100'}

        r = Request()
        yield from my_server.leds(r)
        assert my_server.command == 'red100\r\n'
Ejemplo n.º 9
0
    def test_accelerometer(self, monkeypatch, mocker):
        # allow the instantiation of EsploraSerial to proceed without a real serial connection
        mocker.patch('serial.Serial')

        # instantiate necessary objects
        my_serial = EsploraSerial("/dev/ttyACM0")
        my_server = Esp4sHttpServer(my_serial)

        @asyncio.coroutine
        def mockreturn(readline):
            return b'2'

        monkeypatch.setattr(EsploraSerial, 'readline', mockreturn)

        class Request:
            def __init__(self):
                self._match_info = None

            @property
            def match_info(self):
                return {'axis': 'X__Side-Twist'}

        r = Request()

        status_text = yield from my_server.accelerometer(r, True)
        assert status_text == '2'

        @asyncio.coroutine
        def mockreturn(readline):
            return b'4'

        monkeypatch.setattr(EsploraSerial, 'readline', mockreturn)

        class Request:
            def __init__(self):
                self._match_info = None

            @property
            def match_info(self):
                return {'axis': 'Y__Front-Twist'}

        r = Request()

        status_text = yield from my_server.accelerometer(r, True)
        assert status_text == '4'

        @asyncio.coroutine
        def mockreturn(readline):
            return b'6'

        monkeypatch.setattr(EsploraSerial, 'readline', mockreturn)

        class Request:
            def __init__(self):
                self._match_info = None

            @property
            def match_info(self):
                return {'axis': 'Z__Raise-Lower'}

        r = Request()

        status_text = yield from my_server.accelerometer(r, True)
        assert status_text == '6'
Ejemplo n.º 10
0
    def test_joystick(self, monkeypatch, mocker):
        # allow the instantiation of EsploraSerial to proceed without a real serial connection
        mocker.patch('serial.Serial')

        # instantiate necessary objects
        my_serial = EsploraSerial("/dev/ttyACM0")
        my_server = Esp4sHttpServer(my_serial)

        @asyncio.coroutine
        def mockreturn(readline):
            return b'2'

        monkeypatch.setattr(EsploraSerial, 'readline', mockreturn)

        class Request:
            def __init__(self):
                self._match_info = None

            @property
            def match_info(self):
                return {'control': 'Button'}

        r = Request()

        status_text = yield from my_server.joystick(r, True)
        assert status_text == '2'

        @asyncio.coroutine
        def mockreturn(readline):
            return b'4'

        monkeypatch.setattr(EsploraSerial, 'readline', mockreturn)

        class Request:
            def __init__(self):
                self._match_info = None

            @property
            def match_info(self):
                return {'control': 'Left-Right_(X)'}

        r = Request()

        status_text = yield from my_server.joystick(r, True)
        assert status_text == '4'

        @asyncio.coroutine
        def mockreturn(readline):
            return b'6'

        monkeypatch.setattr(EsploraSerial, 'readline', mockreturn)

        class Request:
            def __init__(self):
                self._match_info = None

            @property
            def match_info(self):
                return {'control': 'Up-Down_(Y)'}

        r = Request()

        status_text = yield from my_server.joystick(r, True)
        assert status_text == '6'