# Path: can4python/canframe_definition.py
# class CanFrameDefinition():
#     def __init__(self, frame_id, name='', dlc=constants.MAX_NUMBER_OF_CAN_DATA_BYTES, cycletime=None,
#                  frame_format=constants.CAN_FRAMEFORMAT_STANDARD):
#     def __repr__(self, long_text=True):
#     def frame_id(self):
#     def frame_id(self, value):
#     def dlc(self):
#     def dlc(self, value):
#     def cycletime(self):
#     def cycletime(self, value):
#     def throttle_time(self):
#     def throttle_time(self, value):
#     def frame_format(self):
#     def frame_format(self, value):
#     def producer_ids(self):
#     def producer_ids(self, value):
#     def get_descriptive_ascii_art(self):
#     def get_signal_mask(self):
#     def is_outbound(self, ego_node_ids):
# 
# Path: can4python/configuration.py
# class Configuration():
#     def __init__(self, framedefinitions=None, busname=None, ego_node_ids=None):
#     def ego_node_ids(self):
#     def ego_node_ids(self, value):
#     def __repr__(self):
#     def get_descriptive_ascii_art(self):
#     def add_framedefinition(self, framedef):
#     def set_throttle_times(self, inputdict):
#     def set_throttle_times_from_signalnames(self, inputdict):
#     def set_receive_on_change_only(self, inputlist):
#     def set_receive_on_change_only_from_signalnames(self, inputlist):
#     def find_frameid_from_signalname(self, input_signalname):
# 
# Path: can4python/exceptions.py
# class CanException(Exception):
# class CanTimeoutException(CanException):
# class CanNotFoundByKernelException(CanException):
# 
# Path: can4python/filehandler_kcd.py
# class FilehandlerKcd():
#     def read(filename, busname=None):
#     def write(config, filename):


import contextlib
import copy
import os
import sys
import unittest
from can4python import canframe_definition
from can4python import configuration
from can4python import exceptions
from can4python import filehandler_kcd
    from .test_configuration import FRAME_ID_SEND, TESTCONFIG1
    from test_configuration import FRAME_ID_SEND, TESTCONFIG1
        self.assertTrue(os.path.exists(self.OUTPUT_FILENAME_1))

        # TODO: Verify result in more detail

    def testSaveLoadedConfigurationToFile(self):
        with contextlib.suppress(FileNotFoundError):
            os.remove(self.OUTPUT_FILENAME_2)

        config = filehandler_kcd.FilehandlerKcd.read(self.input_filename, None)
        self.assertEqual(config.busname, "Mainbus")
        filehandler_kcd.FilehandlerKcd.write(config, self.OUTPUT_FILENAME_2)
        self.assertTrue(os.path.exists(self.OUTPUT_FILENAME_2))

        # TODO: Check manually that the input and output files are similar

    def testWriteKcdFileNoBusnameGiven(self):
        with contextlib.suppress(FileNotFoundError):
            os.remove(self.OUTPUT_FILENAME_3)

        config = configuration.Configuration()
        self.assertEqual(config.busname, None)
        filehandler_kcd.FilehandlerKcd.write(config, self.OUTPUT_FILENAME_3)

        with open(self.OUTPUT_FILENAME_3, 'r') as file:
            self.assertTrue(any("Mainbus" in line for line in file.readlines()))

    def testWriteKcdFileNoProducerGiven(self):
        with contextlib.suppress(FileNotFoundError):
            os.remove(self.OUTPUT_FILENAME_10)


# Path: can4python/canframe_definition.py
# class CanFrameDefinition():
#     def __init__(self, frame_id, name='', dlc=constants.MAX_NUMBER_OF_CAN_DATA_BYTES, cycletime=None,
#                  frame_format=constants.CAN_FRAMEFORMAT_STANDARD):
#     def __repr__(self, long_text=True):
#     def frame_id(self):
#     def frame_id(self, value):
#     def dlc(self):
#     def dlc(self, value):
#     def cycletime(self):
#     def cycletime(self, value):
#     def throttle_time(self):
#     def throttle_time(self, value):
#     def frame_format(self):
#     def frame_format(self, value):
#     def producer_ids(self):
#     def producer_ids(self, value):
#     def get_descriptive_ascii_art(self):
#     def get_signal_mask(self):
#     def is_outbound(self, ego_node_ids):
# 
# Path: can4python/configuration.py
# class Configuration():
#     def __init__(self, framedefinitions=None, busname=None, ego_node_ids=None):
#     def ego_node_ids(self):
#     def ego_node_ids(self, value):
#     def __repr__(self):
#     def get_descriptive_ascii_art(self):
#     def add_framedefinition(self, framedef):
#     def set_throttle_times(self, inputdict):
#     def set_throttle_times_from_signalnames(self, inputdict):
#     def set_receive_on_change_only(self, inputlist):
#     def set_receive_on_change_only_from_signalnames(self, inputlist):
#     def find_frameid_from_signalname(self, input_signalname):
# 
# Path: can4python/exceptions.py
# class CanException(Exception):
# class CanTimeoutException(CanException):
# class CanNotFoundByKernelException(CanException):
# 
# Path: can4python/filehandler_kcd.py
# class FilehandlerKcd():
#     def read(filename, busname=None):
#     def write(config, filename):


# Path: tests/test_filehandler_kcd.py
import contextlib
import copy
import os
import sys
import unittest
from can4python import canframe_definition
from can4python import configuration
from can4python import exceptions
from can4python import filehandler_kcd
    from .test_configuration import FRAME_ID_SEND, TESTCONFIG1
    from test_configuration import FRAME_ID_SEND, TESTCONFIG1

        self.assertTrue(os.path.exists(self.OUTPUT_FILENAME_1))

        # TODO: Verify result in more detail

    def testSaveLoadedConfigurationToFile(self):
        with contextlib.suppress(FileNotFoundError):
            os.remove(self.OUTPUT_FILENAME_2)

        config = filehandler_kcd.FilehandlerKcd.read(self.input_filename, None)
        self.assertEqual(config.busname, "Mainbus")
        filehandler_kcd.FilehandlerKcd.write(config, self.OUTPUT_FILENAME_2)
        self.assertTrue(os.path.exists(self.OUTPUT_FILENAME_2))

        # TODO: Check manually that the input and output files are similar

    def testWriteKcdFileNoBusnameGiven(self):
        with contextlib.suppress(FileNotFoundError):
            os.remove(self.OUTPUT_FILENAME_3)

        config = configuration.Configuration()
        self.assertEqual(config.busname, None)
        filehandler_kcd.FilehandlerKcd.write(config, self.OUTPUT_FILENAME_3)

        with open(self.OUTPUT_FILENAME_3, 'r') as file:
            self.assertTrue(any("Mainbus" in line for line in file.readlines()))

    def testWriteKcdFileNoProducerGiven(self):
        with contextlib.suppress(FileNotFoundError):
            os.remove(self.OUTPUT_FILENAME_10)


        config = configuration.Configuration()