Skip to content

Commit

Permalink
test(hooks): add test case for run
Browse files Browse the repository at this point in the history
  • Loading branch information
Lee-W committed Feb 8, 2023
1 parent 2759f35 commit da0ea0e
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion tests/test_bump_hooks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,35 @@
from commitizen import hooks
from unittest.mock import call

import pytest
from pytest_mock import MockFixture

from commitizen import cmd, hooks
from commitizen.exceptions import RunHookError


def test_run(mocker: MockFixture):
bump_hooks = ["pre_bump_hook", "pre_bump_hook_1"]

cmd_run_mock = mocker.Mock()
cmd_run_mock.return_value.return_code = 0
mocker.patch.object(cmd, "run", cmd_run_mock)

hooks.run(bump_hooks)

cmd_run_mock.assert_has_calls(
[call("pre_bump_hook", env={}), call("pre_bump_hook_1", env={})]
)


def test_run_error(mocker: MockFixture):
bump_hooks = ["pre_bump_hook", "pre_bump_hook_1"]

cmd_run_mock = mocker.Mock()
cmd_run_mock.return_value.return_code = 1
mocker.patch.object(cmd, "run", cmd_run_mock)

with pytest.raises(RunHookError):
hooks.run(bump_hooks)


def test_format_env():
Expand Down

0 comments on commit da0ea0e

Please sign in to comment.