summaryrefslogtreecommitdiff
path: root/Lib/test/test_readline.py
diff options
context:
space:
mode:
authorRonald Oussoren <ronaldoussoren@mac.com>2009-09-20 14:53:22 +0000
committerRonald Oussoren <ronaldoussoren@mac.com>2009-09-20 14:53:22 +0000
commit2efd9247549064887b0206d4a57d2abda03384e8 (patch)
treeabc5516ea2c01ad39b789f03f1187a2df483bada /Lib/test/test_readline.py
parentf172f31e4f1ad74e31215138e56327af118603ef (diff)
downloadcpython-git-2efd9247549064887b0206d4a57d2abda03384e8.tar.gz
Merged revisions 74970 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r74970 | ronald.oussoren | 2009-09-20 16:18:15 +0200 (Sun, 20 Sep 2009) | 7 lines Issue 6877: this patch makes it possible to link the readline extension to the libedit emulation of the readline API on OSX 10.5 or later. This also adds a minimal testsuite for readline to check that the history manipuation functions have the same interface with both C libraries. ........
Diffstat (limited to 'Lib/test/test_readline.py')
-rw-r--r--Lib/test/test_readline.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/Lib/test/test_readline.py b/Lib/test/test_readline.py
new file mode 100644
index 0000000000..b2495a3f13
--- /dev/null
+++ b/Lib/test/test_readline.py
@@ -0,0 +1,42 @@
+"""
+Very minimal unittests for parts of the readline module.
+
+These tests were added to check that the libedit emulation on OSX and
+the "real" readline have the same interface for history manipulation. That's
+why the tests cover only a small subset of the interface.
+"""
+import unittest
+from test.support import run_unittest
+
+import readline
+
+class TestHistoryManipulation (unittest.TestCase):
+ def testHistoryUpdates(self):
+ readline.clear_history()
+
+ readline.add_history("first line")
+ readline.add_history("second line")
+
+ self.assertEqual(readline.get_history_item(0), None)
+ self.assertEqual(readline.get_history_item(1), "first line")
+ self.assertEqual(readline.get_history_item(2), "second line")
+
+ readline.replace_history_item(0, "replaced line")
+ self.assertEqual(readline.get_history_item(0), None)
+ self.assertEqual(readline.get_history_item(1), "replaced line")
+ self.assertEqual(readline.get_history_item(2), "second line")
+
+ self.assertEqual(readline.get_current_history_length(), 2)
+
+ readline.remove_history_item(0)
+ self.assertEqual(readline.get_history_item(0), None)
+ self.assertEqual(readline.get_history_item(1), "second line")
+
+ self.assertEqual(readline.get_current_history_length(), 1)
+
+
+def test_main():
+ run_unittest(TestHistoryManipulation)
+
+if __name__ == "__main__":
+ test_main()