8000 gh-119205: Fix autocompletion bug in new repl by koxudaxi · Pull Request #119229 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-119205: Fix autocompletion bug in new repl #119229

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
May 21, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
gh-119205: Add unittest
  • Loading branch information
koxudaxi committed May 20, 2024
commit f9ee8097e930258bad90c6a21704bc2927af19d0
51 changes: 37 additions & 14 deletions Lib/test/test_pyrepl.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import itertools

import io
import os
import rlcompleter
import sys
Expand All @@ -20,7 +22,7 @@
readline = import_module("readline")

from _pyrepl.console import Console, Event
from _pyrepl.readline import ReadlineAlikeReader, ReadlineConfig
from _pyrepl.readline import ReadlineAlikeReader, ReadlineConfig, _ReadlineWrapper
from _pyrepl.simple_interact import _strip_final_indent
from _pyrepl.unix_eventqueue import EventQueue
from _pyrepl.simple_interact import InteractiveColoredConsole
Expand Down Expand Up @@ -276,7 +278,7 @@ def test_cursor_position_double_width_characters_move_up(self):

# fmt: off
code = (
f"{for_loop}\n"
f"{for_loop}\n"
" ' 可口可乐; 可口可樂'"
)
# fmt: on
Expand All @@ -299,7 +301,7 @@ def test_cursor_position_double_width_characters_move_up_down(self):

# fmt: off
code = (
f"{for_loop}\n"
f"{for_loop}\n"
" ' 可口可乐; 可口可樂'"
)
# fmt: on
Expand Down Expand Up @@ -346,8 +348,8 @@ def test_cursor_position_move_up_to_eol(self):
code = (
f"{first_line}\n"
f"{second_line}\n"
" h\n"
" hel"
" h\n"
" hel"
)
# fmt: on

Expand Down Expand Up @@ -379,7 +381,7 @@ def test_cursor_position_move_down_to_eol(self):
"for _ in _:\n"
" hello\n"
" h\n"
f"{last_line}"
f"{last_line}"
)
# fmt: on

Expand Down Expand Up @@ -607,6 +609,27 @@ def test_global_namespace_completion(self):
output = multiline_input(reader, namespace)
self.assertEqual(output, "python")

@patch("_pyrepl.readline._ReadlineWrapper.get_reader")
def test_completion_with_warnings(self, mock_get_reader):
class Dummy:
@property
def test_func(self):
import sys
sys.stderr.write("warnings\n")
return None

dummy = Dummy()
events = code_to_events("dummy.test_func.\t\n\n")
namespace = {"dummy": dummy}
reader = self.prepare_reader(events, namespace)
from _pyrepl.readline import multiline_input as readline_multiline_input
with patch("_pyrepl.readline._ReadlineWrapper.get_reader", lambda _: reader), \
patch("sys.stderr", new_callable=io.StringIO) as f:
output = readline_multiline_input(more_lines, ">>>", "...")

self.assertEqual(output[0], "dummy.test_func.")
self.assertEqual(f.getvalue(), "")


@patch("_pyrepl.curses.tigetstr", lambda x: b"")
class TestUnivEventQueue(TestCase):
Expand Down Expand Up @@ -883,24 +906,24 @@ def assert_screen_equals(self, reader, expected):
def test_calc_screen_wrap_simple(self):
events = code_to_events(10 * "a")
reader, _ = handle_events_narrow_console(events)
self.assert_screen_equals(reader, f"{9*"a"}\\\na")
self.assert_screen_equals(reader, f"{9 * "a"}\\\na")

def test_calc_screen_wrap_wide_characters(self):
events = code_to_events(8 * "a" + "樂")
reader, _ = handle_events_narrow_console(events)
self.assert_screen_equals(reader, f"{8*"a"}\\\n樂")
self.assert_screen_equals(reader, f"{8 * "a"}\\\n樂")

def test_calc_screen_wrap_three_lines(self):
events = code_to_events(20 * "a")
reader, _ = handle_events_narrow_console(events)
self.assert_screen_equals(reader, f"{9*"a"}\\\n{9*"a"}\\\naa")
self.assert_screen_equals(reader, f"{9 * "a"}\\\n{9 * "a"}\\\naa")

def test_calc_screen_wrap_three_lines_mixed_character(self):
# fmt: off
code = (
"def f():\n"
f" {8*"a"}\n"
f" {5*"樂"}"
f" {8 * "a"}\n"
f" {5 * "樂"}"
)
# fmt: on

Expand All @@ -910,9 +933,9 @@ def test_calc_screen_wrap_three_lines_mixed_character(self):
# fmt: off
self.assert_screen_equals(reader, (
"def f():\n"
f" {7*"a"}\\\n"
f" {7 * "a"}\\\n"
"a\n"
f" {3*"樂"}\\\n"
f" {3 * "樂"}\\\n"
"樂樂"
))
# fmt: on
Expand Down Expand Up @@ -945,7 +968,7 @@ def test_calc_screen_backspace_in_second_line_after_wrap(self):
],
)
reader, _ = handle_events_narrow_console(events)
self.assert_screen_equals(reader, f"{9*"a"}\\\na")
self.assert_screen_equals(reader, f"{9 * "a"}\\\na")

def test_setpos_for_xy_simple(self):
events = code_to_events("11+11")
Expand Down
0