Skip to content

Commit

Permalink
test(commands/bump): add test case from bump hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
Lee-W committed Feb 8, 2023
1 parent 5797f8a commit 2759f35
Showing 1 changed file with 57 additions and 2 deletions.
59 changes: 57 additions & 2 deletions tests/commands/test_bump_command.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import inspect
import sys
from typing import Tuple
from unittest.mock import MagicMock
from unittest.mock import MagicMock, call

import pytest
from pytest_mock import MockFixture

import commitizen.commands.bump as bump
from commitizen import cli, cmd, git
from commitizen import cli, cmd, git, hooks
from commitizen.exceptions import (
BumpTagFailedError,
CommitizenException,
Expand Down Expand Up @@ -759,3 +759,58 @@ def test_bump_manual_version_disallows_major_version_zero(mocker):
"--major-version-zero cannot be combined with MANUAL_VERSION"
)
assert expected_error_message in str(excinfo.value)


@pytest.mark.parametrize("commit_msg", ("feat: new file", "feat(user): new file"))
def test_bump_with_pre_bump_hooks(
commit_msg, mocker: MockFixture, tmp_commitizen_project
):
pre_bump_hook = "scripts/pre_bump_hook.sh"
post_bump_hook = "scripts/post_bump_hook.sh"

tmp_commitizen_cfg_file = tmp_commitizen_project.join("pyproject.toml")
tmp_commitizen_cfg_file.write(
f"{tmp_commitizen_cfg_file.read()}\n"
f'pre_bump_hooks = ["{pre_bump_hook}"]\n'
f'post_bump_hooks = ["{post_bump_hook}"]\n'
)

run_mock = mocker.Mock()
mocker.patch.object(hooks, "run", run_mock)

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")
assert tag_exists is True

run_mock.assert_has_calls(
[
call(
[pre_bump_hook],
_env_prefix="CZ_PRE_",
is_initial=True,
current_version="0.1.0",
current_tag_version="0.1.0",
new_version="0.2.0",
new_tag_version="0.2.0",
message="bump: version 0.1.0 → 0.2.0",
increment="MINOR",
changelog_file_name=None,
),
call(
[post_bump_hook],
_env_prefix="CZ_POST_",
was_initial=True,
previous_version="0.1.0",
previous_tag_version="0.1.0",
current_version="0.2.0",
current_tag_version="0.2.0",
message="bump: version 0.1.0 → 0.2.0",
increment="MINOR",
changelog_file_name=None,
),
]
)

0 comments on commit 2759f35

Please sign in to comment.