summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_pyrepl/test_pyrepl.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_pyrepl/test_pyrepl.py')
-rw-r--r--Lib/test/test_pyrepl/test_pyrepl.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/Lib/test/test_pyrepl/test_pyrepl.py b/Lib/test/test_pyrepl/test_pyrepl.py
index 84030e0..e816de3 100644
--- a/Lib/test/test_pyrepl/test_pyrepl.py
+++ b/Lib/test/test_pyrepl/test_pyrepl.py
@@ -1217,11 +1217,33 @@ class TestMain(TestCase):
cmdline_args: list[str] | None = None,
cwd: str | None = None,
) -> tuple[str, int]:
+ temp_dir = None
+ if cwd is None:
+ temp_dir = tempfile.TemporaryDirectory(ignore_cleanup_errors=True)
+ cwd = temp_dir.name
+ try:
+ return self._run_repl(
+ repl_input, env=env, cmdline_args=cmdline_args, cwd=cwd
+ )
+ finally:
+ if temp_dir is not None:
+ temp_dir.cleanup()
+
+ def _run_repl(
+ self,
+ repl_input: str | list[str],
+ *,
+ env: dict | None,
+ cmdline_args: list[str] | None,
+ cwd: str,
+ ) -> tuple[str, int]:
assert pty
master_fd, slave_fd = pty.openpty()
cmd = [sys.executable, "-i", "-u"]
if env is None:
cmd.append("-I")
+ elif "PYTHON_HISTORY" not in env:
+ env["PYTHON_HISTORY"] = os.path.join(cwd, ".regrtest_history")
if cmdline_args is not None:
cmd.extend(cmdline_args)
process = subprocess.Popen(
@@ -1260,3 +1282,26 @@ class TestMain(TestCase):
process.kill()
exit_code = process.wait()
return "".join(output), exit_code
+
+ def test_readline_history_file(self):
+ # skip, if readline module is not available
+ readline = import_module('readline')
+ if readline.backend != "editline":
+ self.skipTest("GNU readline is not affected by this issue")
+
+ hfile = tempfile.NamedTemporaryFile()
+ self.addCleanup(unlink, hfile.name)
+ env = os.environ.copy()
+ env["PYTHON_HISTORY"] = hfile.name
+
+ env["PYTHON_BASIC_REPL"] = "1"
+ output, exit_code = self.run_repl("spam \nexit()\n", env=env)
+ self.assertEqual(exit_code, 0)
+ self.assertIn("spam ", output)
+ self.assertNotEqual(pathlib.Path(hfile.name).stat().st_size, 0)
+ self.assertIn("spam\\040", pathlib.Path(hfile.name).read_text())
+
+ env.pop("PYTHON_BASIC_REPL", None)
+ output, exit_code = self.run_repl("exit\n", env=env)
+ self.assertEqual(exit_code, 0)
+ self.assertNotIn("\\040", pathlib.Path(hfile.name).read_text())