Exemplo n.º 1
0
 def __init__(self, base_path: pathlib.Path):
     super().__init__(base_path,
                      PathsConfig.force_ansible(base_dir=str(base_path)))
     self.mkdir(
         os.path.join(self.paths.base_dir, 'lib', 'ansible', 'modules'))
     self.mkdir(
         os.path.join(self.paths.base_dir, 'lib', 'ansible', 'plugins'))
def test_fragment_loading_fail(tmp_path):
    paths = PathsConfig.force_ansible(str(tmp_path))
    config = ChangelogConfig.default(paths, CollectionDetails(paths))
    p = tmp_path / 'test.yaml'
    p.write_text('test: [')
    with pytest.raises(ChangelogError):
        load_fragments(paths, config, [str(p)])
Exemplo n.º 3
0
def test_is_release_version_ansible_fail(version):
    paths = PathsConfig.force_ansible('.')
    config = ChangelogConfig.default(paths, CollectionDetails(paths))
    config.release_tag_re = r'(v(?:[\d.ab\-]|rc)+)'
    config.pre_release_tag_re = r'(?P<pre_release>(?:[ab]|rc)+\d*)$'
    with pytest.raises(ChangelogError):
        print(is_release_version(config, version))
Exemplo n.º 4
0
 def ansible_base(cls,
                  changelog_data: t.Optional[t.Any] = None
                  ) -> 'ChangelogData':
     paths = PathsConfig.force_ansible('')
     collection_details = CollectionDetails(paths)
     config = ChangelogConfig.default(paths, collection_details)
     return cls(paths,
                config,
                ChangesData(config, '', changelog_data),
                flatmap=False)
Exemplo n.º 5
0
    def ansible(cls, directory: t.Optional[str],
                output_directory: t.Optional[str] = None) -> 'ChangelogData':
        paths = PathsConfig.force_ansible('')

        config = ChangelogConfig.default(paths, CollectionDetails(paths), 'Ansible')
        # TODO: adjust the following lines once Ansible switches to semantic versioning
        config.use_semantic_versioning = False
        config.release_tag_re = r'''(v(?:[\d.ab\-]|rc)+)'''
        config.pre_release_tag_re = r'''(?P<pre_release>(?:[ab]|rc)+\d*)$'''

        changelog_path = ''
        if directory is not None:
            changelog_path = os.path.join(directory, 'changelog.yaml')
        changes = ChangesData(config, changelog_path)
        if output_directory is not None:
            changes.path = os.path.join(output_directory, 'changelog.yaml')
        return cls(paths, config, changes, flatmap=True)
def test_fragments_filename_ignore(tmp_path):
    '''Ensure we don't load files we mean to ignore'''
    paths = PathsConfig.force_ansible(str(tmp_path))
    config = ChangelogConfig.default(paths, CollectionDetails(paths))
    test_filenames = [
        '.test.yaml', 'test.yaml~', 'test.yml~', 'test', 'valid.yml',
        'valid.yaml'
    ]

    for fn in test_filenames:
        p = tmp_path / fn
        p.write_text('minor_changes: ["foo"]')

    loaded = load_fragments(paths, config, [], None, tmp_path)
    assert sorted([x.name for x in loaded]) == ['valid.yaml', 'valid.yml']

    config.ignore_other_fragment_extensions = False
    loaded = load_fragments(paths, config, [], None, tmp_path)
    assert sorted([x.name for x in loaded]) == [
        'test', 'test.yaml~', 'test.yml~', 'valid.yaml', 'valid.yml'
    ]
Exemplo n.º 7
0
def test_collection_details(tmp_path):
    paths = PathsConfig.force_ansible(str(tmp_path))
    details = CollectionDetails(paths)
    with pytest.raises(Exception) as exc:
        details.get_namespace()
    assert str(
        exc.value
    ) == 'Internal error: cannot get collection details for non-collection'
    with pytest.raises(Exception) as exc:
        details.get_name()
    assert str(
        exc.value
    ) == 'Internal error: cannot get collection details for non-collection'
    with pytest.raises(Exception) as exc:
        details.get_version()
    assert str(
        exc.value
    ) == 'Internal error: cannot get collection details for non-collection'
    with pytest.raises(Exception) as exc:
        details.get_flatmap()
    assert str(
        exc.value
    ) == 'Internal error: cannot get collection details for non-collection'

    paths = PathsConfig.force_collection(str(tmp_path))
    details = CollectionDetails(paths)
    with pytest.raises(ChangelogError) as exc:
        details.get_namespace()
    assert 'Cannot find galaxy.yml' in str(exc.value)
    with pytest.raises(ChangelogError) as exc:
        details.get_name()
    assert 'Cannot find galaxy.yml' in str(exc.value)
    with pytest.raises(ChangelogError) as exc:
        details.get_version()
    assert 'Cannot find galaxy.yml' in str(exc.value)
    with pytest.raises(ChangelogError) as exc:
        details.get_flatmap()
    assert 'Cannot find galaxy.yml' in str(exc.value)

    galaxy_path = tmp_path / 'galaxy.yml'
    galaxy_path.write_text('---\na: b\n')
    paths = PathsConfig.force_collection(str(tmp_path))
    details = CollectionDetails(paths)
    with pytest.raises(ChangelogError) as exc:
        details.get_namespace()
    assert 'Cannot find "namespace" field in galaxy.yaml' in str(exc.value)
    with pytest.raises(ChangelogError) as exc:
        details.get_name()
    assert 'Cannot find "name" field in galaxy.yaml' in str(exc.value)
    with pytest.raises(ChangelogError) as exc:
        details.get_version()
    assert 'Cannot find "version" field in galaxy.yaml' in str(exc.value)
    assert details.get_flatmap() is None

    galaxy_path = tmp_path / 'galaxy.yml'
    galaxy_path.write_text('---\nnamespace: 1\nname: 2\nversion: 3\ntype: 4')
    paths = PathsConfig.force_collection(str(tmp_path))
    details = CollectionDetails(paths)
    with pytest.raises(ChangelogError) as exc:
        details.get_namespace()
    assert 'Cannot find "namespace" field in galaxy.yaml' in str(exc.value)
    with pytest.raises(ChangelogError) as exc:
        details.get_name()
    assert 'Cannot find "name" field in galaxy.yaml' in str(exc.value)
    with pytest.raises(ChangelogError) as exc:
        details.get_version()
    assert 'Cannot find "version" field in galaxy.yaml' in str(exc.value)
    assert details.get_flatmap() is False

    galaxy_path = tmp_path / 'galaxy.yml'
    galaxy_path.write_text(
        '---\nnamespace: a\nname: b\nversion: c\ntype: flatmap')
    paths = PathsConfig.force_collection(str(tmp_path))
    details = CollectionDetails(paths)
    assert details.get_namespace() == 'a'
    assert details.get_name() == 'b'
    assert details.get_version() == 'c'
    assert details.get_flatmap() is True

    galaxy_path = tmp_path / 'galaxy.yml'
    galaxy_path.write_text('---\ntype: other')
    paths = PathsConfig.force_collection(str(tmp_path))
    details = CollectionDetails(paths)
    assert details.get_flatmap() is False

    galaxy_path = tmp_path / 'galaxy.yml'
    galaxy_path.write_text(
        '---\nnamespace: a\nname: b\nversion: c\ntype: flatmap')
    paths = PathsConfig.force_collection(str(tmp_path))
    details = CollectionDetails(paths)
    details.namespace = 'test'
    details.name = 'asdf'
    details.version = '1.0.0'
    details.flatmap = False
    assert details.get_namespace() == 'test'
    assert details.get_name() == 'asdf'
    assert details.get_version() == '1.0.0'
    assert details.get_flatmap() is False
Exemplo n.º 8
0
def test_is_release_version_ansible(version, is_release):
    paths = PathsConfig.force_ansible('.')
    config = ChangelogConfig.default(paths, CollectionDetails(paths))
    config.release_tag_re = r'(v(?:[\d.ab\-]|rc)+)'
    config.pre_release_tag_re = r'(?P<pre_release>(?:[ab]|rc)+\d*)$'
    assert is_release_version(config, version) == is_release