def test_finish_release_with_custom_tag(temp_git_dir, safe_devnull): release_name = "1.0" commit_message = "A commit message" tag = "Version_{}".format(release_name) config = vc.VCSConfiguration( 'git', {'tag': tag}, global_variables={}, special_variables={'new_version': release_name}, commit_message=commit_message) repo = gr.GitRepo(temp_git_dir, config) repo.pre_start_release() repo.start_release() with open(os.path.join(temp_git_dir, "version.txt"), "w") as f: f.writelines([release_name]) subprocess.check_call(["git", "add", "version.txt"], cwd=temp_git_dir, stdout=safe_devnull, stderr=safe_devnull) repo.finish_release() assert tag in repo.get_tags()
def test_init_with_uninitialized_dir(temp_empty_dir, empty_vcs_configuration): with pytest.raises(re.RepositorySystemError) as exc: gr.GitRepo(temp_empty_dir, empty_vcs_configuration) assert str(exc.value) == \ "The current directory {} is not a Git repository".format( temp_empty_dir)
def test_finish_release_with_default_default_annotated_tag_message( temp_git_dir, safe_devnull): release_name = "1.0" commit_message = "A commit message" annotation_message = "Version 1.0" config = vc.VCSConfiguration( 'git', {'annotate_tags': True}, global_variables={}, special_variables={'new_version': release_name}, commit_message=commit_message) repo = gr.GitRepo(temp_git_dir, config) repo.pre_start_release() repo.start_release() with open(os.path.join(temp_git_dir, "version.txt"), "w") as f: f.writelines([release_name]) subprocess.check_call(["git", "add", "version.txt"], cwd=temp_git_dir, stdout=safe_devnull, stderr=safe_devnull) repo.finish_release() p = subprocess.Popen(["git", "show", release_name], cwd=temp_git_dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = p.communicate() assert annotation_message in stdout.decode('utf8')
def test_release_with_explicit_release_branch(temp_git_dir, safe_devnull): release_name = "1.0" commit_message = "A commit message" config = vc.VCSConfiguration( 'git', {'make_release_branch': True}, global_variables={}, special_variables={'new_version': release_name}, commit_message=commit_message) repo = gr.GitRepo(temp_git_dir, config) repo.pre_start_release() repo.start_release() assert release_name in repo.get_branches() with open(os.path.join(temp_git_dir, "version.txt"), "w") as f: f.writelines([release_name]) subprocess.check_call(["git", "add", "version.txt"], cwd=temp_git_dir, stdout=safe_devnull, stderr=safe_devnull) repo.finish_release() p = subprocess.Popen(["git", "log"], cwd=temp_git_dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = p.communicate() assert commit_message in stdout.decode('utf8') assert release_name in repo.get_tags() assert release_name not in repo.get_branches()
def test_get_info(temp_git_dir, develop_vcs_configuration): repo = gr.GitRepo(temp_git_dir, develop_vcs_configuration) assert repo.get_info() == [("Commit message", "Version updated a -> b"), ("Create release branch", 'yes'), ("Release branch", 'b'), ("Annotate tags", 'no'), ("Annotation message", '')]
def test_finish_release_without_changes(temp_git_dir, empty_vcs_configuration): repo = gr.GitRepo(temp_git_dir, empty_vcs_configuration) repo.pre_start_release() repo.start_release() assert 'b' in repo.get_branches() repo.finish_release() assert repo.get_current_branch() == "master" assert 'b' not in repo.get_branches() assert 'b' not in repo.get_tags()
def test_pre_start_release_starting_from_different_branch( temp_git_dir, safe_devnull, empty_vcs_configuration): subprocess.check_call(["git", "checkout", "-b", "new_branch"], cwd=temp_git_dir, stdout=safe_devnull, stderr=safe_devnull) repo = gr.GitRepo(temp_git_dir, empty_vcs_configuration) repo.pre_start_release() assert repo.get_current_branch() == 'master'
def test_pre_start_release_develop( temp_git_dir_develop, develop_vcs_configuration, ): # With develop branch as target_branch repo = gr.GitRepo( temp_git_dir_develop, develop_vcs_configuration, ) repo.pre_start_release() assert repo.get_current_branch() == 'develop'
def test_finish_release_custom_tag_cannot_contain_spaces(temp_git_dir): release_name = "1.0" commit_message = "A commit message" tag = "Version {}".format(release_name) config = vc.VCSConfiguration( 'git', {'tag': tag}, global_variables={}, special_variables={'new_version': release_name}, commit_message=commit_message) with pytest.raises(re.RepositoryConfigurationError): gr.GitRepo(temp_git_dir, config)
def test_pre_start_release_starting_from_different_branch_w_unstaged_changes( temp_git_dir, safe_devnull, empty_vcs_configuration): subprocess.check_call(["git", "checkout", "-b", "new_branch"], cwd=temp_git_dir, stdout=safe_devnull, stderr=safe_devnull) with open(os.path.join(temp_git_dir, "README.md"), "w") as f: f.writelines(["Unstaged lines"]) repo = gr.GitRepo(temp_git_dir, empty_vcs_configuration) repo.pre_start_release() assert repo.get_current_branch() == 'master'
def test_finish_release_develop( temp_git_dir_develop, develop_vcs_configuration, ): repo = gr.GitRepo( temp_git_dir_develop, develop_vcs_configuration, ) repo.pre_start_release() repo.start_release() repo.finish_release() assert repo.get_current_branch() == "develop"
def test_pre_start_release_starting_from_different_branch_w_uncom_changes( temp_git_dir, safe_devnull, empty_vcs_configuration): subprocess.check_call(["git", "checkout", "-b", "new_branch"], cwd=temp_git_dir, stdout=safe_devnull, stderr=safe_devnull) with open(os.path.join(temp_git_dir, "README.md"), "w") as f: f.writelines(["Unstaged lines"]) subprocess.check_call(["git", "add", "README.md"], cwd=temp_git_dir, stdout=safe_devnull, stderr=safe_devnull) repo = gr.GitRepo(temp_git_dir, empty_vcs_configuration) with pytest.raises(re.RepositoryStatusError): repo.pre_start_release()
def test_finish_release_with_annotated_tag(temp_git_dir): release_name = "1.0" commit_message = "A commit message" annotation_message = "An annotation message" config = vc.VCSConfiguration( 'git', {'annotate_tags': True, 'annotation_message': annotation_message}, global_variables={}, special_variables={'new_version': release_name}, commit_message=commit_message ) repo = gr.GitRepo(temp_git_dir, config) repo.pre_start_release() repo.start_release() with open(os.path.join(temp_git_dir, "version.txt"), "w") as f: f.writelines([release_name]) repo.finish_release() p = subprocess.Popen(["git", "log"], cwd=temp_git_dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = p.communicate() assert commit_message in stdout.decode('utf8') p = subprocess.Popen( ["git", "show", release_name], cwd=temp_git_dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE ) stdout, stderr = p.communicate() assert annotation_message in stdout.decode('utf8') assert release_name in repo.get_tags() assert release_name not in repo.get_branches()
def test_init(temp_empty_git_dir, empty_vcs_configuration): repo = gr.GitRepo(temp_empty_git_dir, empty_vcs_configuration) assert repo.working_path == temp_empty_git_dir
def test_get_tags(temp_git_dir, empty_vcs_configuration): repo = gr.GitRepo(temp_git_dir, empty_vcs_configuration) assert repo.get_tags() == ''
def test_get_current_branch(temp_git_dir, empty_vcs_configuration): repo = gr.GitRepo(temp_git_dir, empty_vcs_configuration) assert repo.get_current_branch() == 'master'
def test_tag(temp_git_dir, empty_vcs_configuration): repo = gr.GitRepo(temp_git_dir, empty_vcs_configuration) repo.tag("just_a_tag") assert "just_a_tag" in repo.get_tags()
def test_start_release(temp_git_dir, empty_vcs_configuration): repo = gr.GitRepo(temp_git_dir, empty_vcs_configuration) repo.pre_start_release() repo.start_release() assert repo.get_current_branch() == "b"