|
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 |
@@ -2105,3 +2105,47 @@ def test_ctrl_d_single_line_end_no_newline(self): |
2105 | 2105 | ) |
2106 | 2106 | reader, _ = handle_all_events(events) |
2107 | 2107 | self.assertEqual("hello", "".join(reader.buffer)) |
| 2108 | + |
| 2109 | + |
| 2110 | +@skipUnless(sys.platform == "win32", "windows console only") |
| 2111 | +class TestWindowsConsoleEolWrap(TestCase): |
| 2112 | + def _make_mock_console(self, width=80): |
| 2113 | + from _pyrepl import windows_console as wc |
| 2114 | + |
| 2115 | + console = object.__new__(wc.WindowsConsole) |
| 2116 | + |
| 2117 | + console.width = width |
| 2118 | + console.posxy = (0, 0) |
| 2119 | + console.screen = [""] |
| 2120 | + |
| 2121 | + console._hide_cursor = Mock() |
| 2122 | + console._show_cursor = Mock() |
| 2123 | + console._erase_to_end = Mock() |
| 2124 | + console._move_relative = Mock() |
| 2125 | + console.move_cursor = Mock() |
| 2126 | + console._WindowsConsole__write = Mock() |
| 2127 | + |
| 2128 | + return console, wc |
| 2129 | + |
| 2130 | + def test_short_line_sets_posxy_normally(self): |
| 2131 | + width = 10 |
| 2132 | + y = 3 |
| 2133 | + console, wc = self._make_mock_console(width=width) |
| 2134 | + old_line = "" |
| 2135 | + new_line = "a" * 3 |
| 2136 | + wc.WindowsConsole._WindowsConsole__write_changed_line( |
| 2137 | + console, y, old_line, new_line, 0 |
| 2138 | + ) |
| 2139 | + self.assertEqual(console.posxy, (3, y)) |
| 2140 | + |
| 2141 | + def test_exact_width_line_does_not_wrap(self): |
| 2142 | + width = 10 |
| 2143 | + y = 3 |
| 2144 | + console, wc = self._make_mock_console(width=width) |
| 2145 | + old_line = "" |
| 2146 | + new_line = "a" * width |
| 2147 | + |
| 2148 | + wc.WindowsConsole._WindowsConsole__write_changed_line( |
| 2149 | + console, y, old_line, new_line, 0 |
| 2150 | + ) |
| 2151 | + self.assertEqual(console.posxy, (width - 1, y)) |
0 commit comments