# Path: can4python/canframe.py
# class CanFrame():
#     def __init__(self, frame_id, frame_data, frame_format=constants.CAN_FRAMEFORMAT_STANDARD):
#     def __repr__(self):
#     def __len__(self):
#     def from_empty_bytes(cls, frame_id, number_of_bytes, frame_format=constants.CAN_FRAMEFORMAT_STANDARD):
#     def from_rawframe(cls, rawframe):
#     def frame_id(self):
#     def frame_id(self, value):
#     def frame_data(self):
#     def frame_data(self, value):
#     def frame_format(self):
#     def frame_format(self, value):
#     def get_signalvalue(self, signaldefinition):
#     def set_signalvalue(self, signaldefinition, physical_value=None):
#     def unpack(self, frame_definitions):
#     def get_rawframe(self):
#     def get_descriptive_ascii_art(self):
# 
# Path: can4python/caninterface_bcm.py
# class SocketCanBcmInterface():
#     def __init__(self, interfacename, timeout=None):
#     def __repr__(self):
#     def interfacename(self):
#     def close(self):
#     def recv_next_frame(self):
#     def send_frame(self, input_frame):
#     def setup_periodic_send(self, input_frame, interval=None, restart_timer=True):
#     def stop_periodic_send(self, frame_id, frame_format=constants.CAN_FRAMEFORMAT_STANDARD):
#     def setup_reception(self, frame_id, frame_format=constants.CAN_FRAMEFORMAT_STANDARD,
#                         min_interval=None, data_mask=None):
#     def stop_reception(self, frame_id, frame_format=constants.CAN_FRAMEFORMAT_STANDARD):
#     def _send_via_socket(self, input_bytes):
# def _build_bcm_header(opcode, flags, interval, frame_id, frame_format, number_of_bcm_frames):
# def _parse_bcm_header(header):
# 
# Path: can4python/exceptions.py
# class CanException(Exception):
# class CanTimeoutException(CanException):
# class CanNotFoundByKernelException(CanException):


import subprocess
import sys
import time
import unittest
from can4python import canframe
from can4python import caninterface_bcm
from can4python import exceptions
    from .test_caninterface_raw import VIRTUAL_CAN_BUS_NAME, enable_virtual_can_bus, disable_virtual_can_bus
    from test_caninterface_raw import VIRTUAL_CAN_BUS_NAME, enable_virtual_can_bus, disable_virtual_can_bus
        c = caninterface_bcm.SocketCanBcmInterface(VIRTUAL_CAN_BUS_NAME, timeout=1.0)
        self.assertEqual(c.interfacename, VIRTUAL_CAN_BUS_NAME)
        
        a.close()
        b.close()
        c.close()

    def testCreateNonExistingBus(self):
        self.assertRaises(exceptions.CanException,
                          caninterface_bcm.SocketCanBcmInterface,
                          self.NONEXISTING_CAN_BUS_NAME, timeout=1.0)
        self.assertRaises(exceptions.CanException, caninterface_bcm.SocketCanBcmInterface, 1, 1.0)

    def testWriteToInterfacenameAttribute(self):
        self.assertRaises(AttributeError, setattr, self.interface, 'interfacename', 'can0')

    def testRepr(self):
        result = repr(self.interface)
        known_result = "SocketCan BCM interface: {}".format(VIRTUAL_CAN_BUS_NAME.strip())
        self.assertEqual(result.strip(), known_result.strip())

    # Receive #

    def testSetupReception(self):
        self.interface.setup_reception(self.FRAME_ID_RECEIVE)
        self.interface.setup_reception(self.FRAME_ID_RECEIVE, min_interval=None)
        self.interface.setup_reception(self.FRAME_ID_RECEIVE, min_interval=0)  # 0 and None should be the same

    def testSetupReceptionWrongValue(self):
        self.assertRaises(exceptions.CanException, self.interface.setup_reception, -1)

# Path: can4python/canframe.py
# class CanFrame():
#     def __init__(self, frame_id, frame_data, frame_format=constants.CAN_FRAMEFORMAT_STANDARD):
#     def __repr__(self):
#     def __len__(self):
#     def from_empty_bytes(cls, frame_id, number_of_bytes, frame_format=constants.CAN_FRAMEFORMAT_STANDARD):
#     def from_rawframe(cls, rawframe):
#     def frame_id(self):
#     def frame_id(self, value):
#     def frame_data(self):
#     def frame_data(self, value):
#     def frame_format(self):
#     def frame_format(self, value):
#     def get_signalvalue(self, signaldefinition):
#     def set_signalvalue(self, signaldefinition, physical_value=None):
#     def unpack(self, frame_definitions):
#     def get_rawframe(self):
#     def get_descriptive_ascii_art(self):
# 
# Path: can4python/caninterface_bcm.py
# class SocketCanBcmInterface():
#     def __init__(self, interfacename, timeout=None):
#     def __repr__(self):
#     def interfacename(self):
#     def close(self):
#     def recv_next_frame(self):
#     def send_frame(self, input_frame):
#     def setup_periodic_send(self, input_frame, interval=None, restart_timer=True):
#     def stop_periodic_send(self, frame_id, frame_format=constants.CAN_FRAMEFORMAT_STANDARD):
#     def setup_reception(self, frame_id, frame_format=constants.CAN_FRAMEFORMAT_STANDARD,
#                         min_interval=None, data_mask=None):
#     def stop_reception(self, frame_id, frame_format=constants.CAN_FRAMEFORMAT_STANDARD):
#     def _send_via_socket(self, input_bytes):
# def _build_bcm_header(opcode, flags, interval, frame_id, frame_format, number_of_bcm_frames):
# def _parse_bcm_header(header):
# 
# Path: can4python/exceptions.py
# class CanException(Exception):
# class CanTimeoutException(CanException):
# class CanNotFoundByKernelException(CanException):


# Path: tests/test_caninterface_bcm.py
import subprocess
import sys
import time
import unittest
from can4python import canframe
from can4python import caninterface_bcm
from can4python import exceptions
    from .test_caninterface_raw import VIRTUAL_CAN_BUS_NAME, enable_virtual_can_bus, disable_virtual_can_bus
    from test_caninterface_raw import VIRTUAL_CAN_BUS_NAME, enable_virtual_can_bus, disable_virtual_can_bus

        c = caninterface_bcm.SocketCanBcmInterface(VIRTUAL_CAN_BUS_NAME, timeout=1.0)
        self.assertEqual(c.interfacename, VIRTUAL_CAN_BUS_NAME)
        
        a.close()
        b.close()
        c.close()

    def testCreateNonExistingBus(self):
        self.assertRaises(exceptions.CanException,
                          caninterface_bcm.SocketCanBcmInterface,
                          self.NONEXISTING_CAN_BUS_NAME, timeout=1.0)
        self.assertRaises(exceptions.CanException, caninterface_bcm.SocketCanBcmInterface, 1, 1.0)

    def testWriteToInterfacenameAttribute(self):
        self.assertRaises(AttributeError, setattr, self.interface, 'interfacename', 'can0')

    def testRepr(self):
        result = repr(self.interface)
        known_result = "SocketCan BCM interface: {}".format(VIRTUAL_CAN_BUS_NAME.strip())
        self.assertEqual(result.strip(), known_result.strip())

    # Receive #

    def testSetupReception(self):
        self.interface.setup_reception(self.FRAME_ID_RECEIVE)
        self.interface.setup_reception(self.FRAME_ID_RECEIVE, min_interval=None)
        self.interface.setup_reception(self.FRAME_ID_RECEIVE, min_interval=0)  # 0 and None should be the same

    def testSetupReceptionWrongValue(self):
        self.assertRaises(exceptions.CanException, self.interface.setup_reception, -1)

        self.assertRaises(exceptions.CanException, self.interface.setup_reception, 0x007, "ABC")