Staging
v0.5.1
https://github.com/python/cpython
Raw File
Tip revision: 3101b7076270756f8be699358c69c5d15ea2cc48 authored by Larry Hastings on 16 March 2014, 05:43:17 UTC
Final documentation fixes for 3.4.0 final.
Tip revision: 3101b70
test_readline.py
"""
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_module

# Skip tests if there is no readline module
readline = import_module('readline')

class TestHistoryManipulation (unittest.TestCase):

    @unittest.skipIf(not hasattr(readline, 'clear_history'),
                     "The history update test cannot be run because the "
                     "clear_history method is not available.")
    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()
back to top