Skip to content

Commit

Permalink
base class for different panda safety tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adeebshihadeh committed Apr 27, 2020
1 parent bd98fe6 commit 0632710
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
21 changes: 14 additions & 7 deletions tests/safety/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions tests/safety/test_toyota.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions tests/safety/test_volkswagen_mqb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 0632710

Please sign in to comment.