|
9 | 9 | import sys |
10 | 10 | import tempfile |
11 | 11 | from unittest import TestCase, skipUnless, skipIf |
12 | | -from unittest.mock import patch |
| 12 | +from unittest.mock import Mock, patch |
13 | 13 | from test.support import force_not_colorized, make_clean_env, Py_DEBUG |
14 | 14 | from test.support import SHORT_TIMEOUT, STDLIB_DIR |
15 | 15 | from test.support.import_helper import import_module |
@@ -1579,3 +1579,47 @@ def test_ctrl_d_single_line_end_no_newline(self): |
1579 | 1579 | ) |
1580 | 1580 | reader, _ = handle_all_events(events) |
1581 | 1581 | self.assertEqual("hello", "".join(reader.buffer)) |
| 1582 | + |
| 1583 | + |
| 1584 | +@skipUnless(sys.platform == "win32", "windows console only") |
| 1585 | +class TestWindowsConsoleEolWrap(TestCase): |
| 1586 | + def _make_mock_console(self, width=80): |
| 1587 | + from _pyrepl import windows_console as wc |
| 1588 | + |
| 1589 | + console = object.__new__(wc.WindowsConsole) |
| 1590 | + |
| 1591 | + console.width = width |
| 1592 | + console.posxy = (0, 0) |
| 1593 | + console.screen = [""] |
| 1594 | + |
| 1595 | + console._hide_cursor = Mock() |
| 1596 | + console._show_cursor = Mock() |
| 1597 | + console._erase_to_end = Mock() |
| 1598 | + console._move_relative = Mock() |
| 1599 | + console.move_cursor = Mock() |
| 1600 | + console._WindowsConsole__write = Mock() |
| 1601 | + |
| 1602 | + return console, wc |
| 1603 | + |
| 1604 | + def test_short_line_sets_posxy_normally(self): |
| 1605 | + width = 10 |
| 1606 | + y = 3 |
| 1607 | + console, wc = self._make_mock_console(width=width) |
| 1608 | + old_line = "" |
| 1609 | + new_line = "a" * 3 |
| 1610 | + wc.WindowsConsole._WindowsConsole__write_changed_line( |
| 1611 | + console, y, old_line, new_line, 0 |
| 1612 | + ) |
| 1613 | + self.assertEqual(console.posxy, (3, y)) |
| 1614 | + |
| 1615 | + def test_exact_width_line_does_not_wrap(self): |
| 1616 | + width = 10 |
| 1617 | + y = 3 |
| 1618 | + console, wc = self._make_mock_console(width=width) |
| 1619 | + old_line = "" |
| 1620 | + new_line = "a" * width |
| 1621 | + |
| 1622 | + wc.WindowsConsole._WindowsConsole__write_changed_line( |
| 1623 | + console, y, old_line, new_line, 0 |
| 1624 | + ) |
| 1625 | + self.assertEqual(console.posxy, (width - 1, y)) |
0 commit comments