예제 #1
0
 def test_parse_signal(self, line, signal_name, start_bit, length, little_endian, signed, factor, offset, value_min,\
                       value_max, unit, is_multiplexer, multiplexer_id, nodes, add_multiplexer):
     parser = DBCParser()
     parser._can_network.add_node(CANNode('Sender'))
     for node in nodes:
         parser._can_network.add_node(CANNode(node))
     msg = CANMessage(2, 'CANMessage', 8)
     if add_multiplexer:
         msg.add_signal(CANSignal('MultiplexerSignal', 8, 8, is_multiplexer=True))
     parser._can_network.nodes['Sender'].add_message(msg)
     parser._mode = ('MESSAGE', msg)
     parser._parse_line(line)
     sig = msg.signals[signal_name]
     assert sig.name == signal_name
     assert sig.start_bit == start_bit
     assert sig.length == length
     assert sig.little_endian == little_endian
     assert sig.signed == signed
     assert sig.factor == factor
     assert sig.value_min == value_min
     assert sig.value_max == value_max
     assert sig.unit == unit
     assert sig.is_multiplexer == is_multiplexer
     assert sig.multiplexer_id == multiplexer_id
     for node in nodes:
         assert parser._can_network.nodes[node] in sig.receiver
예제 #2
0
 def test_parse_message_desc(self, line, can_id, expected_desc):
     parser = DBCParser()
     node = CANNode('Node0')
     node.add_message(CANMessage(can_id, 'CANMessage', 8))
     parser._can_network.add_node(node)
     parser._parse_line(line)
     assert parser._can_network.nodes['Node0'].messages[1234].description == expected_desc
예제 #3
0
 def test_parse_nodes(self, line, expected_nodes):
     parser = DBCParser()
     parser._parse_line(line)
     assert len(parser._can_network.nodes) == len(expected_nodes)
     node_names = parser._can_network._nodes.keys()
     for node in expected_nodes:
         assert node in node_names
예제 #4
0
 def test_parse_attribute_definition(self, line, obj_type_expected, def_name,  def_type_expected, check_config):
     parser = DBCParser()
     parser._parse_line(line)
     assert def_name in parser._can_network.attributes.definitions
     ad = parser._can_network.attributes.definitions[def_name]
     assert ad.obj_type == obj_type_expected
     assert def_type_expected == type(ad)
     assert check_config(ad)
예제 #5
0
 def test_parse_message(self, line, expected_name, expected_id, expected_length, expected_sender):
     parser = DBCParser()
     sender = CANNode(expected_sender)
     parser._can_network.add_node(sender)
     parser._parse_line(line)
     msg = parser._can_network.get_message(1234)
     assert msg.name == expected_name
     assert msg.can_id == expected_id
     assert msg.length == expected_length
     assert msg.sender == sender
예제 #6
0
 def test_parse_signal_desc(self, line, can_id, signal_name, expected_desc):
     parser = DBCParser()
     node = CANNode('Node')
     msg = CANMessage(can_id, 'Message', 8)
     sig = CANSignal(signal_name, 0, 8)
     msg.add_signal(sig)
     node.add_message(msg)
     parser._can_network.add_node(node)
     parser._parse_line(line)
     assert sig.description == expected_desc
예제 #7
0
    def test_parse_val(self, line, msg_id, signal_name, expected_dict, val_table_name):
        parser = DBCParser()
        if val_table_name:
            parser._can_network.add_value_dict(val_table_name, expected_dict)

        node = CANNode('Node')
        parser._can_network.add_node(node)
        msg = CANMessage(msg_id, 'Message', 1)
        node.add_message(msg)
        sig = CANSignal(signal_name, 0, 8)
        msg.add_signal(sig)

        parser._parse_line(line)

        assert sig.value_dict == expected_dict
예제 #8
0
    def test_parse_attribute(self, line, expected_value, attr_definition, cfg_dict):
        parser = DBCParser()
        parser._can_network.attributes.add_definition(attr_definition)

        if attr_definition.obj_type == CANNetwork:
            can_object = parser._can_network
        if attr_definition.obj_type in [CANNode, CANMessage, CANSignal]:
            cfg_dict['NODE'] = CANNode(cfg_dict['NODE'])
            parser._can_network.add_node(cfg_dict['NODE'])
            can_object = cfg_dict['NODE']
        if attr_definition.obj_type in [CANMessage, CANSignal]:
            cfg_dict['MESSAGE'] = CANMessage(cfg_dict['MESSAGE'], 'Message', 1)
            cfg_dict['NODE'].add_message(cfg_dict['MESSAGE'])
            can_object = cfg_dict['MESSAGE']
        if attr_definition.obj_type in [CANSignal]:
            cfg_dict['SIGNAL'] = CANSignal(cfg_dict['SIGNAL'], 0, 8)
            cfg_dict['MESSAGE'].add_signal(cfg_dict['SIGNAL'])
            can_object = cfg_dict['SIGNAL']

        parser._parse_line(line)
        assert can_object.attributes[attr_definition.name].value == expected_value
예제 #9
0
def test_whole_dbc():
    parser = DBCParser()
    candb = parser.parse_file('docs/DBC_template.dbc')
    assert len(candb.nodes) == 3
    assert candb.version == "1.0"
    assert candb.speed == 500
예제 #10
0
 def test_parse_val_table(self, line, expected_name, expected_dict):
     parser = DBCParser()
     parser._parse_line(line)
     assert len(parser._can_network.value_dicts) == 1
     assert expected_name in parser._can_network.value_dicts
     assert parser._can_network.value_dicts[expected_name] == expected_dict
예제 #11
0
 def test_parse_attribute_default(self, line, default_value_expected, attr_definition):
     parser = DBCParser()
     parser._can_network.attributes.add_definition(attr_definition)
     parser._parse_line(line)
     attr_def = attr_definition
     assert attr_def.default == default_value_expected
예제 #12
0
 def test_parse_attribute_definition_wrong_type(self):
     parser = DBCParser()
     with pytest.raises(AttributeError):
         parser._parse_line('BA_DEF_ BU_ "BUIntAttribute" INTEGER 0 100;')
예제 #13
0
 def test_parse_bus_config(self, line, expected_speed):
     parser = DBCParser()
     parser._parse_line(line)
     assert parser._can_network.speed == expected_speed
예제 #14
0
 def test_parse_multiline_desc(self):
     parser = DBCParser()
     lines = ['CM_ " Line 1\t\n', 'Line2\n', 'Line3  ";']
     for line in lines:
         parser._parse_line(line)
     assert parser._can_network.description == ' Line 1\t\nLine2\nLine3  '
예제 #15
0
 def test_parse_version(self, line, expected_version):
     parser = DBCParser()
     parser._parse_line(line)
     assert parser._can_network.version == expected_version
예제 #16
0
 def test_parse_signal_wrong_block(self):
     parser = DBCParser()
     node = CANNode('Node0')
     parser._mode = ('NORMAL', None)
     with pytest.raises(RuntimeError):
         parser._parse_line('SG_ DUMMY_LINE')
예제 #17
0
 def test_parse_candb_desc(self, line, expected_desc):
     parser = DBCParser()
     parser._parse_line(line)
     assert parser._can_network.description == expected_desc
예제 #18
0
 def test_parse_node_desc(self, line, node, expected_desc):
     parser = DBCParser()
     parser._can_network.add_node(CANNode(node))
     parser._parse_line(line)
     assert parser._can_network.nodes[node].description == expected_desc