Skip to content

Commit

Permalink
[3.13] pythongh-121245: a regression test for site.register_readline() (
Browse files Browse the repository at this point in the history
  • Loading branch information
miss-islington committed Jul 3, 2024
1 parent 3302c5f commit 2516673
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions Lib/test/test_pyrepl/test_pyrepl.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -898,6 +901,30 @@ def test_python_basic_repl(self):
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(
Expand Down

0 comments on commit 2516673

Please sign in to comment.