forked from commaai/opendbc
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert tests to pytests (commaai#1060)
* Convert tests to pytests * cleanup * args * clean * linter --------- Co-authored-by: Maxime Desroches <desroches.maxime@gmail.com>
- Loading branch information
1 parent
de39b14
commit 5ba7870
Showing
8 changed files
with
79 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,30 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import unittest | ||
import pytest | ||
|
||
from opendbc.can.parser import CANParser, CANDefine | ||
from opendbc.can.packer import CANPacker | ||
from opendbc.can.tests import TEST_DBC | ||
|
||
|
||
class TestCanParserPackerExceptions(unittest.TestCase): | ||
class TestCanParserPackerExceptions: | ||
def test_civic_exceptions(self): | ||
dbc_file = "honda_civic_touring_2016_can_generated" | ||
dbc_invalid = dbc_file + "abcdef" | ||
msgs = [("STEERING_CONTROL", 50)] | ||
with self.assertRaises(RuntimeError): | ||
with pytest.raises(RuntimeError): | ||
CANParser(dbc_invalid, msgs, 0) | ||
with self.assertRaises(RuntimeError): | ||
with pytest.raises(RuntimeError): | ||
CANPacker(dbc_invalid) | ||
with self.assertRaises(RuntimeError): | ||
with pytest.raises(RuntimeError): | ||
CANDefine(dbc_invalid) | ||
with self.assertRaises(KeyError): | ||
with pytest.raises(KeyError): | ||
CANDefine(TEST_DBC) | ||
|
||
parser = CANParser(dbc_file, msgs, 0) | ||
with self.assertRaises(RuntimeError): | ||
with pytest.raises(RuntimeError): | ||
parser.update_strings([b'']) | ||
|
||
# Everything is supposed to work below | ||
CANParser(dbc_file, msgs, 0) | ||
CANParser(dbc_file, [], 0) | ||
CANPacker(dbc_file) | ||
CANDefine(dbc_file) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,26 @@ | ||
#!/usr/bin/env python3 | ||
import unittest | ||
|
||
from opendbc.can.can_define import CANDefine | ||
from opendbc.can.tests import ALL_DBCS | ||
|
||
|
||
class TestCADNDefine(unittest.TestCase): | ||
class TestCADNDefine: | ||
def test_civic(self): | ||
|
||
dbc_file = "honda_civic_touring_2016_can_generated" | ||
defs = CANDefine(dbc_file) | ||
|
||
self.assertDictEqual(defs.dv[399], defs.dv['STEER_STATUS']) | ||
self.assertDictEqual(defs.dv[399], | ||
{'STEER_STATUS': | ||
{7: 'PERMANENT_FAULT', | ||
6: 'TMP_FAULT', | ||
5: 'FAULT_1', | ||
4: 'NO_TORQUE_ALERT_2', | ||
3: 'LOW_SPEED_LOCKOUT', | ||
2: 'NO_TORQUE_ALERT_1', | ||
0: 'NORMAL'} | ||
} | ||
) | ||
|
||
def test_all_dbcs(self): | ||
assert defs.dv[399] == defs.dv['STEER_STATUS'] | ||
assert defs.dv[399] == {'STEER_STATUS': | ||
{7: 'PERMANENT_FAULT', | ||
6: 'TMP_FAULT', | ||
5: 'FAULT_1', | ||
4: 'NO_TORQUE_ALERT_2', | ||
3: 'LOW_SPEED_LOCKOUT', | ||
2: 'NO_TORQUE_ALERT_1', | ||
0: 'NORMAL'} | ||
} | ||
|
||
def test_all_dbcs(self, subtests): | ||
# Asserts no exceptions on all DBCs | ||
for dbc in ALL_DBCS: | ||
with self.subTest(dbc=dbc): | ||
with subtests.test(dbc=dbc): | ||
CANDefine(dbc) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
Oops, something went wrong.