def test_bump_files_only(mocker, tmp_commitizen_project): tmp_version_file = tmp_commitizen_project.join("__version__.py") tmp_version_file.write("0.1.0") tmp_commitizen_cfg_file = tmp_commitizen_project.join("pyproject.toml") tmp_commitizen_cfg_file.write( f"{tmp_commitizen_cfg_file.read()}\n" f'version_files = ["{str(tmp_version_file)}"]') create_file_and_commit("feat: new user interface") testargs = ["cz", "bump", "--yes"] mocker.patch.object(sys, "argv", testargs) cli.main() tag_exists = git.tag_exist("0.2.0") assert tag_exists is True create_file_and_commit("feat: another new feature") testargs = ["cz", "bump", "--yes", "--files-only"] mocker.patch.object(sys, "argv", testargs) with pytest.raises(ExpectedExit): cli.main() tag_exists = git.tag_exist("0.3.0") assert tag_exists is False with open(tmp_version_file, "r") as f: assert "0.3.0" in f.read() with open(tmp_commitizen_cfg_file, "r") as f: assert "0.3.0" in f.read()
def test_bump_command(mocker, create_project): with open("./pyproject.toml", "w") as f: f.write("[tool.commitizen]\n" 'version="0.1.0"') cmd.run("git init") # MINOR create_file_and_commit("feat: new file") testargs = ["cz", "bump", "--yes"] mocker.patch.object(sys, "argv", testargs) cli.main() tag_exists = git.tag_exist("0.2.0") assert tag_exists is True # PATCH create_file_and_commit("fix: username exception") testargs = ["cz", "bump"] mocker.patch.object(sys, "argv", testargs) cli.main() tag_exists = git.tag_exist("0.2.1") assert tag_exists is True # PRERELEASE create_file_and_commit("feat: location") testargs = ["cz", "bump", "--prerelease", "alpha"] mocker.patch.object(sys, "argv", testargs) cli.main() tag_exists = git.tag_exist("0.3.0a0") assert tag_exists is True # PRERELEASE BUMP CREATES VERSION WITHOUT PRERELEASE testargs = ["cz", "bump"] mocker.patch.object(sys, "argv", testargs) cli.main() tag_exists = git.tag_exist("0.3.0") assert tag_exists is True # MAJOR create_file_and_commit( "feat: new user interface\n\nBREAKING CHANGE: age is no longer supported" ) testargs = ["cz", "bump"] mocker.patch.object(sys, "argv", testargs) cli.main() tag_exists = git.tag_exist("1.0.0") assert tag_exists is True
def test_bump_command(mocker): # MINOR create_file_and_commit("feat: new file") testargs = ["cz", "bump", "--yes"] mocker.patch.object(sys, "argv", testargs) cli.main() tag_exists = git.tag_exist("0.2.0") assert tag_exists is True # PATCH create_file_and_commit("fix: username exception") testargs = ["cz", "bump"] mocker.patch.object(sys, "argv", testargs) cli.main() tag_exists = git.tag_exist("0.2.1") assert tag_exists is True # PRERELEASE create_file_and_commit("feat: location") testargs = ["cz", "bump", "--prerelease", "alpha"] mocker.patch.object(sys, "argv", testargs) cli.main() tag_exists = git.tag_exist("0.3.0a0") assert tag_exists is True # PRERELEASE BUMP CREATES VERSION WITHOUT PRERELEASE testargs = ["cz", "bump"] mocker.patch.object(sys, "argv", testargs) cli.main() tag_exists = git.tag_exist("0.3.0") assert tag_exists is True # MAJOR create_file_and_commit( "feat: new user interface\n\nBREAKING CHANGE: age is no longer supported" ) testargs = ["cz", "bump"] mocker.patch.object(sys, "argv", testargs) cli.main() tag_exists = git.tag_exist("1.0.0") assert tag_exists is True
def test_bump_patch_increment(commit_msg, mocker): create_file_and_commit(commit_msg) testargs = ["cz", "bump", "--yes"] mocker.patch.object(sys, "argv", testargs) cli.main() tag_exists = git.tag_exist("0.1.1") assert tag_exists is True
def test_bump_minor_increment_annotated(commit_msg, mocker): create_file_and_commit(commit_msg) testargs = ["cz", "bump", "--yes", "--annotated-tag"] mocker.patch.object(sys, "argv", testargs) cli.main() tag_exists = git.tag_exist("0.2.0") cmd_res = cmd.run('git for-each-ref refs/tags --format "%(objecttype):%(refname)"') assert tag_exists is True and "tag:refs/tags/0.2.0\n" in cmd_res.out
def test_bump_command_prelease(mocker): # PRERELEASE create_file_and_commit("feat: location") testargs = ["cz", "bump", "--prerelease", "alpha", "--yes"] mocker.patch.object(sys, "argv", testargs) cli.main() tag_exists = git.tag_exist("0.2.0a0") assert tag_exists is True # PRERELEASE BUMP CREATES VERSION WITHOUT PRERELEASE testargs = ["cz", "bump"] mocker.patch.object(sys, "argv", testargs) cli.main() tag_exists = git.tag_exist("0.2.0") assert tag_exists is True
def test_bump_command_increment_option(commit_msg, increment, expected_tag, mocker): create_file_and_commit(commit_msg) testargs = ["cz", "bump", "--increment", increment, "--yes"] mocker.patch.object(sys, "argv", testargs) cli.main() tag_exists = git.tag_exist(expected_tag) assert tag_exists is True
def test_bump_with_changelog_arg(mocker, changelog_path): create_file_and_commit("feat(user): new file") testargs = ["cz", "bump", "--yes", "--changelog"] mocker.patch.object(sys, "argv", testargs) cli.main() tag_exists = git.tag_exist("0.2.0") assert tag_exists is True with open(changelog_path, "r") as f: out = f.read() assert out.startswith("#") assert "0.2.0" in out
def test_bump_minor_increment_annotated_config_file(commit_msg, mocker, tmp_commitizen_project): tmp_commitizen_cfg_file = tmp_commitizen_project.join("pyproject.toml") tmp_commitizen_cfg_file.write(f"{tmp_commitizen_cfg_file.read()}\n" f"annotated_tag = 1") create_file_and_commit(commit_msg) testargs = ["cz", "bump", "--yes"] mocker.patch.object(sys, "argv", testargs) cli.main() tag_exists = git.tag_exist("0.2.0") cmd_res = cmd.run( 'git for-each-ref refs/tags --format "%(objecttype):%(refname)"') assert tag_exists is True and "tag:refs/tags/0.2.0\n" in cmd_res.out
def test_bump_dry_run(mocker, capsys, tmp_commitizen_project): create_file_and_commit("feat: new file") testargs = ["cz", "bump", "--yes", "--dry-run"] mocker.patch.object(sys, "argv", testargs) with pytest.raises(DryRunExit): cli.main() out, _ = capsys.readouterr() assert "0.2.0" in out tag_exists = git.tag_exist("0.2.0") assert tag_exists is False
def test_bump_with_changelog_to_stdout_arg(mocker, capsys, changelog_path): create_file_and_commit("feat(user): this should appear in stdout") testargs = ["cz", "bump", "--yes", "--changelog-to-stdout"] mocker.patch.object(sys, "argv", testargs) cli.main() out, _ = capsys.readouterr() assert "this should appear in stdout" in out tag_exists = git.tag_exist("0.2.0") assert tag_exists is True with open(changelog_path, "r") as f: out = f.read() assert out.startswith("#") assert "0.2.0" in out
def test_bump_on_git_with_hooks_no_verify_enabled(mocker): cmd.run("mkdir .git/hooks") with open(".git/hooks/pre-commit", "w") as f: f.write("#!/usr/bin/env bash\n" 'echo "0.1.0"') cmd.run("chmod +x .git/hooks/pre-commit") # MINOR create_file_and_commit("feat: new file") testargs = ["cz", "bump", "--yes", "--no-verify"] mocker.patch.object(sys, "argv", testargs) cli.main() tag_exists = git.tag_exist("0.2.0") assert tag_exists is True
def is_initial_tag(self, current_tag_version: str, is_yes: bool = False) -> bool: """Check if reading the whole git tree up to HEAD is needed.""" is_initial = False if not git.tag_exist(current_tag_version): if is_yes: is_initial = True else: out.info(f"Tag {current_tag_version} could not be found. ") out.info( ( "Possible causes:\n" "- version in configuration is not the current version\n" "- tag_format is missing, check them using 'git tag --list'\n" ) ) is_initial = questionary.confirm("Is this the first tag created?").ask() return is_initial
def test_bump_local_version(mocker, tmp_commitizen_project): tmp_version_file = tmp_commitizen_project.join("__version__.py") tmp_version_file.write("4.5.1+0.1.0") tmp_commitizen_cfg_file = tmp_commitizen_project.join("pyproject.toml") tmp_commitizen_cfg_file.write( f"[tool.commitizen]\n" 'version="4.5.1+0.1.0"\n' f'version_files = ["{str(tmp_version_file)}"]') create_file_and_commit("feat: new user interface") testargs = ["cz", "bump", "--yes", "--local-version"] mocker.patch.object(sys, "argv", testargs) cli.main() tag_exists = git.tag_exist("4.5.1+0.2.0") assert tag_exists is True with open(tmp_version_file, "r") as f: assert "4.5.1+0.2.0" in f.read()