Beispiel #1
0
def test_authors_append(col_info):
    # let authors go to the defualt
    del col_info['authors']
    res = CollectionInfo(**col_info)
    # log.debug('res %s res.authors: %s', res, res.authors)

    # append to the first objects authors.
    # This should not change the default authors for new
    # CollectionInfo()'s
    res.authors.append('Faux Author')
    log.debug('res %s res.authors: %s', res, res.authors)

    new_data = col_info.copy()

    # No authors provided, should default to []
    res2 = CollectionInfo(**new_data)

    res.authors.append('OnlyAuthoredResNotRes2')

    log.debug('res %s res.authors: %s', res, res.authors)
    log.debug('res2 %s res2.authors: %s', res2, res2.authors)

    # Based on https://www.attrs.org/en/stable/init.html#defaults info about defaults
    # These should not be the same value here
    assert res != res2
    assert res.authors != res2.authors
    assert res2.authors == []
    assert res.authors == ['Faux Author', 'OnlyAuthoredResNotRes2']
    assert 'OnlyAuthoredResNotRes2' not in res2.authors
def test_authors_append():
    test_data = {
        'name': 'foo.foo',
        # let authors go to the defualt
        # 'authors': ['chouseknecht'],
        'license': 'GPL-3.0-or-later',
        'version': '1.0.0',
        'description': 'unit testing thing',
    }
    res = CollectionInfo(**test_data)
    # log.debug('res %s res.authors: %s', res, res.authors)

    # append to the first objects authors.
    # This should not change the default authors for new
    # CollectionInfo()'s
    res.authors.append('Faux Author')
    log.debug('res %s res.authors: %s', res, res.authors)

    new_data = test_data.copy()

    # No authors provided, should default to []
    res2 = CollectionInfo(**new_data)

    res.authors.append('OnlyAuthoredResNotRes2')

    log.debug('res %s res.authors: %s', res, res.authors)
    log.debug('res2 %s res2.authors: %s', res2, res2.authors)

    # Based on https://www.attrs.org/en/stable/init.html#defaults info about defaults
    # These should not be the same value here
    assert res != res2
    assert res.authors != res2.authors
    assert res2.authors == []
    assert res.authors == ['Faux Author', 'OnlyAuthoredResNotRes2']
    assert 'OnlyAuthoredResNotRes2' not in res2.authors
def test_minimal():
    test_data = {
        'name': 'foo.foo',
        'license': 'GPL-3.0-or-later',
        'version': '1.0.0',
        'description': 'unit testing thing',
    }
    res = CollectionInfo(**test_data)

    res.authors.append('Faux Author')
    res.keywords.append('somekeyword')
    res.dependencies.append(('some_dep', 'stuff'))

    log.debug('res %s res.authors: %s', res, res.authors)

    new_data = test_data.copy()
    res2 = CollectionInfo(**new_data)

    log.debug('res %s res.authors: %s', res, res.authors)
    log.debug('res2 %s res2.authors: %s', res2, res2.authors)

    assert res != res2
    assert res2.authors == []
    assert res2.keywords == []
    assert res2.dependencies == []
Beispiel #4
0
def _collection_info(namespace=None, name=None, version=None, author=None):
    namespace = namespace or 'some_namespace'
    name = name or 'some_name'
    version = version or '1.2.3'
    author = author or 'Rex Chapman'

    return CollectionInfo(namespace, name, version, author=author)
def test_name_has_hypen_error(col_info):
    col_info['name'] = 'foo-bar'

    with pytest.raises(ValueError,
                       match=NON_ALPHA_ERROR_PAT) as exc:
        CollectionInfo(**col_info)
    assert 'foo-bar' in str(exc)
Beispiel #6
0
def test_deps_is_none(col_info):
    col_info['dependencies'] = None
    res = CollectionInfo(**col_info)

    log.debug('res: %s', res)

    assert res.dependencies == {}
Beispiel #7
0
def test_license_with_contradicting_license_file(col_info):
    col_info['license_file'] = 'MY_LICENSE.txt'

    res = CollectionInfo(**col_info)

    assert res.license_file == 'MY_LICENSE.txt'
    assert res.license == ['GPL-3.0-or-later']
Beispiel #8
0
def load(data_or_file_object):

    # FIXME: This file is json now, so could use the regular json.load()
    #        (this works as well since json is subset of yaml...)
    log.debug('loading collection info from %s', pf(data_or_file_object))

    data_dict = yaml.safe_load(data_or_file_object)

    # log.debug('data: %s', pf(data_dict))
    # log.debug('data_dict: %s', data_dict)

    col_info = CollectionInfo(**data_dict['collection_info'])

    file_manifest_file = None
    if data_dict.get('file_manifest_file', None):
        file_manifest_file = CollectionArtifactFile(
            **data_dict['file_manifest_file'])

    instance = CollectionArtifactManifest(
        collection_info=col_info, file_manifest_file=file_manifest_file)

    log.debug('%s instance from_kwargs', type(instance))

    log.debug('collection_artifact_manifest: %r', instance)

    return instance
Beispiel #9
0
def test_name_parse_error_name_leading_hyphen(col_info):
    col_info['name'] = '-foo'

    # For the case of a leading '-', the 'no dashes' check raises error first
    with pytest.raises(ValueError, match=NON_ALPHA_ERROR_PAT) as exc:
        CollectionInfo(**col_info)
    assert '-foo' in str(exc)
Beispiel #10
0
def test_name_parse_error_other_chars_namespace(col_info):
    col_info['namespace'] = 'foo@blip'

    # ValueError: Invalid collection metadata. Expecting 'name' and 'namespace' to contain only alphanumeric characters
    # or '_' only but 'foo@blip' contains others"
    with pytest.raises(ValueError, match=NON_ALPHA_ERROR_PAT) as exc:
        CollectionInfo(**col_info)
    assert 'foo@blip' in str(exc)
Beispiel #11
0
def test_deps_is_list(col_info):
    col_info['dependencies'] = ['blip', {'sub_dict': 'these_deps_are_wrong'}]
    error_re = r"Invalid collection metadata. Expecting 'dependencies' to be a dict"

    with pytest.raises(ValueError, match=error_re) as exc:
        CollectionInfo(**col_info)

    log.debug(str(exc))
Beispiel #12
0
def test_name_parse_error_name_leading_underscore(col_info):
    col_info['name'] = '_foo'

    # ValueError: Invalid collection metadata. Expecting 'name' and 'namespace' to not start with '_' but '_foo' did
    error_re = r"Invalid collection metadata. Expecting 'name' and 'namespace' to not start with '_' but '_foo' did"
    with pytest.raises(ValueError, match=error_re) as exc:
        CollectionInfo(**col_info)
    assert '_foo' in str(exc)
Beispiel #13
0
def test_license_with_valid_license_file(col_info):
    # license=None will be converted to license=[]
    col_info['license'] = None
    col_info['license_file'] = 'MY_LICENSE.txt'

    res = CollectionInfo(**col_info)

    assert res.license_file == 'MY_LICENSE.txt'
    assert res.license == []
Beispiel #14
0
def test_license_error(col_info):
    col_info['license'] = 'GPLv2'

    with pytest.raises(ValueError) as exc:
        CollectionInfo(**col_info)

    log.debug(str(exc))

    assert 'license' in str(exc)
Beispiel #15
0
def test_license_empty_list(col_info):
    col_info['license'] = []

    error_re = r"Valid values for 'license' or 'license_file' are required. But 'license' \(.*\) and 'license_file' \(.*\) were invalid."

    with pytest.raises(ValueError, match=error_re) as exc:
        CollectionInfo(**col_info)

    log.debug('exc: %s', str(exc))
Beispiel #16
0
def test_invalid_names(col_info, invalid_name):
    col_info['name'] = invalid_name

    log.debug('invalid_name: %s', invalid_name)

    with pytest.raises(ValueError) as exc:
        CollectionInfo(**col_info)

    log.debug('exc: %s', str(exc))
Beispiel #17
0
def test_name_parse_error_dots_in_name(col_info):
    col_info['name'] = 'foo.bar'

    # CollectionInfo(**col_info)
    # ValueError: Invalid collection metadata. Expecting 'name' and 'namespace' to not include any '.' but 'foo.bar' has a '.'
    error_re = r"Invalid collection metadata. Expecting 'name' and 'namespace' to not include any '\.' but 'foo\.bar' has a '\.'"
    with pytest.raises(ValueError, match=error_re) as exc:
        CollectionInfo(**col_info)
    assert 'name' in str(exc)
Beispiel #18
0
def test_valid_names(col_info, valid_name):
    col_info['name'] = valid_name

    log.debug('valid_name: %s', valid_name)

    res = CollectionInfo(**col_info)

    assert isinstance(res, CollectionInfo)
    assert res.name == valid_name
def test_namespace_property():
    test_data = {
        'name': 'foo.foo',
        'authors': ['chouseknecht'],
        'license': 'GPL-3.0-or-later',
        'version': '1.0.0',
        'description': 'unit testing thing',
    }
    info = CollectionInfo(**test_data)
    assert info.namespace == 'foo'
Beispiel #20
0
def test_tags_non_alpha_error(col_info):
    bad_tag = 'bad-tag!'
    col_info['tags'] = ['goodtag', bad_tag]

    # ValueError: Invalid collection metadata. Expecting tags to contain alphanumeric characters only, instead found 'bad-tag!'.
    error_re = r"Invalid collection metadata. Expecting tags to contain lowercase alphanumeric characters only, instead found '.*'"

    with pytest.raises(ValueError, match=error_re) as exc:
        CollectionInfo(**col_info)
    assert bad_tag in str(exc)
Beispiel #21
0
def test_tags_not_a_list_error(col_info):
    not_a_list = 'notataglist'
    col_info['tags'] = not_a_list

    # ValueError: Invalid collection metadata. Expecting 'tags' to be a list
    error_re = r"Invalid collection metadata. Expecting 'tags' to be a list"

    with pytest.raises(ValueError, match=error_re) as exc:
        CollectionInfo(**col_info)
    assert 'tags' in str(exc)
Beispiel #22
0
def test_name_invalid_leading_number(col_info, invalid_name_leading_number):
    col_info['name'] = invalid_name_leading_number
    col_info['namespace'] = invalid_name_leading_number

    log.debug('invalid_name_leading_number: %s', invalid_name_leading_number)

    error_re = r"Invalid collection metadata. Expecting 'name' and 'namespace' to not start with a number but '%s' did" % invalid_name_leading_number
    with pytest.raises(ValueError, match=error_re) as exc:
        CollectionInfo(**col_info)
    assert invalid_name_leading_number in str(exc)
Beispiel #23
0
def test_license_valid_and_none_list(col_info):
    col_info['license'] = ['GPL-3.0-or-later', None]

    error_re = r"Invalid collection metadata. Expecting 'license' to be a list of valid SPDX license identifiers, "
    "instead found invalid license identifiers: '.*' in 'license' value .*."

    with pytest.raises(ValueError, match=error_re) as exc:
        CollectionInfo(**col_info)

    log.debug('exc: %s', str(exc))
def test_required_error():
    test_data = {
        'authors': ['chouseknecht'],
        'license': 'GPL-3.0-or-later',
        'version': '0.0.1',
        'description': 'unit testing thing'
    }
    with pytest.raises(ValueError) as exc:
        CollectionInfo(**test_data)
    assert 'name' in str(exc) in str(exc)
Beispiel #25
0
def _collection_info(namespace=None, name=None, version=None, authors=None):
    # name = name or 'some_namespace.some_name'
    namespace = namespace or 'some_namespace'
    name = name or 'some_name'
    version = version or '1.2.3'
    authors = authors or ['Rex Chapman']
    description = "Unit testing thing"
    test_license = 'GPL-3.0-or-later'

    return CollectionInfo(namespace=namespace, name=name, version=version, authors=authors, description=description,
                          license=test_license)
Beispiel #26
0
def test_minimal(col_info):
    del col_info['authors']
    res = CollectionInfo(**col_info)

    res.authors.append('Faux Author')
    res.tags.append('sometag')
    res.dependencies.update({'some_dep': '1.1.0', 'stuff': '2.2.2'})

    log.debug('res %s res.authors: %s', res, res.authors)

    new_data = col_info.copy()
    res2 = CollectionInfo(**new_data)

    log.debug('res %s res.authors: %s', res, res.authors)
    log.debug('res2 %s res2.authors: %s', res2, res2.authors)

    assert res != res2
    assert res2.authors == []
    assert res2.tags == []
    assert res2.dependencies == {}
Beispiel #27
0
def test_name_invalid_uppercase(col_info, invalid_name_uppercase):
    col_info['name'] = invalid_name_uppercase
    col_info['namespace'] = invalid_name_uppercase

    log.debug('invalid_name_uppercase: %s', invalid_name_uppercase)

    with pytest.raises(ValueError, match=NON_ALPHA_ERROR_PAT) as exc:
        CollectionInfo(**col_info)

    log.debug('exc: %s', str(exc))
    assert invalid_name_uppercase in str(exc)
Beispiel #28
0
def _namespace_invalid_name_non_alphanumeric(col_info,
                                             invalid_name_non_alphanumeric):

    log.debug('invalid_name_non_alphanumeric: %s',
              invalid_name_non_alphanumeric)

    with pytest.raises(ValueError, match=NON_ALPHA_ERROR_PAT) as exc:
        CollectionInfo(**col_info)

    log.debug('exc: %s', str(exc))
    assert invalid_name_non_alphanumeric in str(exc)
def test_semantic_version_error():
    test_data = {
        'name': 'foo.foo',
        'authors': ['chouseknecht'],
        'license': 'GPL-3.0-or-later',
        'version': 'foo',
        'description': 'unit testing thing',
    }
    with pytest.raises(ValueError) as exc:
        CollectionInfo(**test_data)
    assert 'version' in str(exc)
def test_license_error():
    test_data = {
        'name': 'foo.foo',
        'authors': ['chouseknecht'],
        'license': 'GPLv2',
        'version': '0.0.1',
        'description': 'unit testing thing',
    }
    with pytest.raises(ValueError) as exc:
        CollectionInfo(**test_data)
    assert 'license' in str(exc)