def clean(data):
    ''' Check a few things on the yaml file and sanitize the data '''
    if data is None:
        raise RuntimeError(f'There is no data in file/stream.')
    # ensure the known fields are dicts
    # for field in FIELDS:
    #     if field not in data:
    #         continue
    #     if not isinstance(data[field], dict):
    #         raise RuntimeError('The %s field should be a dict, not %s.' %
    #                            (field, data[field].__class__.__name__))

    ensure_valid_license_family(data)
    # clean git spec in source, and turns package/build version into string
    return sanitize(data)
Esempio n. 2
0
def parse(data, config, path=None):
    data = select_lines(data, ns_cfg(config))
    res = yamlize(data)
    # ensure the result is a dict
    if res is None:
        res = {}
    for field in FIELDS:
        if field not in res:
            continue
        # ensure that empty fields are dicts (otherwise selectors can cause invalid fields)
        if not res[field]:
            res[field] = {}
        if not isinstance(res[field], dict):
            raise RuntimeError("The %s field should be a dict, not %s in file %s." %
                               (field, res[field].__class__.__name__, path))

    ensure_valid_fields(res)
    ensure_valid_license_family(res)
    ensure_valid_noarch_value(res)
    return sanitize(res)
Esempio n. 3
0
def parse(data, config, path=None):
    data = select_lines(data, ns_cfg(config))
    res = yamlize(data)
    # ensure the result is a dict
    if res is None:
        res = {}
    for field in FIELDS:
        if field not in res:
            continue
        # ensure that empty fields are dicts (otherwise selectors can cause invalid fields)
        if not res[field]:
            res[field] = {}
        if not isinstance(res[field], dict):
            raise RuntimeError("The %s field should be a dict, not %s in file %s." %
                               (field, res[field].__class__.__name__, path))

    ensure_valid_fields(res)
    ensure_valid_license_family(res)
    ensure_valid_noarch_value(res)
    return sanitize(res)
Esempio n. 4
0
def test_ensure_valid_family(testing_metadata):
    testing_metadata.meta['about']['license_family'] = 'public-domain'
    ensure_valid_license_family(testing_metadata.meta)
    with pytest.raises(RuntimeError):
        testing_metadata.meta['about']['license_family'] = 'local H'
        ensure_valid_license_family(testing_metadata.meta)
Esempio n. 5
0
def test_ensure_valid_family(testing_metadata):
    testing_metadata.meta['about']['license_family'] = 'public-domain'
    ensure_valid_license_family(testing_metadata.meta)
    with pytest.raises(RuntimeError):
        testing_metadata.meta['about']['license_family'] = 'local H'
        ensure_valid_license_family(testing_metadata.meta)