|
6 | 6 | import threading |
7 | 7 | import unittest |
8 | 8 | from functools import partial |
9 | | -from test.support import os_helper, force_not_colorized_test_class |
| 9 | +from _colorize import ANSIColors |
| 10 | +from test.support import force_color, os_helper, force_not_colorized_test_class |
10 | 11 | from test.support import threading_helper |
11 | 12 |
|
12 | 13 | from unittest import TestCase |
@@ -107,6 +108,24 @@ def test_no_newline(self, _os_write): |
107 | 108 | self.assertNotIn(call(ANY, b'\n'), _os_write.mock_calls) |
108 | 109 | con.restore() |
109 | 110 |
|
| 111 | + def test_reset_on_finish(self, _os_write): |
| 112 | + # gh-152068: finish() must emit the ANSI reset sequence so any |
| 113 | + # active color does not leak past the prompt. |
| 114 | + code = "1" |
| 115 | + events = code_to_events(code) |
| 116 | + _, con = handle_events_unix_console(events) |
| 117 | + con.finish() |
| 118 | + _os_write.assert_any_call(ANY, ANSIColors.RESET.encode(con.encoding)) |
| 119 | + con.restore() |
| 120 | + |
| 121 | + def test_reset_on_restore(self, _os_write): |
| 122 | + # gh-152068: restore() must emit the ANSI reset sequence. |
| 123 | + code = "1" |
| 124 | + events = code_to_events(code) |
| 125 | + _, con = handle_events_unix_console(events) |
| 126 | + con.restore() |
| 127 | + _os_write.assert_any_call(ANY, ANSIColors.RESET.encode(con.encoding)) |
| 128 | + |
110 | 129 | def test_newline(self, _os_write): |
111 | 130 | code = "\n" |
112 | 131 | events = code_to_events(code) |
|
0 commit comments