|
20 | 20 | colors = {overrides.get(k, k[0].lower()): v for k, v in default_theme.syntax.items()} |
21 | 21 |
|
22 | 22 |
|
| 23 | +def prepare_reader_multiline_prompt(*args, **kwargs): |
| 24 | + reader = prepare_reader(*args, **kwargs) |
| 25 | + del reader.get_prompt |
| 26 | + reader.ps1 = "Python 3.15\n>>> " |
| 27 | + reader.ps2 = "Python 3.15\n>>> " |
| 28 | + reader.ps3 = "Python 3.15\n... " |
| 29 | + reader.ps4 = "Python 3.15\n... " |
| 30 | + reader.can_colorize = False |
| 31 | + reader.paste_mode = False |
| 32 | + return reader |
| 33 | + |
| 34 | + |
23 | 35 | @force_not_colorized_test_class |
24 | 36 | class TestReader(ScreenEqualMixin, TestCase): |
| 37 | + def assert_multiline_prompt_screen(self, code, expected_screen, expected_cxy): |
| 38 | + reader, _ = handle_all_events( |
| 39 | + code_to_events(code), |
| 40 | + prepare_reader=prepare_reader_multiline_prompt, |
| 41 | + ) |
| 42 | + |
| 43 | + self.assertEqual(reader.screen, expected_screen) |
| 44 | + self.assertEqual(reader.cxy, expected_cxy) |
| 45 | + |
| 46 | + def test_multiline_prompt_does_not_duplicate_leading_lines(self): |
| 47 | + self.assert_multiline_prompt_screen( |
| 48 | + "abc", |
| 49 | + ["Python 3.15", ">>> abc"], |
| 50 | + (7, 1), |
| 51 | + ) |
| 52 | + |
| 53 | + def test_multiline_prompt_does_not_duplicate_leading_lines_across_buffer_lines(self): |
| 54 | + self.assert_multiline_prompt_screen( |
| 55 | + "if x:\n y", |
| 56 | + [ |
| 57 | + "Python 3.15", |
| 58 | + ">>> if x:", |
| 59 | + "Python 3.15", |
| 60 | + "... y", |
| 61 | + ], |
| 62 | + (13, 3), |
| 63 | + ) |
| 64 | + |
25 | 65 | def test_calc_screen_wrap_simple(self): |
26 | 66 | events = code_to_events(10 * "a") |
27 | 67 | reader, _ = handle_events_narrow_console(events) |
|
0 commit comments