|
12 | 12 | import tempfile |
13 | 13 | from pkgutil import ModuleInfo |
14 | 14 | from unittest import TestCase, skipUnless, skipIf, SkipTest |
15 | | -from unittest.mock import patch |
| 15 | +from unittest.mock import Mock, patch |
16 | 16 | from test.support import force_not_colorized, make_clean_env, Py_DEBUG |
17 | 17 | from test.support import has_subprocess_support, SHORT_TIMEOUT, STDLIB_DIR |
18 | 18 | from test.support.import_helper import import_module |
@@ -2095,3 +2095,47 @@ def test_ctrl_d_single_line_end_no_newline(self): |
2095 | 2095 | ) |
2096 | 2096 | reader, _ = handle_all_events(events) |
2097 | 2097 | self.assertEqual("hello", "".join(reader.buffer)) |
| 2098 | + |
| 2099 | + |
| 2100 | +@skipUnless(sys.platform == "win32", "windows console only") |
| 2101 | +class TestWindowsConsoleEolWrap(TestCase): |
| 2102 | + def _make_mock_console(self, width=80): |
| 2103 | + from _pyrepl import windows_console as wc |
| 2104 | + |
| 2105 | + console = object.__new__(wc.WindowsConsole) |
| 2106 | + |
| 2107 | + console.width = width |
| 2108 | + console.posxy = (0, 0) |
| 2109 | + console.screen = [""] |
| 2110 | + |
| 2111 | + console._hide_cursor = Mock() |
| 2112 | + console._show_cursor = Mock() |
| 2113 | + console._erase_to_end = Mock() |
| 2114 | + console._move_relative = Mock() |
| 2115 | + console.move_cursor = Mock() |
| 2116 | + console._WindowsConsole__write = Mock() |
| 2117 | + |
| 2118 | + return console, wc |
| 2119 | + |
| 2120 | + def test_short_line_sets_posxy_normally(self): |
| 2121 | + width = 10 |
| 2122 | + y = 3 |
| 2123 | + console, wc = self._make_mock_console(width=width) |
| 2124 | + old_line = "" |
| 2125 | + new_line = "a" * 3 |
| 2126 | + wc.WindowsConsole._WindowsConsole__write_changed_line( |
| 2127 | + console, y, old_line, new_line, 0 |
| 2128 | + ) |
| 2129 | + self.assertEqual(console.posxy, (3, y)) |
| 2130 | + |
| 2131 | + def test_exact_width_line_does_not_wrap(self): |
| 2132 | + width = 10 |
| 2133 | + y = 3 |
| 2134 | + console, wc = self._make_mock_console(width=width) |
| 2135 | + old_line = "" |
| 2136 | + new_line = "a" * width |
| 2137 | + |
| 2138 | + wc.WindowsConsole._WindowsConsole__write_changed_line( |
| 2139 | + console, y, old_line, new_line, 0 |
| 2140 | + ) |
| 2141 | + self.assertEqual(console.posxy, (width - 1, y)) |
0 commit comments