|
9 | 9 | import sys
|
10 | 10 | import tempfile
|
11 | 11 | import unittest
|
12 |
| -from test.support import import_module, unlink, TESTFN |
| 12 | +from test.support import import_module, unlink, temp_dir, TESTFN |
13 | 13 | from test.support.script_helper import assert_python_ok
|
14 | 14 |
|
15 | 15 | # Skip tests if there is no readline module
|
@@ -210,6 +210,44 @@ def display(substitution, matches, longest_match_length):
|
210 | 210 | self.assertIn(b"result " + expected + b"\r\n", output)
|
211 | 211 | self.assertIn(b"history " + expected + b"\r\n", output)
|
212 | 212 |
|
| 213 | + @unittest.skipIf(is_editline, |
| 214 | + "editline history size configuration is broken") |
| 215 | + @unittest.expectedFailure |
| 216 | + def test_history_size(self): |
| 217 | + history_size = 10 |
| 218 | + with temp_dir() as test_dir: |
| 219 | + inputrc = os.path.join(test_dir, "inputrc") |
| 220 | + with open(inputrc, "wb") as f: |
| 221 | + f.write(b"set history-size %d\n" % history_size) |
| 222 | + |
| 223 | + history_file = os.path.join(test_dir, "history") |
| 224 | + with open(history_file, "wb") as f: |
| 225 | + # history_size * 2 items crashes readline |
| 226 | + data = b"".join(b"item %d\n" % i |
| 227 | + for i in range(history_size * 2)) |
| 228 | + f.write(data) |
| 229 | + |
| 230 | + script = """ |
| 231 | +import os |
| 232 | +import readline |
| 233 | +
|
| 234 | +history_file = os.environ["HISTORY_FILE"] |
| 235 | +readline.read_history_file(history_file) |
| 236 | +input() |
| 237 | +readline.write_history_file(history_file) |
| 238 | +""" |
| 239 | + |
| 240 | + env = dict(os.environ) |
| 241 | + env["INPUTRC"] = inputrc |
| 242 | + env["HISTORY_FILE"] = history_file |
| 243 | + |
| 244 | + run_pty(script, input=b"last input\r", env=env) |
| 245 | + |
| 246 | + with open(history_file, "rb") as f: |
| 247 | + lines = f.readlines() |
| 248 | + self.assertEqual(len(lines), history_size) |
| 249 | + self.assertEqual(lines[-1].strip(), b"last input") |
| 250 | + |
213 | 251 |
|
214 | 252 | def run_pty(script, input=b"dummy input\r", env=None):
|
215 | 253 | pty = import_module('pty')
|
|
0 commit comments