1
1
import itertools
2
+
3
+ import io
2
4
import os
3
5
import rlcompleter
4
6
import sys
20
22
readline = import_module ("readline" )
21
23
22
24
from _pyrepl .console import Console , Event
23
- from _pyrepl .readline import ReadlineAlikeReader , ReadlineConfig
25
+ from _pyrepl .readline import ReadlineAlikeReader , ReadlineConfig , _ReadlineWrapper
24
26
from _pyrepl .simple_interact import _strip_final_indent
25
27
from _pyrepl .unix_eventqueue import EventQueue
26
28
from _pyrepl .simple_interact import InteractiveColoredConsole
@@ -276,7 +278,7 @@ def test_cursor_position_double_width_characters_move_up(self):
276
278
277
279
# fmt: off
278
280
code = (
279
- f"{ for_loop } \n "
281
+ f"{ for_loop } \n "
280
282
" ' 可口可乐; 可口可樂'"
281
283
)
282
284
# fmt: on
@@ -299,7 +301,7 @@ def test_cursor_position_double_width_characters_move_up_down(self):
299
301
300
302
# fmt: off
301
303
code = (
302
- f"{ for_loop } \n "
304
+ f"{ for_loop } \n "
303
305
" ' 可口可乐; 可口可樂'"
304
306
)
305
307
# fmt: on
@@ -346,8 +348,8 @@ def test_cursor_position_move_up_to_eol(self):
346
348
code = (
347
349
f"{ first_line } \n "
348
350
f"{ second_line } \n "
349
- " h\n "
350
- " hel"
351
+ " h\n "
352
+ " hel"
351
353
)
352
354
# fmt: on
353
355
@@ -379,7 +381,7 @@ def test_cursor_position_move_down_to_eol(self):
379
381
"for _ in _:\n "
380
382
" hello\n "
381
383
" h\n "
382
- f"{ last_line } "
384
+ f"{ last_line } "
383
385
)
384
386
# fmt: on
385
387
@@ -607,6 +609,27 @@ def test_global_namespace_completion(self):
607
609
output = multiline_input (reader , namespace )
608
610
self .assertEqual (output , "python" )
609
611
612
+ @patch ("_pyrepl.readline._ReadlineWrapper.get_reader" )
613
+ def test_completion_with_warnings (self , mock_get_reader ):
614
+ class Dummy :
615
+ @property
616
+ def test_func (self ):
617
+ import sys
618
+ sys .stderr .write ("warnings\n " )
619
+ return None
620
+
621
+ dummy = Dummy ()
622
+ events = code_to_events ("dummy.test_func.\t \n \n " )
623
+ namespace = {"dummy" : dummy }
624
+ reader = self .prepare_reader (events , namespace )
625
+ from _pyrepl .readline import multiline_input as readline_multiline_input
626
+ with patch ("_pyrepl.readline._ReadlineWrapper.get_reader" , lambda _ : reader ), \
627
+ patch ("sys.stderr" , new_callable = io .StringIO ) as f :
628
+ output = readline_multiline_input (more_lines , ">>>" , "..." )
629
+
630
+ self .assertEqual (output [0 ], "dummy.test_func." )
631
+ self .assertEqual (f .getvalue (), "" )
632
+
610
633
611
634
@patch ("_pyrepl.curses.tigetstr" , lambda x : b"" )
612
635
class TestUnivEventQueue (TestCase ):
@@ -883,24 +906,24 @@ def assert_screen_equals(self, reader, expected):
883
906
def test_calc_screen_wrap_simple (self ):
884
907
events = code_to_events (10 * "a" )
885
908
reader , _ = handle_events_narrow_console (events )
886
- self .assert_screen_equals (reader , f"{ 9 * "a" } \\ \n a" )
909
+ self .assert_screen_equals (reader , f"{ 9 * "a" } \\ \n a" )
887
910
888
911
def test_calc_screen_wrap_wide_characters (self ):
889
912
events = code_to_events (8 * "a" + "樂" )
890
913
reader , _ = handle_events_narrow_console (events )
891
- self .assert_screen_equals (reader , f"{ 8 * "a" } \\ \n 樂" )
914
+ self .assert_screen_equals (reader , f"{ 8 * "a" } \\ \n 樂" )
892
915
893
916
def test_calc_screen_wrap_three_lines (self ):
894
917
events = code_to_events (20 * "a" )
895
918
reader , _ = handle_events_narrow_console (events )
896
- self .assert_screen_equals (reader , f"{ 9 * "a" } \\ \n { 9 * "a" } \\ \n aa" )
919
+ self .assert_screen_equals (reader , f"{ 9 * "a" } \\ \n { 9 * "a" } \\ \n aa" )
897
920
898
921
def test_calc_screen_wrap_three_lines_mixed_character (self ):
899
922
# fmt: off
900
923
code = (
901
924
"def f():\n "
902
- f" { 8 * "a" } \n "
903
- f" { 5 * "樂" } "
925
+ f" { 8 * "a" } \n "
926
+ f" { 5 * "樂" } "
904
927
)
905
928
# fmt: on
906
929
@@ -910,9 +933,9 @@ def test_calc_screen_wrap_three_lines_mixed_character(self):
910
933
# fmt: off
911
934
self .assert_screen_equals (reader , (
912
935
"def f():\n "
913
- f" { 7 * "a" } \\ \n "
936
+ f" { 7 * "a" } \\ \n "
914
937
"a\n "
915
- f" { 3 * "樂" } \\ \n "
938
+ f" { 3 * "樂" } \\ \n "
916
939
"樂樂"
917
940
))
918
941
# fmt: on
@@ -945,7 +968,7 @@ def test_calc_screen_backspace_in_second_line_after_wrap(self):
945
968
],
946
969
)
947
970
reader , _ = handle_events_narrow_console (events )
948
- self .assert_screen_equals (reader , f"{ 9 * "a" } \\ \n a" )
971
+ self .assert_screen_equals (reader , f"{ 9 * "a" } \\ \n a" )
949
972
950
973
def test_setpos_for_xy_simple (self ):
951
974
events = code_to_events ("11+11" )
0 commit comments