|
11 | 11 | import tempfile |
12 | 12 | from pkgutil import ModuleInfo |
13 | 13 | from unittest import TestCase, skipUnless, skipIf, SkipTest |
14 | | -from unittest.mock import patch |
| 14 | +from unittest.mock import Mock, patch |
15 | 15 | from test.support import force_not_colorized, make_clean_env, Py_DEBUG |
16 | 16 | from test.support import has_subprocess_support, SHORT_TIMEOUT, STDLIB_DIR |
17 | 17 | from test.support.import_helper import import_module |
@@ -1908,3 +1908,43 @@ def test_ctrl_d_single_line_end_no_newline(self): |
1908 | 1908 | ) |
1909 | 1909 | reader, _ = handle_all_events(events) |
1910 | 1910 | self.assertEqual("hello", "".join(reader.buffer)) |
| 1911 | + |
| 1912 | + |
| 1913 | +@skipUnless(sys.platform == "win32", "windows console only") |
| 1914 | +class TestWindowsConsoleEolWrap(TestCase): |
| 1915 | + def _make_mock_console(self, width=80): |
| 1916 | + from _pyrepl import windows_console as wc |
| 1917 | + |
| 1918 | + console = object.__new__(wc.WindowsConsole) |
| 1919 | + |
| 1920 | + console.width = width |
| 1921 | + console.posxy = (0, 0) |
| 1922 | + console.screen = [""] |
| 1923 | + |
| 1924 | + console._hide_cursor = Mock() |
| 1925 | + console._show_cursor = Mock() |
| 1926 | + console._erase_to_end = Mock() |
| 1927 | + console._move_relative = Mock() |
| 1928 | + console.move_cursor = Mock() |
| 1929 | + console._WindowsConsole__write = Mock() |
| 1930 | + |
| 1931 | + return console, wc |
| 1932 | + |
| 1933 | + def test_normal_line_not_full(self): |
| 1934 | + width = 10 |
| 1935 | + console, wc = self._make_mock_console(width=width) |
| 1936 | + new_line = "a" * 3 |
| 1937 | + wc.WindowsConsole._WindowsConsole__write_changed_line( |
| 1938 | + console, 0, "", new_line, 0 |
| 1939 | + ) |
| 1940 | + self.assertEqual(console.posxy, (3, 0)) |
| 1941 | + |
| 1942 | + def test_exact_width_line_wrap_behavior(self): |
| 1943 | + width = 10 |
| 1944 | + console, wc = self._make_mock_console(width=width) |
| 1945 | + new_line = "a" * width |
| 1946 | + |
| 1947 | + wc.WindowsConsole._WindowsConsole__write_changed_line( |
| 1948 | + console, 0, "", new_line, 0 |
| 1949 | + ) |
| 1950 | + self.assertEqual(console.posxy, (width - 1, 0)) |
0 commit comments