Skip to content

Commit 2c61df1

Browse files
committed
Mock __init__ for WindowsConsole in test
1 parent 991bd20 commit 2c61df1

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

Lib/test/test_pyrepl/test_windows_console.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from test.support import force_not_colorized_test_class
1111
from typing import Iterable
1212
from unittest import TestCase
13-
from unittest.mock import MagicMock, call
13+
from unittest.mock import MagicMock, call, patch
1414

1515
from .support import handle_all_events, code_to_events
1616
from .support import prepare_reader as default_prepare_reader
@@ -30,7 +30,21 @@
3030
pass
3131

3232

33+
def _mock_console_init(self, f_in=0, f_out=1, term="", encoding="utf-8"):
34+
"""Mock __init__ to avoid real Windows API calls in headless environments."""
35+
super(WindowsConsole, self).__init__(f_in, f_out, term, encoding)
36+
self.screen = []
37+
self.width = 80
38+
self.height = 25
39+
self._WindowsConsole__offset = 0
40+
self.posxy = (0, 0)
41+
self._WindowsConsole__vt_support = False
42+
self._WindowsConsole_original_input_mode = 0
43+
self.event_queue = wc.EventQueue('utf-8')
44+
45+
3346
@force_not_colorized_test_class
47+
@patch.object(WindowsConsole, '__init__', _mock_console_init)
3448
class WindowsConsoleTests(TestCase):
3549
def console(self, events, **kwargs) -> Console:
3650
console = WindowsConsole()
@@ -373,6 +387,7 @@ def test_multiline_ctrl_z(self):
373387
con.restore()
374388

375389

390+
@patch.object(WindowsConsole, '__init__', _mock_console_init)
376391
class WindowsConsoleGetEventTests(TestCase):
377392
# Virtual-Key Codes: https://learn.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes
378393
VK_BACK = 0x08

0 commit comments

Comments
 (0)