Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_dbc_parse_error_messages(self):
# No valid entry.
with self.assertRaises(textparser.ParseError) as cm:
cantools.db.formats.dbc.load_string('abc')
self.assertEqual(
str(cm.exception),
'Invalid syntax at line 1, column 1: ">>!<>!<
def test_dbc_parse_error_messages(self):
# No valid entry.
with self.assertRaises(textparser.ParseError) as cm:
cantools.db.formats.dbc.load_string('abc')
self.assertEqual(
str(cm.exception),
'Invalid syntax at line 1, column 1: ">>!<>!<>!<
str(cm.exception),
'Invalid syntax at line 2, column 5: "BO_ >>!<>!<>!<<8 EMV_Statusmeldungen"')
# Missing frame id in message comment.
with self.assertRaises(textparser.ParseError) as cm:
cantools.db.formats.dbc.load_string('CM_ BO_ "Foo.";')
self.assertEqual(
str(cm.exception),
'Invalid syntax at line 1, column 9: "CM_ BO_ >>!<<"Foo.";"')
'Invalid syntax at line 2, column 1: ">>!<>!<<8 EMV_Statusmeldungen"')
# Missing frame id in message comment.
with self.assertRaises(textparser.ParseError) as cm:
cantools.db.formats.dbc.load_string('CM_ BO_ "Foo.";')
self.assertEqual(
str(cm.exception),
'Invalid syntax at line 1, column 9: "CM_ BO_ >>!<<"Foo.";"')
# Missing frame id in message comment, using load_string().
with self.assertRaises(cantools.db.UnsupportedDatabaseFormatError) as cm:
cantools.db.load_string('CM_ BO_ "Foo.";')
self.assertEqual(
str(cm.exception),
"DBC: \"Invalid syntax at line 1, column 9: \"CM_ BO_ >>!<<\"Foo."
"\";\"\", KCD: \"syntax error: line 1, column 0\", SYM: \"Only SYM "
def test_dbc_parse_error_messages(self):
# No valid entry.
with self.assertRaises(textparser.ParseError) as cm:
cantools.db.formats.dbc.load_string('abc')
self.assertEqual(
str(cm.exception),
'Invalid syntax at line 1, column 1: ">>!<>!<>!<
str(cm.exception),
'Invalid syntax at line 1, column 1: ">>!<>!<>!<
str(cm.exception),
'Invalid syntax at line 2, column 5: "BO_ >>!<>!<>!<<8 EMV_Statusmeldungen"')
# Missing frame id in message comment.
with self.assertRaises(textparser.ParseError) as cm:
cantools.db.formats.dbc.load_string('CM_ BO_ "Foo.";')
self.assertEqual(
str(cm.exception),
'Invalid syntax at line 1, column 9: "CM_ BO_ >>!<<"Foo.";"')
def add_dbc_string(self, string):
"""Parse given DBC data string and add the parsed data to the
database.
>>> db = cantools.db.File()
>>> with open ('foo.dbc', 'r') as fin:
... db.add_dbc_string(fin.read())
"""
database = dbc.load_string(string)
for message in database.messages:
self.add_message(message)
self._nodes = database.nodes
self._buses = database.buses
self._version = database.version
self._attribute_definitions = database.attribute_definitions
self._attribute_definition_defaults = database.attribute_definition_defaults