8000 test(commands/commit): add test case for customize exception raised · modlin/commitizen@41e3eac · GitHub
[go: up one dir, main page]

Skip to content

Commit 41e3eac

Browse files
committed
test(commands/commit): add test case for customize exception raised
commitizen-tools#46
1 parent 35d285e commit 41e3eac

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

tests/test_commands.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import pytest
55

66
from commitizen import cmd, commands, defaults
7+
from commitizen.cz.exceptions import CzException
78

89
config = {"name": defaults.name}
910

@@ -92,6 +93,24 @@ def test_commit_when_nothing_to_commit(mocker):
9293
assert err.value.code == commands.commit.NOTHING_TO_COMMIT
9394

9495

96+
def test_commit_when_customized_expected_raised(mocker, capsys):
97+
_err = ValueError()
98+
_err.__context__ = CzException("This is the root custom err")
99+
100+
prompt_mock = mocker.patch("questionary.prompt")
101+
prompt_mock.side_effect = _err
102+
103+
with pytest.raises(SystemExit) as err:
104+
commit_cmd = commands.Commit(config, {})
105+
commit_cmd()
106+
107+
assert err.value.code == commands.commit.CUSTOM_ERROR
108+
109+
# Assert only the content in the formatted text
110+
captured = capsys.readouterr()
111+
assert "This is the root custom err" in captured.err
112+
113+
95114
def test_example():
96115
with mock.patch("commitizen.out.write") as write_mock:
97116
commands.Example(config)()

0 commit comments

Comments
 (0)
0