コード例 #1
0
 def test_firmware_version_returns_a_string(self):
     mock_transport = MockTransport([
         Response(ResponseHeader.Status_Ok, list(b'0.1-r5')),
         Response(ResponseHeader.Status_Ok, list(b'v0.1-r5'))
     ])
     fw = ReadFirmwareVersionCommand(mock_transport)
     self.assertEqual(Version("0.1-r5"), fw())
     self.assertEqual(None, fw())
コード例 #2
0
 def test_hardware_version_returns_a_string(self):
     mock_transport = MockTransport([
         Response(ResponseHeader.Status_Ok, list(b'0.1')),
         Response(ResponseHeader.Status_Ok, list(b'v0.1'))
     ])
     hw = ReadHardwareVersionCommand(mock_transport)
     self.assertEqual(Version("0.1"), hw())
     self.assertEqual(None, hw())
コード例 #3
0
    def test_read_sensor_port_types_returns_a_dict(self):
        mock_transport = MockTransport([
            Response(ResponseStatus.Ok, b''),  # no strings
            Response(ResponseStatus.Ok, b'\x01\x06foobar'),  # one string
            Response(ResponseStatus.Ok, b'\x01\x06foobar\x03\x04hola'),  # multiple strings
        ])
        read_types = ReadSensorPortTypesCommand(mock_transport)

        self.assertFalse(read_types())
        self.assertDictEqual({'foobar': 1}, read_types())
        self.assertDictEqual({'foobar': 1, 'hola': 3}, read_types())
コード例 #4
0
    def test_set_bluetooth_status_payload_is_one_byte(self):
        mock_transport = MockTransport([
            Response(ResponseHeader.Status_Ok, []),
            Response(ResponseHeader.Status_Ok, [1]),
        ])
        set_status = SetBluetoothStatusCommand(mock_transport)

        self.assertIsNone(set_status(3))
        self.assertEqual([3], mock_transport.commands[0][1])

        # unexpected payload byte
        self.assertRaises(NotImplementedError, lambda: set_status(3))
コード例 #5
0
    def test_set_master_status_payload_is_one_byte(self):
        mock_transport = MockTransport([
            Response(ResponseStatus.Ok, []),
            Response(ResponseStatus.Ok, [1]),
        ])
        set_status = SetMasterStatusCommand(mock_transport)

        self.assertIsNone(set_status(3))
        self.assertListEqual([3], list(mock_transport.commands[0][1]))

        # unexpected payload byte
        self.assertRaises(NotImplementedError, lambda: set_status(3))
コード例 #6
0
 def test_default_command_raises_when_response_has_payload(self):
     mock_transport = MockTransport(
         [Response(ResponseHeader.Status_Ok, [1])])
     c = MockCommand(mock_transport)
     self.assertRaises(NotImplementedError, c)
     # assert that command was sent
     self.assertEqual(1, mock_transport.command_count)
コード例 #7
0
 def test_call_sends_command(self):
     mock_transport = MockTransport([Response(ResponseStatus.Ok, [])])
     c = MockCommand(mock_transport)
     self.assertEqual(0, mock_transport.command_count)
     c()
     self.assertEqual(1, mock_transport.command_count)
     self.assertEqual((2, b''), mock_transport.commands[0])
コード例 #8
0
    def test_command_raises_when_response_is_not_ok(self):
        mock_transport = MockTransport([
            Response(ResponseHeader.Status_Error_UnknownCommand, []),
            Response(ResponseHeader.Status_Error_UnknownOperation, []),
            Response(ResponseHeader.Status_Error_CommandError, []),
            Response(ResponseHeader.Status_Error_CommandIntegrityError, []),
            Response(ResponseHeader.Status_Error_InternalError, []),
            Response(ResponseHeader.Status_Error_InvalidOperation, []),
            Response(ResponseHeader.Status_Error_PayloadIntegrityError, []),
            Response(ResponseHeader.Status_Error_PayloadLengthError, []),
        ])

        c = MockCommand(mock_transport)

        self.assertRaises(UnknownCommandError, c)
        self.assertRaises(ValueError, c)
        self.assertRaises(ValueError, c)
        self.assertRaises(ValueError, c)
        self.assertRaises(ValueError, c)
        self.assertRaises(ValueError, c)
        self.assertRaises(ValueError, c)
        self.assertRaises(ValueError, c)
コード例 #9
0
 def test_ping_has_no_payload_and_return_value(self):
     mock_transport = MockTransport(
         [Response(ResponseHeader.Status_Ok, [])])
     ping = PingCommand(mock_transport)
     self.assertIsNone(ping())
     self.assertListEqual([], mock_transport.commands[0][1])