diff options
author | Sergey B Kirpichev <skirpichev@gmail.com> | 2025-04-27 13:32:37 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-27 13:32:37 (GMT) |
commit | 276252565ccfcbc6408abcbcbe6af7c56eea1e10 (patch) | |
tree | 22c3429b816b8d0372756a8736fef080bf161113 /Lib/test/test_pyrepl/test_pyrepl.py | |
parent | 614d79231d1e60d31b9452ea2afbc2a7d2f0034b (diff) | |
download | cpython-276252565ccfcbc6408abcbcbe6af7c56eea1e10.zip cpython-276252565ccfcbc6408abcbcbe6af7c56eea1e10.tar.gz cpython-276252565ccfcbc6408abcbcbe6af7c56eea1e10.tar.bz2 |
gh-127495: Append to history file after every statement in PyREPL (GH-132294)
Diffstat (limited to 'Lib/test/test_pyrepl/test_pyrepl.py')
-rw-r--r-- | Lib/test/test_pyrepl/test_pyrepl.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/Lib/test/test_pyrepl/test_pyrepl.py b/Lib/test/test_pyrepl/test_pyrepl.py index 3c4cc4b..c0d657e 100644 --- a/Lib/test/test_pyrepl/test_pyrepl.py +++ b/Lib/test/test_pyrepl/test_pyrepl.py @@ -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) |