gh-127495: Append to history file after every statement in PyREPL (GH-132294)

This commit is contained in:
Sergey B Kirpichev 2025-04-27 16:32:37 +03:00 committed by GitHub
parent 614d79231d
commit 276252565c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 47 additions and 1 deletions

View file

@ -112,6 +112,7 @@ class ReplTestCase(TestCase):
else:
os.close(master_fd)
process.kill()
process.wait(timeout=SHORT_TIMEOUT)
self.fail(f"Timeout while waiting for output, got: {''.join(output)}")
os.close(master_fd)
@ -1564,6 +1565,27 @@ class TestMain(ReplTestCase):
self.assertEqual(exit_code, 0)
self.assertNotIn("\\040", pathlib.Path(hfile.name).read_text())
def test_history_survive_crash(self):
env = os.environ.copy()
commands = "1\nexit()\n"
output, exit_code = self.run_repl(commands, env=env)
if "can't use pyrepl" in output:
self.skipTest("pyrepl not available")
with tempfile.NamedTemporaryFile() as hfile:
env["PYTHON_HISTORY"] = hfile.name
commands = "spam\nimport time\ntime.sleep(1000)\npreved\n"
try:
self.run_repl(commands, env=env)
except AssertionError:
pass
history = pathlib.Path(hfile.name).read_text()
self.assertIn("spam", history)
self.assertIn("time", history)
self.assertNotIn("sleep", history)
self.assertNotIn("preved", history)
def test_keyboard_interrupt_after_isearch(self):
output, exit_code = self.run_repl(["\x12", "\x03", "exit"])
self.assertEqual(exit_code, 0)