示例#1
0
def test_raises_exception_if_file_not_exists():
    not_existing_file = 'non-existing.yaml'

    provider = ConfigProvider()

    with pytest.raises(FileNotFoundError):
        provider.load(not_existing_file)
示例#2
0
def test_raises_value_error_if_not_yaml():
    yaml = 'test/config.json'

    provider = ConfigProvider()

    with pytest.raises(ValueError):
        provider.load(yaml)
示例#3
0
def test_provides_config_from_string():
    yaml = """
    SingleValue: "text:/PathToElement"
    """

    provider = ConfigProvider()
    config = provider.parse(yaml)

    assert isinstance(config, dict)
    assert config['SingleValue'] == 'text:/PathToElement'
示例#4
0
def load_config(file):
    logger = logging.getLogger()
    logger.info(f'START PROCESS - loading configuration \'{str(file)}\'')

    try:
        config_provider = ConfigProvider()
        config = config_provider.load(str(file))
    except Exception as e:
        handle_exception(f'reading configuration file \'{str(file)}\'', e)
        sys.exit(-1)

    logger.info('END PROCESS - successfully finished loading configuration')
    return config
示例#5
0
def test_provides_config_from_file():
    yaml = 'arxml_data_extractor/tests/test_config.yaml'

    provider = ConfigProvider()
    config = provider.load(yaml)

    assert isinstance(config, dict)
    assert len(config) == 1
    root = config['RootObject']
    assert isinstance(root, dict)
    assert root['_xpath'] == './/*'
    assert root['SingleValue'] == 'text:Value'
    object_value = root['ObjectValue']
    assert object_value['_xpath'] == './/Object'
    assert object_value['Name'] == 'text:Name'
    assert object_value['Data'] == 'text>int:Data'
def test_extracting_nested_objects():
    yaml = """
    'PDUs':
        '_xpath': './/I-SIGNAL-I-PDU'
        'Name': 'text:SHORT-NAME'
        'Length': 'text>int:LENGTH'
        'Cyclic Timing': 'text>float:.//TRANSMISSION-MODE-TRUE-TIMING/CYCLIC-TIMING/TIME-PERIOD/VALUE'
        'Signal Mappings':
            '_xpath': './/I-SIGNAL-TO-I-PDU-MAPPING'
            'Signal': 'SHORT-NAME'
            'Start Position': 'text>int:START-POSITION'
            'ISignal':
                '_xref': 'I-SIGNAL-REF'
                'Init Value': 'text>int:.//VALUE'
                'Length': 'text>int:LENGTH'
    """
    config_provider = ConfigProvider()
    config = config_provider.parse(yaml)

    query_builder = QueryBuilder()
    queries = query_builder.build(config)

    query_handler = QueryHandler()
    data = query_handler.handle_queries(arxml, queries)

    assert isinstance(data, dict)
    assert len(data['PDUs']) == 2
    assert data['PDUs'][0]['Name'] == 'TxMessage'
    assert data['PDUs'][0]['Length'] == 5
    assert data['PDUs'][0]['Cyclic Timing'] == 0.1
    assert data['PDUs'][0]['Signal Mappings']['Signal'] == 'Signal1'
    assert data['PDUs'][0]['Signal Mappings']['Start Position'] == 0
    assert data['PDUs'][0]['Signal Mappings']['ISignal']['Init Value'] == 128
    assert data['PDUs'][0]['Signal Mappings']['ISignal']['Length'] == 5

    assert data['PDUs'][1]['Name'] == 'RxMessage'
    assert data['PDUs'][1]['Length'] == 2
    assert data['PDUs'][1]['Cyclic Timing'] == 0.1
    assert data['PDUs'][1]['Signal Mappings'][0]['Signal'] == 'Signal2'
    assert data['PDUs'][1]['Signal Mappings'][0]['Start Position'] == 0
    assert data['PDUs'][1]['Signal Mappings'][0]['ISignal']['Init Value'] == 0
    assert data['PDUs'][1]['Signal Mappings'][0]['ISignal']['Length'] == 1
    assert data['PDUs'][1]['Signal Mappings'][1]['Signal'] == 'Signal3'
    assert data['PDUs'][1]['Signal Mappings'][1]['Start Position'] == 1
    assert data['PDUs'][1]['Signal Mappings'][1]['ISignal']['Init Value'] == 0
    assert data['PDUs'][1]['Signal Mappings'][1]['ISignal']['Length'] == 1
def test_extracting_simple_object():
    yaml = """
    'CAN Cluster':
        '_ref': '/Cluster/CAN'
        'Name': 'SHORT-NAME'
        'Baudrate': 'text>int:CAN-CLUSTER-VARIANTS/CAN-CLUSTER-CONDITIONAL/BAUDRATE'
        'Long Name': 'text:LONG-NAME/L-4'
        'Language': '@L:LONG-NAME/L-4'
    """

    config_provider = ConfigProvider()
    config = config_provider.parse(yaml)

    query_builder = QueryBuilder()
    queries = query_builder.build(config)

    query_handler = QueryHandler()
    data = query_handler.handle_queries(arxml, queries)

    assert isinstance(data, dict)
    assert data['CAN Cluster']['Name'] == 'CAN'
    assert data['CAN Cluster']['Baudrate'] == 500000
    assert data['CAN Cluster']['Long Name'] == 'CAN Channel 1'
    assert data['CAN Cluster']['Language'] == 'FOR-ALL'