mirror of https://github.com/python/cpython
[3.13] gh-121245: a regression test for site.register_readline() (GH-121259) (#121322)
This commit is contained in:
parent
3302c5f155
commit
251667340e
|
@ -1,14 +1,17 @@
|
|||
import io
|
||||
import itertools
|
||||
import os
|
||||
import pathlib
|
||||
import rlcompleter
|
||||
import select
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
from unittest import TestCase, skipUnless
|
||||
from unittest.mock import patch
|
||||
from test.support import force_not_colorized
|
||||
from test.support import SHORT_TIMEOUT
|
||||
from test.support.os_helper import unlink
|
||||
|
||||
from .support import (
|
||||
FakeConsole,
|
||||
|
@ -898,6 +901,30 @@ class TestMain(TestCase):
|
|||
self.assertNotIn("Exception", output)
|
||||
self.assertNotIn("Traceback", output)
|
||||
|
||||
def test_not_wiping_history_file(self):
|
||||
hfile = tempfile.NamedTemporaryFile(delete=False)
|
||||
self.addCleanup(unlink, hfile.name)
|
||||
env = os.environ.copy()
|
||||
env["PYTHON_HISTORY"] = hfile.name
|
||||
commands = "123\nspam\nexit()\n"
|
||||
|
||||
env.pop("PYTHON_BASIC_REPL", None)
|
||||
output, exit_code = self.run_repl(commands, env=env)
|
||||
self.assertEqual(exit_code, 0)
|
||||
self.assertIn("123", output)
|
||||
self.assertIn("spam", output)
|
||||
self.assertNotEqual(pathlib.Path(hfile.name).stat().st_size, 0)
|
||||
|
||||
hfile.file.truncate()
|
||||
hfile.close()
|
||||
|
||||
env["PYTHON_BASIC_REPL"] = "1"
|
||||
output, exit_code = self.run_repl(commands, env=env)
|
||||
self.assertEqual(exit_code, 0)
|
||||
self.assertIn("123", output)
|
||||
self.assertIn("spam", output)
|
||||
self.assertNotEqual(pathlib.Path(hfile.name).stat().st_size, 0)
|
||||
|
||||
def run_repl(self, repl_input: str | list[str], env: dict | None = None) -> tuple[str, int]:
|
||||
master_fd, slave_fd = pty.openpty()
|
||||
process = subprocess.Popen(
|
||||
|
|
Loading…
Reference in New Issue