|
6 | 6 |
|
7 | 7 |
|
8 | 8 | import itertools |
| 9 | +from _colorize import ANSIColors |
9 | 10 | from functools import partial |
10 | 11 | from test.support import force_not_colorized_test_class |
11 | 12 | from typing import Iterable |
12 | 13 | from unittest import TestCase |
13 | | -from unittest.mock import MagicMock, call |
| 14 | +from unittest.mock import MagicMock, call, patch |
14 | 15 |
|
15 | 16 | from .support import handle_all_events, code_to_events |
16 | 17 | from .support import prepare_reader as default_prepare_reader |
@@ -366,6 +367,28 @@ def test_multiline_ctrl_z(self): |
366 | 367 | self.assertEqual(reader.cxy, (2, 3)) |
367 | 368 | con.restore() |
368 | 369 |
|
| 370 | + def test_reset_on_finish(self): |
| 371 | + # gh-152068: finish() must emit the ANSI reset sequence so any |
| 372 | + # active color does not leak past the prompt. |
| 373 | + code = "1" |
| 374 | + events = code_to_events(code) |
| 375 | + _, con = self.handle_events(events) |
| 376 | + con.finish() |
| 377 | + con.out.write.assert_any_call(ANSIColors.RESET.encode(con.encoding)) |
| 378 | + con.restore() |
| 379 | + |
| 380 | + def test_reset_on_restore(self): |
| 381 | + # gh-152068: restore() must emit the ANSI reset sequence when VT |
| 382 | + # support is enabled. |
| 383 | + code = "1" |
| 384 | + events = code_to_events(code) |
| 385 | + _, con = self.handle_events(events) |
| 386 | + con._WindowsConsole__vt_support = True |
| 387 | + con._WindowsConsole__original_input_mode = 0 |
| 388 | + with patch.object(wc, "SetConsoleMode", return_value=1): |
| 389 | + con.restore() |
| 390 | + con.out.write.assert_any_call(ANSIColors.RESET.encode(con.encoding)) |
| 391 | + |
369 | 392 |
|
370 | 393 | class WindowsConsoleGetEventTests(TestCase): |
371 | 394 | # Virtual-Key Codes: https://learn.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes |
|
0 commit comments