Skip to content

Commit

Permalink
gh-128770: fix ResourceWarning in test_pyrepl (#128906)
Browse files Browse the repository at this point in the history
  • Loading branch information
graingert authored Jan 22, 2025
1 parent a16ded1 commit 24c84d8
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions Lib/test/test_pyrepl/test_pyrepl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1324,22 +1324,21 @@ def test_readline_history_file(self):
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())
with tempfile.NamedTemporaryFile() as hfile:
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())

def test_keyboard_interrupt_after_isearch(self):
output, exit_code = self.run_repl(["\x12", "\x03", "exit"])
Expand Down

0 comments on commit 24c84d8

Please sign in to comment.