Skip to content

Commit db49ffb

Browse files
committed
refactor(commands/commit) use direct async class and open tty as binmod
1 parent 73298f2 commit db49ffb

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

commitizen/commands/commit.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import selectors
44
import sys
55
import tempfile
6-
from asyncio import DefaultEventLoopPolicy, get_event_loop_policy, set_event_loop_policy
6+
from asyncio import get_event_loop_policy, set_event_loop_policy
7+
from asyncio.unix_events import _UnixDefaultEventLoopPolicy
78
from io import IOBase
89

910
import questionary
@@ -22,7 +23,7 @@
2223
)
2324

2425

25-
class CZEventLoopPolicy(DefaultEventLoopPolicy):
26+
class CZEventLoopPolicy(_UnixDefaultEventLoopPolicy):
2627
def get_event_loop(self):
2728
self.set_event_loop(self._loop_factory(selectors.SelectSelector()))
2829
return self._local._loop
@@ -36,7 +37,7 @@ def __init__(self, stdx: IOBase):
3637
fd = os.open("/dev/tty", os.O_RDWR | os.O_NOCTTY)
3738
tty = open(fd, "wb+", buffering=0)
3839
else:
39-
tty = open("/dev/tty", "w")
40+
tty = open("/dev/tty", "wb")
4041
else:
4142
fd = os.open("/dev/tty", os.O_RDWR | os.O_NOCTTY)
4243
if self._fileno == 0:

tests/commands/test_commit_command.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ def test_WrapStdx(mocker):
230230
wrap_stout.write("data")
231231

232232
if sys.platform == "linux":
233-
writer_mock.assert_called_once_with("/dev/tty", "w")
233+
writer_mock.assert_called_once_with("/dev/tty", "wb")
234234
else:
235235
pass
236236
writer_mock().write.assert_called_once_with("data")
@@ -244,7 +244,7 @@ def test_WrapStdx(mocker):
244244
wrap_sterr.write("data")
245245

246246
if sys.platform == "linux":
247-
writer_mock.assert_called_once_with("/dev/tty", "w")
247+
writer_mock.assert_called_once_with("/dev/tty", "wb")
248248
else:
249249
pass
250250
writer_mock().write.assert_called_once_with("data")

0 commit comments

Comments
 (0)