# Path: sakuraio/hardware/base.py
# def calc_parity(values):
#     parity = 0x00
#     for value in values:
#         parity ^= value
#     return parity
# 
# Path: sakuraio/hardware/dummy.py
# class DummySakuraIO(SakuraIOBase):
# 
#     def start(self, write=True):
#         pass
# 
#     def end(self):
#         pass
# 
#     def initial(self, response):
#         self.return_values = response
#         self.values = []
# 
#     def send_byte(self, value):
#         self.values.append(value)
# 
#     def recv_byte(self):
#         value = self.return_values[0]
#         self.return_values = self.return_values[1:]
#         return value
# 
# Path: sakuraio/hardware/exceptions.py
# class CommandError(SakuraIOBaseException):
# 
#     def __init__(self, status):
#         self.status = status
# 
#     def __str__(self):
#         return "Invalid response status '0x{0:02x}'".format(self.status)
# 
# class ParityError(SakuraIOBaseException):
# 
#     def __init__(self):
#         pass
# 
#     def __str__(self):
#         return "Invalid parity"


import unittest
from sakuraio.hardware.base import calc_parity
from sakuraio.hardware.dummy import DummySakuraIO
from sakuraio.hardware.exceptions import CommandError, ParityError

        expected = response[2:-1]

        self.assertEqual(self._execute_command(cmd, request, response), expected)

    def test_execute_command_status_error(self):
        base = DummySakuraIO()

        cmd = 0x10
        request = [0x01, 0x02, 0x03, 0x04]
        request.append(calc_parity(request))

        status = 0x02
        response = [status, 0x00]
        response.append(calc_parity(response))

        with self.assertRaises(CommandError):
            self._execute_command(cmd, request, response)

    def test_execute_command_parity_error(self):
        base = DummySakuraIO()

        cmd = 0x10
        request = [0x01, 0x02, 0x03, 0x04]
        request.append(calc_parity(request))

        status = 0x01
        response = [status, 0x00]
        response.append(0x12)


# Path: sakuraio/hardware/base.py
# def calc_parity(values):
#     parity = 0x00
#     for value in values:
#         parity ^= value
#     return parity
# 
# Path: sakuraio/hardware/dummy.py
# class DummySakuraIO(SakuraIOBase):
# 
#     def start(self, write=True):
#         pass
# 
#     def end(self):
#         pass
# 
#     def initial(self, response):
#         self.return_values = response
#         self.values = []
# 
#     def send_byte(self, value):
#         self.values.append(value)
# 
#     def recv_byte(self):
#         value = self.return_values[0]
#         self.return_values = self.return_values[1:]
#         return value
# 
# Path: sakuraio/hardware/exceptions.py
# class CommandError(SakuraIOBaseException):
# 
#     def __init__(self, status):
#         self.status = status
# 
#     def __str__(self):
#         return "Invalid response status '0x{0:02x}'".format(self.status)
# 
# class ParityError(SakuraIOBaseException):
# 
#     def __init__(self):
#         pass
# 
#     def __str__(self):
#         return "Invalid parity"


# Path: sakuraio/hardware/test/test_base.py
import unittest
from sakuraio.hardware.base import calc_parity
from sakuraio.hardware.dummy import DummySakuraIO
from sakuraio.hardware.exceptions import CommandError, ParityError


        expected = response[2:-1]

        self.assertEqual(self._execute_command(cmd, request, response), expected)

    def test_execute_command_status_error(self):
        base = DummySakuraIO()

        cmd = 0x10
        request = [0x01, 0x02, 0x03, 0x04]
        request.append(calc_parity(request))

        status = 0x02
        response = [status, 0x00]
        response.append(calc_parity(response))

        with self.assertRaises(CommandError):
            self._execute_command(cmd, request, response)

    def test_execute_command_parity_error(self):
        base = DummySakuraIO()

        cmd = 0x10
        request = [0x01, 0x02, 0x03, 0x04]
        request.append(calc_parity(request))

        status = 0x01
        response = [status, 0x00]
        response.append(0x12)


        with self.assertRaises(ParityError):