2 Very minimal unittests for parts of the readline module.
4 These tests were added to check that the libedit emulation on OSX and
5 the "real" readline have the same interface for history manipulation. That's
6 why the tests cover only a small subset of the interface.
9 from test
.test_support
import run_unittest
, import_module
11 # Skip tests if there is no readline module
12 readline
= import_module('readline')
14 class TestHistoryManipulation (unittest
.TestCase
):
15 def testHistoryUpdates(self
):
16 readline
.clear_history()
18 readline
.add_history("first line")
19 readline
.add_history("second line")
21 self
.assertEqual(readline
.get_history_item(0), None)
22 self
.assertEqual(readline
.get_history_item(1), "first line")
23 self
.assertEqual(readline
.get_history_item(2), "second line")
25 readline
.replace_history_item(0, "replaced line")
26 self
.assertEqual(readline
.get_history_item(0), None)
27 self
.assertEqual(readline
.get_history_item(1), "replaced line")
28 self
.assertEqual(readline
.get_history_item(2), "second line")
30 self
.assertEqual(readline
.get_current_history_length(), 2)
32 readline
.remove_history_item(0)
33 self
.assertEqual(readline
.get_history_item(0), None)
34 self
.assertEqual(readline
.get_history_item(1), "second line")
36 self
.assertEqual(readline
.get_current_history_length(), 1)
40 run_unittest(TestHistoryManipulation
)
42 if __name__
== "__main__":