|
1 | 1 | import itertools
|
| 2 | +import io |
2 | 3 | import os
|
3 | 4 | import rlcompleter
|
4 |
| -import unittest |
5 | 5 | from unittest import TestCase
|
| 6 | +from unittest.mock import patch |
6 | 7 |
|
7 |
| -from .support import FakeConsole, handle_all_events, handle_events_narrow_console, multiline_input, code_to_events |
| 8 | +from .support import FakeConsole, handle_all_events, handle_events_narrow_console |
| 9 | +from .support import more_lines, multiline_input, code_to_events |
8 | 10 | from _pyrepl.console import Event
|
9 | 11 | from _pyrepl.readline import ReadlineAlikeReader, ReadlineConfig
|
| 12 | +from _pyrepl.readline import multiline_input as readline_multiline_input |
10 | 13 |
|
11 | 14 |
|
12 | 15 | class TestCursorPosition(TestCase):
|
@@ -475,6 +478,25 @@ def test_updown_arrow_with_completion_menu(self):
|
475 | 478 | output = multiline_input(reader, namespace)
|
476 | 479 | self.assertEqual(output, "os.")
|
477 | 480 |
|
| 481 | + @patch("_pyrepl.readline._ReadlineWrapper.get_reader") |
| 482 | + @patch("sys.stderr", new_callable=io.StringIO) |
| 483 | + def test_completion_with_warnings(self, mock_stderr, mock_get_reader): |
| 484 | + class Dummy: |
| 485 | + @property |
| 486 | + def test_func(self): |
| 487 | + import warnings |
| 488 | + warnings.warn("warnings\n") |
| 489 | + return None |
| 490 | + |
| 491 | + dummy = Dummy() |
| 492 | + events = code_to_events("dummy.test_func.\t\n\n") |
| 493 | + namespace = {"dummy": dummy} |
| 494 | + reader = self.prepare_reader(events, namespace) |
| 495 | + mock_get_reader.return_value = reader |
| 496 | + output = readline_multiline_input(more_lines, ">>>", "...") |
| 497 | + self.assertEqual(output[0], "dummy.test_func.__") |
| 498 | + self.assertEqual(mock_stderr.getvalue(), "") |
| 499 | + |
478 | 500 |
|
479 | 501 | class TestPasteEvent(TestCase):
|
480 | 502 | def prepare_reader(self, events):
|
@@ -633,7 +655,3 @@ def test_bracketed_paste_single_line(self):
|
633 | 655 | reader = self.prepare_reader(events)
|
634 | 656 | output = multiline_input(reader)
|
635 | 657 | self.assertEqual(output, input_code)
|
636 |
| - |
637 |
| - |
638 |
| -if __name__ == "__main__": |
639 |
| - unittest.main() |
|
0 commit comments