# Path: can4python/utilities.py
# def calculate_backward_bitnumber(normal_bitnumber):
# def calculate_normal_bitnumber(backward_bitnumber):
# def generate_bit_byte_overview(inputstring, number_of_indent_spaces=4, show_reverse_bitnumbering=False):
# def generate_can_integer_overview(value):
# def can_bytes_to_int(input_bytes):
# def int_to_can_bytes(dlc, dataint):
# def twos_complement(value, bits):
# def from_twos_complement(value, bits):
# def split_seconds_to_full_and_part(seconds_float):
# def check_frame_id_and_format(frame_id, frame_format):
# def get_busvalue_from_bytes(input_bytes, endianness, numberofbits, startbit):
# def get_shiftedvalue_from_busvalue(input_value, endianness, numberofbits, startbit):
# 
# Path: can4python/exceptions.py
# class CanException(Exception):
# class CanTimeoutException(CanException):
# class CanNotFoundByKernelException(CanException):


import sys
import unittest
from can4python import utilities
from can4python import exceptions
    )

    def testKnownValues(self):
        USECONDS_DELTA = 1
        for inputvalue, known_seconds_full, known_useconds in self.knownValues:
            result_seconds_full, result_useconds = utilities.split_seconds_to_full_and_part(inputvalue)

            self.assertEqual(result_seconds_full, known_seconds_full)
            self.assertLessEqual(result_useconds, known_useconds + USECONDS_DELTA)
            self.assertGreaterEqual(result_useconds, known_useconds - USECONDS_DELTA)

    def testWrongInputValue(self):
        self.assertRaises(exceptions.CanException, utilities.split_seconds_to_full_and_part, -0.001)
        self.assertRaises(exceptions.CanException, utilities.split_seconds_to_full_and_part, -1)
        self.assertRaises(exceptions.CanException, utilities.split_seconds_to_full_and_part, -1.0)
        self.assertRaises(exceptions.CanException, utilities.split_seconds_to_full_and_part, -1000)


class TestCheckFrameId(unittest.TestCase):

    def testKnownValues(self):
        utilities.check_frame_id_and_format(0, 'standard')
        utilities.check_frame_id_and_format(0, 'extended')
        utilities.check_frame_id_and_format(7, 'standard')
        utilities.check_frame_id_and_format(19, 'extended')
        utilities.check_frame_id_and_format(0x7FF, 'standard')
        utilities.check_frame_id_and_format(0x1FFFFFFF, 'extended')

    def testWrongInputValue(self):
        self.assertRaises(exceptions.CanException, utilities.check_frame_id_and_format, None, 'standard')

# Path: can4python/utilities.py
# def calculate_backward_bitnumber(normal_bitnumber):
# def calculate_normal_bitnumber(backward_bitnumber):
# def generate_bit_byte_overview(inputstring, number_of_indent_spaces=4, show_reverse_bitnumbering=False):
# def generate_can_integer_overview(value):
# def can_bytes_to_int(input_bytes):
# def int_to_can_bytes(dlc, dataint):
# def twos_complement(value, bits):
# def from_twos_complement(value, bits):
# def split_seconds_to_full_and_part(seconds_float):
# def check_frame_id_and_format(frame_id, frame_format):
# def get_busvalue_from_bytes(input_bytes, endianness, numberofbits, startbit):
# def get_shiftedvalue_from_busvalue(input_value, endianness, numberofbits, startbit):
# 
# Path: can4python/exceptions.py
# class CanException(Exception):
# class CanTimeoutException(CanException):
# class CanNotFoundByKernelException(CanException):


# Path: tests/test_utilities.py
import sys
import unittest
from can4python import utilities
from can4python import exceptions

    )

    def testKnownValues(self):
        USECONDS_DELTA = 1
        for inputvalue, known_seconds_full, known_useconds in self.knownValues:
            result_seconds_full, result_useconds = utilities.split_seconds_to_full_and_part(inputvalue)

            self.assertEqual(result_seconds_full, known_seconds_full)
            self.assertLessEqual(result_useconds, known_useconds + USECONDS_DELTA)
            self.assertGreaterEqual(result_useconds, known_useconds - USECONDS_DELTA)

    def testWrongInputValue(self):
        self.assertRaises(exceptions.CanException, utilities.split_seconds_to_full_and_part, -0.001)
        self.assertRaises(exceptions.CanException, utilities.split_seconds_to_full_and_part, -1)
        self.assertRaises(exceptions.CanException, utilities.split_seconds_to_full_and_part, -1.0)
        self.assertRaises(exceptions.CanException, utilities.split_seconds_to_full_and_part, -1000)


class TestCheckFrameId(unittest.TestCase):

    def testKnownValues(self):
        utilities.check_frame_id_and_format(0, 'standard')
        utilities.check_frame_id_and_format(0, 'extended')
        utilities.check_frame_id_and_format(7, 'standard')
        utilities.check_frame_id_and_format(19, 'extended')
        utilities.check_frame_id_and_format(0x7FF, 'standard')
        utilities.check_frame_id_and_format(0x1FFFFFFF, 'extended')

    def testWrongInputValue(self):
        self.assertRaises(exceptions.CanException, utilities.check_frame_id_and_format, None, 'standard')

        self.assertRaises(exceptions.CanException, utilities.check_frame_id_and_format, None, 'extended')