Skip to content

Commit

Permalink
pythongh-123856: Refactor isearch clean-up to call the existing clean…
Browse files Browse the repository at this point in the history
…-up command; add tests
  • Loading branch information
emilyemorehouse committed Sep 24, 2024
1 parent b8f9c6e commit 7389752
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 1 addition & 3 deletions Lib/_pyrepl/simple_interact.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,7 @@ def maybe_run_command(statement: str) -> bool:
except KeyboardInterrupt:
r = _get_reader()
if r.input_trans is r.isearch_trans:
r.isearch_direction = ''
r.console.forgetinput()
r.pop_input_trans()
r.do_cmd(("isearch-end", [""]))
r.pos = len(r.get_unicode())
r.dirty = True
r.refresh()
Expand Down
11 changes: 11 additions & 0 deletions Lib/test/test_pyrepl/test_pyrepl.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import subprocess
import sys
import tempfile
import termios
from unittest import TestCase, skipUnless
from unittest.mock import patch
from test.support import force_not_colorized
Expand Down Expand Up @@ -1246,6 +1247,12 @@ def _run_repl(
env["PYTHON_HISTORY"] = os.path.join(cwd, ".regrtest_history")
if cmdline_args is not None:
cmd.extend(cmdline_args)

term_attr = termios.tcgetattr(slave_fd)
term_attr[6][termios.VREPRINT] = 0 # pass through CTRL-R
term_attr[6][termios.VINTR] = 0 # pass through CTRL-C
termios.tcsetattr(slave_fd, termios.TCSANOW, term_attr)

process = subprocess.Popen(
cmd,
stdin=slave_fd,
Expand Down Expand Up @@ -1305,3 +1312,7 @@ def test_readline_history_file(self):
output, exit_code = self.run_repl("exit\n", env=env)
self.assertEqual(exit_code, 0)
self.assertNotIn("\\040", pathlib.Path(hfile.name).read_text())

def test_keyboard_interrupt_after_isearch(self):
output, exit_code = self.run_repl(["\x12", "\x03", "exit"])
self.assertEqual(exit_code, 0)

0 comments on commit 7389752

Please sign in to comment.