From 0632710acd922a4496472a86f56e8f9203d48340 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Mon, 27 Apr 2020 15:39:08 -0700 Subject: [PATCH] base class for different panda safety tests --- tests/safety/common.py | 21 ++++++++++++++------- tests/safety/test_toyota.py | 10 +++++----- tests/safety/test_volkswagen_mqb.py | 10 +++++----- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/tests/safety/common.py b/tests/safety/common.py index e711cf39712e88..464d9149775f3e 100644 --- a/tests/safety/common.py +++ b/tests/safety/common.py @@ -41,7 +41,20 @@ def make_can_msg_panda(self, name_or_addr, bus, values, counter=-1): msg = self.make_can_msg(name_or_addr, bus, values, counter=-1) return package_can_msg(msg) -class PandaSafetyTest(unittest.TestCase): +class PandaSafetyTestBase(unittest.TestCase): + @classmethod + def setUpClass(cls): + if cls.__name__ == "PandaSafetyTestBase": + cls.safety = None + raise unittest.SkipTest + + def _rx(self, msg): + return self.safety.safety_rx_hook(msg) + + def _tx(self, msg): + return self.safety.safety_tx_hook(msg) + +class PandaSafetyTest(PandaSafetyTestBase): TX_MSGS = None STANDSTILL_THRESHOLD = None GAS_PRESSED_THRESHOLD = 0 @@ -56,12 +69,6 @@ def setUpClass(cls): cls.safety = None raise unittest.SkipTest - def _rx(self, msg): - return self.safety.safety_rx_hook(msg) - - def _tx(self, msg): - return self.safety.safety_tx_hook(msg) - @abc.abstractmethod def _brake_msg(self, brake): pass diff --git a/tests/safety/test_toyota.py b/tests/safety/test_toyota.py index 63e917a4e212be..29d06f5ba1dac4 100755 --- a/tests/safety/test_toyota.py +++ b/tests/safety/test_toyota.py @@ -42,11 +42,11 @@ class TestToyotaSafety(common.PandaSafetyTest): FWD_BUS_LOOKUP = {0: 2, 2: 0} @classmethod - def setUp(cls): - cls.packer = CANPackerPanda("toyota_prius_2017_pt_generated") - cls.safety = libpandasafety_py.libpandasafety - cls.safety.set_safety_hooks(Panda.SAFETY_TOYOTA, 66) - cls.safety.init_tests_toyota() + def setUp(self): + self.packer = CANPackerPanda("toyota_prius_2017_pt_generated") + self.safety = libpandasafety_py.libpandasafety + self.safety.set_safety_hooks(Panda.SAFETY_TOYOTA, 66) + self.safety.init_tests_toyota() def _set_prev_torque(self, t): self.safety.set_toyota_desired_torque_last(t) diff --git a/tests/safety/test_volkswagen_mqb.py b/tests/safety/test_volkswagen_mqb.py index b6eaa7e7094354..279c98ca73b1a7 100644 --- a/tests/safety/test_volkswagen_mqb.py +++ b/tests/safety/test_volkswagen_mqb.py @@ -42,11 +42,11 @@ class TestVolkswagenMqbSafety(common.PandaSafetyTest): FWD_BUS_LOOKUP = {0: 2, 2: 0} @classmethod - def setUp(cls): - cls.packer = CANPackerPanda("vw_mqb_2010") - cls.safety = libpandasafety_py.libpandasafety - cls.safety.set_safety_hooks(Panda.SAFETY_VOLKSWAGEN_MQB, 0) - cls.safety.init_tests_volkswagen() + def setUp(self): + self.packer = CANPackerPanda("vw_mqb_2010") + self.safety = libpandasafety_py.libpandasafety + self.safety.set_safety_hooks(Panda.SAFETY_VOLKSWAGEN_MQB, 0) + self.safety.init_tests_volkswagen() def _set_prev_torque(self, t): self.safety.set_volkswagen_desired_torque_last(t)