From 33940105be96ec1f265f9de3fb40956710cd1ea8 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Fri, 7 Jul 2023 01:02:12 -0700 Subject: [PATCH] tests: global constants (#889) small clean up --- can/tests/__init__.py | 8 ++++++++ can/tests/test_dbc_exceptions.py | 1 + can/tests/test_dbc_parser.py | 12 ++---------- can/tests/test_packer_parser.py | 5 +---- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/can/tests/__init__.py b/can/tests/__init__.py index e69de29..3bf02fd 100644 --- a/can/tests/__init__.py +++ b/can/tests/__init__.py @@ -0,0 +1,8 @@ +import glob +import os + +from opendbc import DBC_PATH + +ALL_DBCS = [os.path.basename(dbc).split('.')[0] for dbc in + glob.glob(f"{DBC_PATH}/*.dbc")] +TEST_DBC = os.path.abspath(os.path.join(os.path.dirname(__file__), "test.dbc")) diff --git a/can/tests/test_dbc_exceptions.py b/can/tests/test_dbc_exceptions.py index b594893..e9102a2 100755 --- a/can/tests/test_dbc_exceptions.py +++ b/can/tests/test_dbc_exceptions.py @@ -5,6 +5,7 @@ import unittest from opendbc.can.parser import CANParser, CANDefine from opendbc.can.packer import CANPacker + class TestCanParserPackerExceptions(unittest.TestCase): def test_civic_exceptions(self): dbc_file = "honda_civic_touring_2016_can_generated" diff --git a/can/tests/test_dbc_parser.py b/can/tests/test_dbc_parser.py index b283926..72cacd7 100755 --- a/can/tests/test_dbc_parser.py +++ b/can/tests/test_dbc_parser.py @@ -1,19 +1,11 @@ #!/usr/bin/env python3 -import glob -import os import unittest -from opendbc import DBC_PATH from opendbc.can.parser import CANParser +from opendbc.can.tests import ALL_DBCS class TestDBCParser(unittest.TestCase): - @classmethod - def setUpClass(cls): - cls.dbcs = [] - for dbc in glob.glob(f"{DBC_PATH}/*.dbc"): - cls.dbcs.append(os.path.basename(dbc).split('.')[0]) - def test_parse_all_dbcs(self): """ Dynamic DBC parser checks: @@ -23,7 +15,7 @@ class TestDBCParser(unittest.TestCase): - All BO_, SG_, VAL_ lines for syntax errors """ - for dbc in self.dbcs: + for dbc in ALL_DBCS: with self.subTest(dbc=dbc): CANParser(dbc, [], [], 0) diff --git a/can/tests/test_packer_parser.py b/can/tests/test_packer_parser.py index 126fd49..b0be248 100755 --- a/can/tests/test_packer_parser.py +++ b/can/tests/test_packer_parser.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -import os import unittest import random from functools import partial @@ -7,9 +6,7 @@ from functools import partial import cereal.messaging as messaging from opendbc.can.parser import CANParser from opendbc.can.packer import CANPacker - - -TEST_DBC = os.path.abspath(os.path.join(os.path.dirname(__file__), "test.dbc")) +from opendbc.can.tests import TEST_DBC # Python implementation so we don't have to depend on boardd