How to use the cantools.db.formats.dbc.load_string function in cantools

To help you get started, we’ve selected a few cantools examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github eerimoq / cantools / tests / test_database.py View on Github external
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: ">>!<>!<
github eerimoq / cantools / tests / test_database.py View on Github external
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: ">>!<>!<>!<
github eerimoq / cantools / tests / test_database.py View on Github external
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.";"')
github eerimoq / cantools / tests / test_database.py View on Github external
'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 "
github eerimoq / cantools / tests / test_database.py View on Github external
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: ">>!<>!<>!<
github eerimoq / cantools / tests / test_database.py View on Github external
str(cm.exception),
            'Invalid syntax at line 1, column 1: ">>!<>!<>!<
github eerimoq / cantools / tests / test_database.py View on Github external
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.";"')
github eerimoq / cantools / cantools / db / file.py View on Github external
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