Skip to content
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

gh-120041: Do not use append_to_screen when completions are visible #120042

Merged
merged 4 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
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
Add tests
  • Loading branch information
lysnikolaou committed Jun 4, 2024
commit 0c67b353eef868d692fc61fc00a8f8662aaee1ba
2 changes: 1 addition & 1 deletion Lib/test/test_pyrepl/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def code_to_events(code: str):


def prepare_reader(console: Console, **kwargs):
config = ReadlineConfig(readline_completer=None)
config = ReadlineConfig(readline_completer=kwargs.pop("readline_completer", None))
reader = ReadlineAlikeReader(console=console, config=config)
reader.more_lines = partial(more_lines, namespace=None)
reader.paste_mode = True # Avoid extra indents
Expand Down
37 changes: 36 additions & 1 deletion Lib/test/test_pyrepl/test_reader.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import itertools
import functools
import rlcompleter
from unittest import TestCase

from .support import handle_all_events, handle_events_narrow_console, code_to_events, prepare_reader
Expand All @@ -9,7 +10,7 @@

class TestReader(TestCase):
def assert_screen_equals(self, reader, expected):
actual = reader.calc_screen()
actual = reader.screen
expected = expected.split("\n")
self.assertListEqual(actual, expected)

Expand Down Expand Up @@ -208,3 +209,37 @@ def test_prompt_length(self):
prompt, l = Reader.process_prompt(ps1)
self.assertEqual(prompt, "\033[0;32m樂>\033[0m> ")
self.assertEqual(l, 5)

def test_completions_updated_on_key_press(self):
namespace = {"itertools": itertools}
code = "itertools."
events = itertools.chain(code_to_events(code), [
Event(evt='key', data='\t', raw=bytearray(b'\t')), # Two tabs for completion
Event(evt='key', data='\t', raw=bytearray(b'\t')),
], code_to_events("a"))

completing_reader = functools.partial(
prepare_reader,
readline_completer=rlcompleter.Completer(namespace).complete
)
reader, _ = handle_all_events(events, prepare_reader=completing_reader)

actual = reader.screen
self.assertEqual(len(actual), 2)
self.assertEqual(actual[0].rstrip(), "itertools.accumulate(")
self.assertEqual(actual[1], f"{code}a")

def test_key_press_on_tab_press_once(self):
namespace = {"itertools": itertools}
code = "itertools."
events = itertools.chain(code_to_events(code), [
Event(evt='key', data='\t', raw=bytearray(b'\t')),
], code_to_events("a"))

completing_reader = functools.partial(
prepare_reader,
readline_completer=rlcompleter.Completer(namespace).complete
)
reader, _ = handle_all_events(events, prepare_reader=completing_reader)

self.assert_screen_equals(reader, f"{code}a")
Loading