Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 626439e

Browse files
committedJul 4, 2024·
Add a test that runs even when clear_history() is not available
1 parent 49b4e50 commit 626439e

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
 

‎Lib/test/test_readline.py

+20
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,26 @@ def test_history_size(self):
349349
self.assertEqual(len(lines), history_size)
350350
self.assertEqual(lines[-1].strip(), b"last input")
351351

352+
def test_write_read_limited_history(self):
353+
previous_length = readline.get_history_length()
354+
self.addCleanup(readline.set_history_length, previous_length)
355+
356+
readline.add_history("first line")
357+
readline.add_history("second line")
358+
readline.add_history("third line")
359+
360+
readline.set_history_length(2)
361+
self.assertEqual(readline.get_history_length(), 2)
362+
readline.write_history_file(TESTFN)
363+
self.addCleanup(os.remove, TESTFN)
364+
365+
readline.read_history_file(TESTFN)
366+
# Without clear_history() there's no good way to test if
367+
# the correct entries are present (we're combining history limiting and
368+
# possible deduplication with arbitrary previous content).
369+
# So, we've only tested that the read did not fail.
370+
# See TestHistoryManipulation for the full test.
371+
352372

353373
if __name__ == "__main__":
354374
unittest.main()

0 commit comments

Comments
 (0)
Please sign in to comment.