|
10 | 10 | from test.support import force_not_colorized_test_class |
11 | 11 | from typing import Iterable |
12 | 12 | from unittest import TestCase |
13 | | -from unittest.mock import MagicMock, call |
| 13 | +from unittest.mock import MagicMock, call, patch |
14 | 14 |
|
15 | 15 | from .support import handle_all_events, code_to_events |
16 | 16 | from .support import prepare_reader as default_prepare_reader |
|
30 | 30 | pass |
31 | 31 |
|
32 | 32 |
|
| 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 | + |
33 | 46 | @force_not_colorized_test_class |
| 47 | +@patch.object(WindowsConsole, '__init__', _mock_console_init) |
34 | 48 | class WindowsConsoleTests(TestCase): |
35 | 49 | def console(self, events, **kwargs) -> Console: |
36 | 50 | console = WindowsConsole() |
@@ -373,6 +387,7 @@ def test_multiline_ctrl_z(self): |
373 | 387 | con.restore() |
374 | 388 |
|
375 | 389 |
|
| 390 | +@patch.object(WindowsConsole, '__init__', _mock_console_init) |
376 | 391 | class WindowsConsoleGetEventTests(TestCase): |
377 | 392 | # Virtual-Key Codes: https://learn.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes |
378 | 393 | VK_BACK = 0x08 |
|
0 commit comments