Fix 222 (#296)
* Added exceptions to packer and parser * added exception tests * improve style * linter is annoying * static analysis fix * static analysis fix2 * static analysis fix3 * clean up the code * update exceptions * style1 * style2
This commit is contained in:
parent
42e105ec1c
commit
ccd7d3e438
|
@ -20,9 +20,11 @@ cdef class CANPacker:
|
|||
map[int, int] address_to_size
|
||||
|
||||
def __init__(self, dbc_name):
|
||||
self.packer = new cpp_CANPacker(dbc_name)
|
||||
self.dbc = dbc_lookup(dbc_name)
|
||||
|
||||
if not self.dbc:
|
||||
raise RuntimeError("Can't lookup" + dbc_name)
|
||||
|
||||
self.packer = new cpp_CANPacker(dbc_name)
|
||||
num_msgs = self.dbc[0].num_msgs
|
||||
for i in range(num_msgs):
|
||||
msg = self.dbc[0].msgs[i]
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
from opendbc.can.parser_pyx import CANParser # pylint: disable=no-name-in-module, import-error
|
||||
assert CANParser
|
||||
from opendbc.can.parser_pyx import CANParser, CANDefine # pylint: disable=no-name-in-module, import-error
|
||||
assert CANParser, CANDefine
|
||||
|
|
|
@ -17,7 +17,6 @@ from collections import defaultdict
|
|||
|
||||
cdef int CAN_INVALID_CNT = 5
|
||||
|
||||
|
||||
cdef class CANParser:
|
||||
cdef:
|
||||
cpp_CANParser *can
|
||||
|
@ -37,10 +36,11 @@ cdef class CANParser:
|
|||
def __init__(self, dbc_name, signals, checks=None, bus=0):
|
||||
if checks is None:
|
||||
checks = []
|
||||
|
||||
self.can_valid = True
|
||||
self.dbc_name = dbc_name
|
||||
self.dbc = dbc_lookup(dbc_name)
|
||||
if not self.dbc:
|
||||
raise RuntimeError("Can't lookup" + dbc_name)
|
||||
self.vl = {}
|
||||
self.ts = {}
|
||||
|
||||
|
@ -148,7 +148,9 @@ cdef class CANDefine():
|
|||
def __init__(self, dbc_name):
|
||||
self.dbc_name = dbc_name
|
||||
self.dbc = dbc_lookup(dbc_name)
|
||||
|
||||
if not self.dbc:
|
||||
raise RuntimeError("Can't lookup" + dbc_name)
|
||||
|
||||
num_vals = self.dbc[0].num_vals
|
||||
|
||||
address_to_msg_name = {}
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
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"
|
||||
dbc_invalid = dbc_file + "abcdef"
|
||||
signals = [
|
||||
("STEER_TORQUE", "STEERING_CONTROL", 0),
|
||||
("STEER_TORQUE_REQUEST", "STEERING_CONTROL", 0),
|
||||
]
|
||||
checks = []
|
||||
with self.assertRaises(RuntimeError):
|
||||
CANParser(dbc_invalid, signals, checks, 0)
|
||||
with self.assertRaises(RuntimeError):
|
||||
CANPacker(dbc_invalid)
|
||||
with self.assertRaises(RuntimeError):
|
||||
CANDefine(dbc_invalid)
|
||||
|
||||
# Everything is supposed to work below
|
||||
CANParser(dbc_file, signals, checks, 0)
|
||||
CANPacker(dbc_file)
|
||||
CANDefine(dbc_file)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
Loading…
Reference in New Issue