|
1 | 1 | import inspect
|
2 | 2 | import sys
|
3 | 3 | from typing import Tuple
|
4 |
| -from unittest.mock import MagicMock |
| 4 | +from unittest.mock import MagicMock, call |
5 | 5 |
|
6 | 6 | import pytest
|
7 | 7 | from pytest_mock import MockFixture
|
8 | 8 |
|
9 | 9 | import commitizen.commands.bump as bump
|
10 |
| -from commitizen import cli, cmd, git |
| 10 | +from commitizen import cli, cmd, git, hooks |
11 | 11 | from commitizen.exceptions import (
|
12 | 12 | BumpTagFailedError,
|
13 | 13 | CommitizenException,
|
@@ -759,3 +759,58 @@ def test_bump_manual_version_disallows_major_version_zero(mocker):
|
759 | 759 | "--major-version-zero cannot be combined with MANUAL_VERSION"
|
760 | 760 | )
|
761 | 761 | 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