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)
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)
def test_update_repoassist_SHOULD_add_new_files_to_repo_tree_and_remove_old_from_tree_and_from_drive( cwd): config, options, repoassit_path, _ = update_repoassist_setup(cwd) pygittools.init(cwd) repoassist_paths_expected = prepare._generate_repoasist( config, cwd, options).paths paths_to_git_add = list(repoassist_paths_expected) paths_to_git_add = [ path for path in paths_to_git_add if (settings.FileName.MAIN not in path.__str__() and settings.FileName.CLI not in path.__str__()) ] (repoassit_path / settings.FileName.MAIN).unlink() (repoassit_path / settings.FileName.CLI).unlink() (repoassit_path / 'dummy_file.txt').touch() (repoassit_path / 'dummy_file2.txt').touch() paths_to_git_add.append(repoassit_path / 'dummy_file.txt') for path in paths_to_git_add: pygittools.add(path, cwd) pygittools.commit('First Commit', cwd) repo_tree = utils.get_git_repo_tree(cwd) pprint(repo_tree) assert set(repo_tree) != set(repoassist_paths_expected) new_files, removed_files = prepare.update_repoassist(config, cwd, add_to_tree=True, options=options) pprint(new_files) pygittools.commit('Second Commit', cwd) paths_to_git_add.remove(repoassit_path / 'dummy_file.txt') assert repoassit_path / settings.FileName.MAIN in new_files assert repoassit_path / settings.FileName.CLI in new_files assert repoassit_path / 'dummy_file.txt' in removed_files assert repoassit_path / 'dummy_file2.txt' in removed_files assert new_files.__len__() == 2 assert removed_files.__len__() == 2 repoassist_files = { item for item in repoassit_path.rglob('*') if item.is_file() } assert set(repoassist_files) == set(repoassist_paths_expected) repo_tree = utils.get_git_repo_tree(cwd) pprint(repo_tree) assert set(repo_tree) == set(repoassist_paths_expected)
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)
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)