Skip to content

Commit afee76b

Browse files
authored
pythongh-121245: a regression test for site.register_readline() (python#121259)
1 parent 722229e commit afee76b

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Lib/test/test_pyrepl/test_pyrepl.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import io
22
import itertools
33
import os
4+
import pathlib
45
import rlcompleter
56
import select
67
import subprocess
78
import sys
9+
import tempfile
810
from unittest import TestCase, skipUnless
911
from unittest.mock import patch
1012
from test.support import force_not_colorized
1113
from test.support import SHORT_TIMEOUT
14+
from test.support.os_helper import unlink
1215

1316
from .support import (
1417
FakeConsole,
@@ -898,6 +901,30 @@ def test_python_basic_repl(self):
898901
self.assertNotIn("Exception", output)
899902
self.assertNotIn("Traceback", output)
900903

904+
def test_not_wiping_history_file(self):
905+
hfile = tempfile.NamedTemporaryFile(delete=False)
906+
self.addCleanup(unlink, hfile.name)
907+
env = os.environ.copy()
908+
env["PYTHON_HISTORY"] = hfile.name
909+
commands = "123\nspam\nexit()\n"
910+
911+
env.pop("PYTHON_BASIC_REPL", None)
912+
output, exit_code = self.run_repl(commands, env=env)
913+
self.assertEqual(exit_code, 0)
914+
self.assertIn("123", output)
915+
self.assertIn("spam", output)
916+
self.assertNotEqual(pathlib.Path(hfile.name).stat().st_size, 0)
917+
918+
hfile.file.truncate()
919+
hfile.close()
920+
921+
env["PYTHON_BASIC_REPL"] = "1"
922+
output, exit_code = self.run_repl(commands, env=env)
923+
self.assertEqual(exit_code, 0)
924+
self.assertIn("123", output)
925+
self.assertIn("spam", output)
926+
self.assertNotEqual(pathlib.Path(hfile.name).stat().st_size, 0)
927+
901928
def run_repl(self, repl_input: str | list[str], env: dict | None = None) -> tuple[str, int]:
902929
master_fd, slave_fd = pty.openpty()
903930
process = subprocess.Popen(

0 commit comments

Comments
 (0)