-
-
Notifications
You must be signed in to change notification settings - Fork 334
Expand file tree
/
Copy pathtest_cz_utils.py
More file actions
55 lines (38 loc) · 1.74 KB
/
test_cz_utils.py
File metadata and controls
55 lines (38 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import pytest
from prompt_toolkit.keys import Keys
from pytest_mock import MockFixture
from commitizen.cz import exceptions, utils
def test_multiline_key_bindings_enter_submits_on_empty(mocker: MockFixture):
kb = utils.get_multiline_key_bindings()
handler = next(b.handler for b in kb.bindings if Keys.Enter in b.keys)
buff = mocker.MagicMock()
buff.text = ""
event = mocker.MagicMock()
event.app.current_buffer = buff
handler(event)
buff.validate_and_handle.assert_called_once()
buff.insert_text.assert_not_called()
def test_multiline_key_bindings_enter_inserts_newline(mocker: MockFixture):
kb = utils.get_multiline_key_bindings()
handler = next(b.handler for b in kb.bindings if Keys.Enter in b.keys)
buff = mocker.MagicMock()
buff.text = "some content"
event = mocker.MagicMock()
event.app.current_buffer = buff
handler(event)
buff.insert_text.assert_called_once_with("\n")
buff.validate_and_handle.assert_not_called()
def test_required_validator():
assert utils.required_validator("test") == "test"
with pytest.raises(exceptions.AnswerRequiredError):
utils.required_validator("")
def test_multiple_line_breaker():
message = "this is the first line | and this is the second line "
result = utils.multiple_line_breaker(message)
assert result == "this is the first line\nand this is the second line"
result = utils.multiple_line_breaker(message, "is")
assert result == "th\n\nthe first line | and th\n\nthe second line"
def test_get_backup_file_path_no_project_root(mocker: MockFixture):
project_root_mock = mocker.patch("commitizen.git.find_git_project_root")
project_root_mock.return_value = None
assert utils.get_backup_file_path()