|
1 | 1 | import io
|
2 | 2 | import itertools
|
3 | 3 | import os
|
| 4 | +import pathlib |
4 | 5 | import rlcompleter
|
5 | 6 | import select
|
6 | 7 | import subprocess
|
7 | 8 | import sys
|
| 9 | +import tempfile |
8 | 10 | from unittest import TestCase, skipUnless
|
9 | 11 | from unittest.mock import patch
|
10 | 12 | from test.support import force_not_colorized
|
11 | 13 | from test.support import SHORT_TIMEOUT
|
| 14 | +from test.support.os_helper import unlink |
12 | 15 |
|
13 | 16 | from .support import (
|
14 | 17 | FakeConsole,
|
@@ -898,6 +901,30 @@ def test_python_basic_repl(self):
|
898 | 901 | self.assertNotIn("Exception", output)
|
899 | 902 | self.assertNotIn("Traceback", output)
|
900 | 903 |
|
| 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 | + |
901 | 928 | def run_repl(self, repl_input: str | list[str], env: dict | None = None) -> tuple[str, int]:
|
902 | 929 | master_fd, slave_fd = pty.openpty()
|
903 | 930 | process = subprocess.Popen(
|
|
0 commit comments