Skip to content

Commit da0ea0e

Browse files
committed
test(hooks): add test case for run
1 parent 2759f35 commit da0ea0e

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

tests/test_bump_hooks.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,35 @@
1-
from commitizen import hooks
1+
from unittest.mock import call
2+
3+
import pytest
4+
from pytest_mock import MockFixture
5+
6+
from commitizen import cmd, hooks
7+
from commitizen.exceptions import RunHookError
8+
9+
10+
def test_run(mocker: MockFixture):
11+
bump_hooks = ["pre_bump_hook", "pre_bump_hook_1"]
12+
13+
cmd_run_mock = mocker.Mock()
14+
cmd_run_mock.return_value.return_code = 0
15+
mocker.patch.object(cmd, "run", cmd_run_mock)
16+
17+
hooks.run(bump_hooks)
18+
19+
cmd_run_mock.assert_has_calls(
20+
[call("pre_bump_hook", env={}), call("pre_bump_hook_1", env={})]
21+
)
22+
23+
24+
def test_run_error(mocker: MockFixture):
25+
bump_hooks = ["pre_bump_hook", "pre_bump_hook_1"]
26+
27+
cmd_run_mock = mocker.Mock()
28+
cmd_run_mock.return_value.return_code = 1
29+
mocker.patch.object(cmd, "run", cmd_run_mock)
30+
31+
with pytest.raises(RunHookError):
32+
hooks.run(bump_hooks)
233

334

435
def test_format_env():

0 commit comments

Comments
 (0)