Skip to content

Commit 2759f35

Browse files
committed
test(commands/bump): add test case from bump hooks
1 parent 5797f8a commit 2759f35

File tree

1 file changed

+57
-2
lines changed

1 file changed

+57
-2
lines changed

tests/commands/test_bump_command.py

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import inspect
22
import sys
33
from typing import Tuple
4-
from unittest.mock import MagicMock
4+
from unittest.mock import MagicMock, call
55

66
import pytest
77
from pytest_mock import MockFixture
88

99
import commitizen.commands.bump as bump
10-
from commitizen import cli, cmd, git
10+
from commitizen import cli, cmd, git, hooks
1111
from commitizen.exceptions import (
1212
BumpTagFailedError,
1313
CommitizenException,
@@ -759,3 +759,58 @@ def test_bump_manual_version_disallows_major_version_zero(mocker):
759759
"--major-version-zero cannot be combined with MANUAL_VERSION"
760760
)
761761
assert expected_error_message in str(excinfo.value)
762+
763+
764+
@pytest.mark.parametrize("commit_msg", ("feat: new file", "feat(user): new file"))
765+
def test_bump_with_pre_bump_hooks(
766+
commit_msg, mocker: MockFixture, tmp_commitizen_project
767+
):
768+
pre_bump_hook = "scripts/pre_bump_hook.sh"
769+
post_bump_hook = "scripts/post_bump_hook.sh"
770+
771+
tmp_commitizen_cfg_file = tmp_commitizen_project.join("pyproject.toml")
772+
tmp_commitizen_cfg_file.write(
773+
f"{tmp_commitizen_cfg_file.read()}\n"
774+
f'pre_bump_hooks = ["{pre_bump_hook}"]\n'
775+
f'post_bump_hooks = ["{post_bump_hook}"]\n'
776+
)
777+
778+
run_mock = mocker.Mock()
779+
mocker.patch.object(hooks, "run", run_mock)
780+
781+
create_file_and_commit(commit_msg)
782+
testargs = ["cz", "bump", "--yes"]
783+
mocker.patch.object(sys, "argv", testargs)
784+
cli.main()
785+
786+
tag_exists = git.tag_exist("0.2.0")
787+
assert tag_exists is True
788+
789+
run_mock.assert_has_calls(
790+
[
791+
call(
792+
[pre_bump_hook],
793+
_env_prefix="CZ_PRE_",
794+
is_initial=True,
795+
current_version="0.1.0",
796+
current_tag_version="0.1.0",
797+
new_version="0.2.0",
798+
new_tag_version="0.2.0",
799+
message="bump: version 0.1.0 → 0.2.0",
800+
increment="MINOR",
801+
changelog_file_name=None,
802+
),
803+
call(
804+
[post_bump_hook],
805+
_env_prefix="CZ_POST_",
806+
was_initial=True,
807+
previous_version="0.1.0",
808+
previous_tag_version="0.1.0",
809+
current_version="0.2.0",
810+
current_tag_version="0.2.0",
811+
message="bump: version 0.1.0 → 0.2.0",
812+
increment="MINOR",
813+
changelog_file_name=None,
814+
),
815+
]
816+
)

0 commit comments

Comments
 (0)