Skip to content

Commit c1ec0e8

Browse files
committed
refactor(cz-commit): use Keys.Enter enum constant over string literal
1 parent 7013205 commit c1ec0e8

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

commitizen/cz/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from pathlib import Path
66

77
from prompt_toolkit.key_binding import KeyBindings, KeyPressEvent
8+
from prompt_toolkit.keys import Keys
89

910
from commitizen import git
1011
from commitizen.cz import exceptions
@@ -16,7 +17,7 @@
1617
def get_multiline_key_bindings() -> KeyBindings:
1718
kb = KeyBindings()
1819

19-
@kb.add("enter")
20+
@kb.add(Keys.Enter)
2021
def handle_enter(event: KeyPressEvent) -> None:
2122
buff = event.app.current_buffer
2223
if buff.text == "":

tests/test_cz_utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import pytest
2+
from prompt_toolkit.keys import Keys
23
from pytest_mock import MockFixture
34

45
from commitizen.cz import exceptions, utils
56

67

78
def test_multiline_key_bindings_enter_submits_on_empty(mocker: MockFixture):
89
kb = utils.get_multiline_key_bindings()
9-
handler = kb.get_bindings_for_keys(("enter",))[0].handler
10+
handler = next(b.handler for b in kb.bindings if Keys.Enter in b.keys)
1011

1112
buff = mocker.MagicMock()
1213
buff.text = ""
@@ -20,7 +21,7 @@ def test_multiline_key_bindings_enter_submits_on_empty(mocker: MockFixture):
2021

2122
def test_multiline_key_bindings_enter_inserts_newline(mocker: MockFixture):
2223
kb = utils.get_multiline_key_bindings()
23-
handler = kb.get_bindings_for_keys(("enter",))[0].handler
24+
handler = next(b.handler for b in kb.bindings if Keys.Enter in b.keys)
2425

2526
buff = mocker.MagicMock()
2627
buff.text = "some content"

0 commit comments

Comments
 (0)