Esempio n. 1
0
def test_update_version_module_SHOULD_rise_error_when_no_version_in_module():
    cwd = TESTS_SETUPS_PATH / 'test_update_version_module_SHOULD_rise_error_when_no_project_module'
    if Path(cwd).exists():
        shutil.rmtree(Path(cwd),
                      ignore_errors=False,
                      onerror=_error_remove_readonly)
    Path(cwd).mkdir(parents=True, exist_ok=True)

    config = settings.Config(**_DEFAULT_CONFIG)
    config.is_sample_layout = True

    options = Args()
    options.force = True

    project_name = config.project_name
    project_module_name = utils.get_module_name_with_suffix(project_name)
    file_version_path = Path(cwd) / project_module_name

    prepare.generate_repo(config, cwd, options)
    with open(cwd / project_module_name, 'w'):
        pass

    try:
        release._update_version(file_version_path, '1.2.3-alpha.4', cwd)
    except exceptions.VersionNotFoundError as e:
        if Path(cwd).exists():
            shutil.rmtree(Path(cwd),
                          ignore_errors=False,
                          onerror=_error_remove_readonly)
        assert "__version__ variable not found in the sample_project.py file" in str(
            e)
Esempio n. 2
0
def test_update_version_module_SHOULD_rise_error_when_no_project_module():
    cwd = TESTS_SETUPS_PATH / 'test_update_version_module_SHOULD_rise_error_when_no_project_module'
    if Path(cwd).exists():
        shutil.rmtree(Path(cwd),
                      ignore_errors=False,
                      onerror=_error_remove_readonly)
    Path(cwd).mkdir(parents=True, exist_ok=True)

    config = settings.Config(**_DEFAULT_CONFIG)

    options = Args()
    options.force = True
    config.is_sample_layout = True

    project_name = config.project_name
    project_module_name = utils.get_module_name_with_suffix(project_name)
    file_version_path = Path(cwd) / project_module_name

    prepare.generate_repo(config, cwd, options)
    (cwd / project_module_name).unlink()

    try:
        release._update_version(file_version_path, '1.2.3-alpha.4', cwd)
        assert False, "Expected error did not occured."
    except exceptions.FileNotFoundError as e:
        if Path(cwd).exists():
            shutil.rmtree(Path(cwd),
                          ignore_errors=False,
                          onerror=_error_remove_readonly)
        assert "with a __version__ variable not foud" in str(e)
Esempio n. 3
0
def test_make_release_SHOULD_rise_error_when_no_commit():
    cwd = TESTS_SETUPS_PATH / 'test_make_release_SHOULD_rise_error_when_no_commit'
    if Path(cwd).exists():
        shutil.rmtree(Path(cwd),
                      ignore_errors=False,
                      onerror=_error_remove_readonly)
    Path(cwd).mkdir(parents=True, exist_ok=True)

    options = Args()
    options.force = True

    config = settings.Config(**_DEFAULT_CONFIG)
    prepare.generate_repo(config, cwd, options)

    pygittools.init(cwd)

    try:
        release.make_release(prompt=False, cwd=cwd)
        assert False, "Expected error did not occured."
    except reltools.NoCommitFoundError as e:
        if Path(cwd).exists():
            shutil.rmtree(Path(cwd),
                          ignore_errors=False,
                          onerror=_error_remove_readonly)
        assert "There are no commits in repository" in str(e)
Esempio n. 4
0
def test_update_version_package_SHOULD_update_version_properly():
    cwd = TESTS_SETUPS_PATH / 'test_update_version_package_SHOULD_update_version_properly'
    if Path(cwd).exists():
        shutil.rmtree(Path(cwd),
                      ignore_errors=False,
                      onerror=_error_remove_readonly)
    Path(cwd).mkdir(parents=True, exist_ok=True)

    config = settings.Config(**_DEFAULT_CONFIG)
    config.project_type = settings.ProjectType.PACKAGE.value
    config.is_sample_layout = True

    options = Args()
    options.force = True

    prepare.generate_repo(config, cwd, options)

    release._update_project_version(config, '1.2.3-alpha.4', cwd)

    project_name = config.project_name
    file_version_path = Path(cwd) / project_name / settings.FileName.PYINIT
    with open(file_version_path, 'r') as file:
        content = file.read()
        m = re.search(release._VERSION_REGEX, content)

    if Path(cwd).exists():
        shutil.rmtree(Path(cwd),
                      ignore_errors=False,
                      onerror=_error_remove_readonly)

    assert m.group(0) == "__version__ = '1.2.3-alpha.4'"
Esempio n. 5
0
def test_generate_module_repo_SHOULD_force_properly():
    cwd = TESTS_SETUPS_PATH / 'test_generate_module_repo_SHOULD_force_properly'
    if Path(cwd).exists():
        shutil.rmtree(Path(cwd),
                      ignore_errors=False,
                      onerror=_error_remove_readonly)
    Path(cwd).mkdir(parents=True, exist_ok=True)

    config = settings.Config(**_DEFAULT_CONFIG)
    config.project_type = settings.ProjectType.MODULE.value
    config.is_sample_layout = True

    args = Args
    args.force = True
    args.cloud = True
    args.sample_layout = True

    for dirname in settings.REPO_DIRS_TO_GEN:
        Path(Path(cwd) / dirname).mkdir(exist_ok=True)

    test_content = '<#test_content#>'

    files_paths_to_overwrite = []
    for file in settings.MODULE_REPO_FILES_TO_GEN:
        if settings.PROJECT_NAME_PATH_PLACEHOLDER in str(file.dst):
            dst = Path(
                str(file.dst).replace(settings.PROJECT_NAME_PATH_PLACEHOLDER,
                                      config.project_name))
        else:
            dst = file.dst
        with open(Path(cwd) / dst, 'w') as testfile:
            testfile.write(test_content)

        files_paths_to_overwrite.append(Path(cwd) / dst)

    for file in settings.REPOASSIST_FILES:
        with open(Path(cwd) / file.dst, 'w') as testfile:
            testfile.write(test_content)

        files_paths_to_overwrite.append(Path(cwd) / file.dst)

    prepare.generate_repo(config, cwd, options=args)

    pprint(files_paths_to_overwrite)
    for path in files_paths_to_overwrite:
        with open(path, 'r') as file:
            content = file.readlines()
            if content == test_content:
                assert False, "{} file not overwritten!".format(path)

    if Path(cwd).exists():
        shutil.rmtree(Path(cwd),
                      ignore_errors=False,
                      onerror=_error_remove_readonly)
Esempio n. 6
0
def test_make_release_SHOULD_rise_error_when_no_release_tag():
    cwd = TESTS_SETUPS_PATH / 'test_make_release_SHOULD_rise_error_when_no_release_tag'
    if Path(cwd).exists():
        shutil.rmtree(Path(cwd),
                      ignore_errors=False,
                      onerror=_error_remove_readonly)
    Path(cwd).mkdir(parents=True, exist_ok=True)

    options = Args()
    options.force = True

    config = settings.Config(**_DEFAULT_CONFIG)
    paths = prepare.generate_repo(config, cwd, options)
    pygittools.init(cwd)
    for path in paths:
        pygittools.add(path, cwd)
    pygittools.commit("Initial Commit", cwd)

    try:
        release.make_release(prompt=False, cwd=cwd)
        assert False, "Expected error did not occured."
    except exceptions.ReleaseMetadataError as e:
        if Path(cwd).exists():
            shutil.rmtree(Path(cwd),
                          ignore_errors=False,
                          onerror=_error_remove_readonly)
        assert "Retrieving release tag error" in str(e)
Esempio n. 7
0
def test_generate_module_repo_SHOULD_generate_makefile_with_cloud_properly():
    cwd = TESTS_SETUPS_PATH / 'test_generate_module_repo_SHOULD_generate_makefile_with_cloud_properly'
    if Path(cwd).exists():
        shutil.rmtree(Path(cwd))
    Path(cwd).mkdir(parents=True, exist_ok=True)

    config = settings.Config(**_DEFAULT_CONFIG)
    config.project_type = settings.ProjectType.MODULE.value

    options = Args
    options.force = True
    options.cloud = True

    paths = prepare.generate_repo(config, cwd, options=options)
    paths = {path.relative_to(cwd).as_posix() for path in paths}

    with open(Path(cwd) / settings.FileName.MAKEFILE) as file:
        makefile_content = file.read()

    if Path(cwd).exists():
        shutil.rmtree(Path(cwd),
                      ignore_errors=False,
                      onerror=_error_remove_readonly)

    assert "make upload" in makefile_content
Esempio n. 8
0
def test_generate_package_repo_SHOULD_add_genereated_files_to_repo_tree_when_choosen(
):
    cwd = TESTS_SETUPS_PATH / 'test_generate_package_repo_SHOULD_add_genereated_files_to_repo_tree_when_choosen'
    if Path(cwd).exists():
        shutil.rmtree(Path(cwd),
                      ignore_errors=False,
                      onerror=_error_remove_readonly)
    Path(cwd).mkdir(parents=True, exist_ok=True)

    config = settings.Config(**_DEFAULT_CONFIG)
    config.project_type = settings.ProjectType.PACKAGE.value
    config.is_sample_layout = True
    config.is_git = True

    args = Args
    args.force = False
    args.cloud = True

    paths = prepare.generate_repo(config, cwd, options=args)
    paths = {path.relative_to(cwd).as_posix() for path in paths \
             if path.is_file() and settings.FileName.CLOUD_CREDENTIALS not in path.__str__()}
    pprint(paths)

    pygittools.commit("Initial Commit", cwd)
    repo_paths = utils.get_git_repo_tree(cwd)
    repo_paths = {path.relative_to(cwd).as_posix() for path in repo_paths}
    pprint(repo_paths)

    assert paths == repo_paths

    if Path(cwd).exists():
        shutil.rmtree(Path(cwd),
                      ignore_errors=False,
                      onerror=_error_remove_readonly)
Esempio n. 9
0
def test_make_release_SHOULD_regenerate_package_properly_on_the_same_commit():
    cwd = TESTS_SETUPS_PATH / 'test_make_release_SHOULD_regenerate_package_properly_on_the_same_commit'
    if Path(cwd).exists():
        shutil.rmtree(Path(cwd),
                      ignore_errors=False,
                      onerror=_error_remove_readonly)
    Path(cwd).mkdir(parents=True, exist_ok=True)

    config = settings.Config(**_DEFAULT_CONFIG)
    config.project_type = settings.ProjectType.PACKAGE.value
    config.is_sample_layout = True

    options = Args()
    options.force = True
    options.cloud = True

    release_data = ReleaseData()
    release_data.tag = '0.2.0'
    release_data.msg = 'Next Release'

    paths = prepare.generate_repo(config, cwd, options)

    pygittools.init(cwd)
    for path in paths:
        try:
            pygittools.add(path, cwd)
        except pygittools.PygittoolsError:
            pass
    pygittools.commit("Initial Commit", cwd)
    pygittools.set_tag('0.1.0', "First Release", cwd)

    time.sleep(1)  # Sleep for different release time than previous

    archive_name = release.make_release(
        action=release.ReleaseAction.MAKE_RELEASE,
        prompt=False,
        push=False,
        release_data=release_data,
        cwd=cwd)

    assert not pygittools.are_uncommited_changes(cwd)

    archive_name_regenerated = release.make_release(
        action=release.ReleaseAction.REGENERATE,
        prompt=False,
        push=False,
        release_data=None,
        cwd=cwd)

    assert archive_name == archive_name_regenerated

    if Path(cwd).exists():
        shutil.rmtree(Path(cwd),
                      ignore_errors=False,
                      onerror=_error_remove_readonly)
Esempio n. 10
0
def test_generate_module_repo_SHOULD_not_generate_cloud_credentials_without_cloud(
):
    cwd = TESTS_SETUPS_PATH / 'test_generate_module_repo_SHOULD_not_generate_cloud_credentials_without_cloud'
    if Path(cwd).exists():
        shutil.rmtree(Path(cwd))
    Path(cwd).mkdir(parents=True, exist_ok=True)

    config = settings.Config(**_DEFAULT_CONFIG)
    config.project_type = settings.ProjectType.MODULE.value

    options = Args
    options.force = True
    options.cloud = False

    paths = prepare.generate_repo(config, cwd, options=options)
    paths = {path.relative_to(cwd).as_posix() for path in paths}

    if Path(cwd).exists():
        shutil.rmtree(Path(cwd),
                      ignore_errors=False,
                      onerror=_error_remove_readonly)

    assert settings.FileName.CLOUD_CREDENTIALS not in paths
Esempio n. 11
0
def test_make_release_SHOULD_release_module_properly():
    cwd = TESTS_SETUPS_PATH / 'test_make_release_SHOULD_release_module_properly'
    if Path(cwd).exists():
        shutil.rmtree(Path(cwd),
                      ignore_errors=False,
                      onerror=_error_remove_readonly)
    Path(cwd).mkdir(parents=True, exist_ok=True)

    config = settings.Config(**_DEFAULT_CONFIG)
    config.project_type = settings.ProjectType.MODULE.value
    config.is_sample_layout = True

    options = Args()
    options.force = True
    options.cloud = True

    release_data = ReleaseData()
    release_data.tag = '0.2.0'
    release_data.msg = 'Next Release'

    paths = prepare.generate_repo(config, cwd, options)
    expected_paths = {path.relative_to(cwd).as_posix() for path in paths}
    expected_paths.remove(
        settings.DirName.DOCS)  # TODO: think about doc in feature
    expected_paths.remove(settings.FileName.CLOUD_CREDENTIALS)
    expected_paths.remove(settings.FileName.GITIGNORE)
    expected_paths = expected_paths | {
        settings.FileName.AUTHORS, settings.FileName.CHANGELOG, 'PKG-INFO',
        '{}.egg-info'.format(config.project_name),
        '{}.egg-info/PKG-INFO'.format(config.project_name),
        '{}.egg-info/SOURCES.txt'.format(config.project_name),
        '{}.egg-info/dependency_links.txt'.format(config.project_name),
        '{}.egg-info/not-zip-safe'.format(config.project_name),
        '{}.egg-info/pbr.json'.format(config.project_name),
        '{}.egg-info/top_level.txt'.format(config.project_name),
        '{}.egg-info/entry_points.txt'.format(config.project_name), '.'
    }
    pprint(expected_paths)

    pygittools.init(cwd)
    for path in paths:
        try:
            pygittools.add(path, cwd)
        except pygittools.PygittoolsError:
            pass
    pygittools.commit("Initial Commit", cwd)
    pygittools.set_tag('0.1.0', "First Release", cwd)

    time.sleep(1)  # Sleep for different release time than previous

    archive_name = release.make_release(
        action=release.ReleaseAction.MAKE_RELEASE,
        prompt=False,
        push=False,
        release_data=release_data,
        cwd=cwd)
    unpack_dir = Path(cwd) / Path(archive_name).stem

    if (unpack_dir.exists()):
        shutil.rmtree(unpack_dir)
    Path.mkdir(unpack_dir, parents=True)
    shutil.unpack_archive(archive_name, extract_dir=unpack_dir, format='gztar')

    unpack_paths = set()
    for path in Path(unpack_dir).glob('**/*'):
        unpack_paths.add(
            Path(path).relative_to(
                Path(cwd) / Path(archive_name).stem /
                Path(Path(archive_name).stem).stem).as_posix())
    pprint(unpack_paths)

    shutil.rmtree(unpack_dir)

    last_release_tag = pygittools.get_latest_tag(cwd)
    last_release_msg = pygittools.get_latest_tag_msg(cwd)

    assert unpack_paths == expected_paths
    assert release_data.tag == last_release_tag
    assert release_data.msg == last_release_msg
    assert not pygittools.are_uncommited_changes(cwd)

    if Path(cwd).exists():
        shutil.rmtree(Path(cwd),
                      ignore_errors=False,
                      onerror=_error_remove_readonly)
Esempio n. 12
0
def test_generate_module_repo_SHOULD_generate_repo_tree_properly_WHEN_no_sample(
):
    cwd = TESTS_SETUPS_PATH / 'test_generate_module_repo_SHOULD_generate_repo_tree_properly_WHEN_no_sample'
    if Path(cwd).exists():
        shutil.rmtree(Path(cwd))
    Path(cwd).mkdir(parents=True, exist_ok=True)

    expected_paths = {
        'docs',
        'tests',
        'README.md',
        '.gitignore',
        'TODO.md',
        'conftest.py',
        'tests/__init__.py',
        'requirements.txt',
        'requirements-dev.txt',
        'Makefile',
        'LICENSE',
        'tox.ini',
        'setup.cfg',
        'setup.py',
        'repoassist',
        'repoassist/templates',
        'repoassist/__init__.py',
        'repoassist/__main__.py',
        'repoassist/cli.py',
        'repoassist/colreqs.py',
        'repoassist/settings.py',
        'repoassist/logger.py',
        'repoassist/release.py',
        'repoassist/pygittools.py',
        'repoassist/utils.py',
        'repoassist/meldformat.py',
        'repoassist/wizard.py',
        'repoassist/sicloudman.py',
        'repoassist/exceptions.py',
        'repoassist/prepare.py',
        'repoassist/reltools.py',
        'repoassist/clean.py',
        'repoassist/templates/CHANGELOG_generated.md.j2',
        'repoassist/templates/CHANGELOG_prepared.md.j2',
        'repoassist/templates/AUTHORS_prepared.md.j2',
        'repoassist/templates/AUTHORS_generated.md.j2',
        'repoassist/templates/requirements-dev.txt.j2',
        'repoassist/README.md',
        'cloud_credentials.txt',
    }

    config = settings.Config(**_DEFAULT_CONFIG)
    config.project_type = settings.ProjectType.MODULE.value
    config.is_sample_layout = False

    args = Args
    args.force = False
    args.cloud = True

    paths = prepare.generate_repo(config, cwd, options=args)
    paths = {path.relative_to(cwd).as_posix() for path in paths}
    pprint(paths)

    if Path(cwd).exists():
        shutil.rmtree(Path(cwd),
                      ignore_errors=False,
                      onerror=_error_remove_readonly)

    assert paths == expected_paths