summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_readline.py
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2014-11-26 19:58:16 (GMT)
committerBenjamin Peterson <benjamin@python.org>2014-11-26 19:58:16 (GMT)
commit33f8f15bdd313b1e2d1c99d0971659e983a35672 (patch)
treedbd199022545350d249c01d659ffcb2a9f55ee27 /Lib/test/test_readline.py
parentaacfcccdc39b074521d3e5d4b5a1b1e020662366 (diff)
downloadcpython-33f8f15bdd313b1e2d1c99d0971659e983a35672.zip
cpython-33f8f15bdd313b1e2d1c99d0971659e983a35672.tar.gz
cpython-33f8f15bdd313b1e2d1c99d0971659e983a35672.tar.bz2
add readline.append_history_file (closes #22940)
patch by "bru"
Diffstat (limited to 'Lib/test/test_readline.py')
-rw-r--r--Lib/test/test_readline.py40
1 files changed, 39 insertions, 1 deletions
diff --git a/Lib/test/test_readline.py b/Lib/test/test_readline.py
index d2a11f2..e5be02e 100644
--- a/Lib/test/test_readline.py
+++ b/Lib/test/test_readline.py
@@ -2,8 +2,9 @@
Very minimal unittests for parts of the readline module.
"""
import os
+import tempfile
import unittest
-from test.support import run_unittest, import_module
+from test.support import run_unittest, import_module, unlink
from test.script_helper import assert_python_ok
# Skip tests if there is no readline module
@@ -42,6 +43,43 @@ class TestHistoryManipulation (unittest.TestCase):
self.assertEqual(readline.get_current_history_length(), 1)
+ def test_write_read_append(self):
+ hfile = tempfile.NamedTemporaryFile(delete=False)
+ hfile.close()
+ hfilename = hfile.name
+ self.addCleanup(unlink, hfilename)
+
+ # test write-clear-read == nop
+ readline.clear_history()
+ readline.add_history("first line")
+ readline.add_history("second line")
+ readline.write_history_file(hfilename)
+
+ readline.clear_history()
+ self.assertEqual(readline.get_current_history_length(), 0)
+
+ readline.read_history_file(hfilename)
+ self.assertEqual(readline.get_current_history_length(), 2)
+ self.assertEqual(readline.get_history_item(1), "first line")
+ self.assertEqual(readline.get_history_item(2), "second line")
+
+ # test append
+ readline.append_history_file(1, hfilename)
+ readline.clear_history()
+ readline.read_history_file(hfilename)
+ self.assertEqual(readline.get_current_history_length(), 3)
+ self.assertEqual(readline.get_history_item(1), "first line")
+ self.assertEqual(readline.get_history_item(2), "second line")
+ self.assertEqual(readline.get_history_item(3), "second line")
+
+ # test 'no such file' behaviour
+ os.unlink(hfilename)
+ with self.assertRaises(FileNotFoundError):
+ readline.append_history_file(1, hfilename)
+
+ # write_history_file can create the target
+ readline.write_history_file(hfilename)
+
class TestReadline(unittest.TestCase):