mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
gh-127495: Append to history file after every statement in PyREPL (GH-132294)
This commit is contained in:
parent
614d79231d
commit
276252565c
4 changed files with 47 additions and 1 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue