########################################################################### # # Copyright (c) 2020-2023 Diality Inc. - All Rights Reserved. # # THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN # WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. # # @file unittests.py # # @author (last) Dara Navaei # @date (last) 22-Feb-2022 # @author (original) Peter Lucia # @date (original) 11-Nov-2020 # ############################################################################ import test import sys from dialin.ui import crc from dialin.ui.utils import check_can0 MICRO = [8, 9] def test_python_version(): """ tests the current python version compatibility @return: None """ test.compare(sys.version_info.major, 3) test.compare(sys.version_info.minor, 6) test.compare(sys.version_info.micro in MICRO, True) def test_crc8(): """ test case for crc8 method @return: None """ str_byte1 = ("4B 43 09 00 14 00 00" "00 00 00 00 00 00 00 00" "00 00 00 00 00 00 00 00" "00 00" # 9D ) str_byte2 = ("4C 43 02 00 12 03 00" "00 00 14 00 00 00 00 00" "00 00 00 00 00 00 7F 00" # 55 ) str_byte3 = ("4A 43 05 00 1C 00 00" "00 00 00 00 00 00 00 00" "00 00 00 00 00 00 6A B6" "99 43 D5 68 6F 44 00 00" "00 00" # 4F ) str_byte4 = ("FB 18 07 00 04 00 00" "00 00" # 7F ) test.compare(crc.calc_crc8(str_byte1, ' '), '9D') test.compare(crc.calc_crc8(str_byte2, ' '), '55') test.compare(crc.calc_crc8(str_byte3, ' '), '4F') test.compare(crc.calc_crc8(str_byte4, ' '), '7F') def test_can0(): """ tests if the can0 bus driver presents @return: None """ ok, msg = check_can0() test.compare(ok, True, msg)