# Path: sakuraio/hardware/base.py
# def calc_parity(values):
#     parity = 0x00
#     for value in values:
#         parity ^= value
#     return parity
# 
# Path: sakuraio/hardware/commands/utils.py
# def value_to_bytes(value):
#     """Convert value to raw values.
# 
#     :param value:
#         Value to Convert
#     :type value: integer, float, str or bytes
# 
#     :return: Tuple of `Type` string and `Value` list
#     :rtype: (str, list)
#     """
# 
#     if isinstance(value, float):
#         return ("d", pack("<d", value))
# 
#     if isinstance(value, int):
#         if value > 9223372036854775807:
#             return ("L", pack("<Q", value))
#         return ("l", pack("<q", value))
# 
#     if platform.python_version_tuple()[0] == "2" and isinstance(value, long):
#         return ("L", pack("<Q", value))
# 
#     if isinstance(value, str):
#         if platform.python_version_tuple()[0] == "2":
#             result = []
#             for c in value.encode("utf-8"):
#                 result.append(ord(c))
#             return ("b", (result+[0x00]*8)[:8])
#         else:
#             return ("b", (list(value.encode("utf-8"))+[0x00]*8)[:8])
# 
#     if isinstance(value, bytes):
#         return ("b", (list(value)+[0x00]*8)[:8])
# 
#     raise ValueError("Unsupported Type %s", value.__class__)
# 
# 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
import datetime
from sakuraio.hardware.base import calc_parity
from sakuraio.hardware.commands import *
from sakuraio.hardware.commands.utils import value_to_bytes
from sakuraio.hardware.dummy import DummySakuraIO
from sakuraio.hardware.exceptions import CommandError, ParityError


class CommandTest(unittest.TestCase):

    def _initial(self, status, response):
        payload = [status, len(response)] + response

# Path: sakuraio/hardware/base.py
# def calc_parity(values):
#     parity = 0x00
#     for value in values:
#         parity ^= value
#     return parity
# 
# Path: sakuraio/hardware/commands/utils.py
# def value_to_bytes(value):
#     """Convert value to raw values.
# 
#     :param value:
#         Value to Convert
#     :type value: integer, float, str or bytes
# 
#     :return: Tuple of `Type` string and `Value` list
#     :rtype: (str, list)
#     """
# 
#     if isinstance(value, float):
#         return ("d", pack("<d", value))
# 
#     if isinstance(value, int):
#         if value > 9223372036854775807:
#             return ("L", pack("<Q", value))
#         return ("l", pack("<q", value))
# 
#     if platform.python_version_tuple()[0] == "2" and isinstance(value, long):
#         return ("L", pack("<Q", value))
# 
#     if isinstance(value, str):
#         if platform.python_version_tuple()[0] == "2":
#             result = []
#             for c in value.encode("utf-8"):
#                 result.append(ord(c))
#             return ("b", (result+[0x00]*8)[:8])
#         else:
#             return ("b", (list(value.encode("utf-8"))+[0x00]*8)[:8])
# 
#     if isinstance(value, bytes):
#         return ("b", (list(value)+[0x00]*8)[:8])
# 
#     raise ValueError("Unsupported Type %s", value.__class__)
# 
# 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_commands.py
import unittest
import datetime
from sakuraio.hardware.base import calc_parity
from sakuraio.hardware.commands import *
from sakuraio.hardware.commands.utils import value_to_bytes
from sakuraio.hardware.dummy import DummySakuraIO
from sakuraio.hardware.exceptions import CommandError, ParityError



class CommandTest(unittest.TestCase):

    def _initial(self, status, response):
        payload = [status, len(response)] + response

        payload.append(calc_parity(payload))