| 1 |
""" |
| 2 |
Very minimal unittests for parts of the readline module. |
| 3 |
""" |
| 4 |
import os |
| 5 |
import unittest |
| 6 |
from test.test_support import run_unittest, import_module |
| 7 |
from test.script_helper import assert_python_ok |
| 8 |
|
| 9 |
|
| 10 |
readline = import_module('readline') |
| 11 |
|
| 12 |
class TestHistoryManipulation (unittest.TestCase): |
| 13 |
"""These tests were added to check that the libedit emulation on OSX and |
| 14 |
the "real" readline have the same interface for history manipulation. |
| 15 |
That's why the tests cover only a small subset of the interface. |
| 16 |
""" |
| 17 |
|
| 18 |
@unittest.skipUnless(hasattr(readline, "clear_history"), |
| 19 |
"The history update test cannot be run because the " |
| 20 |
"clear_history method is not available.") |
| 21 |
def testHistoryUpdates(self): |
| 22 |
readline.clear_history() |
| 23 |
|
| 24 |
readline.add_history("first line") |
| 25 |
readline.add_history("second line") |
| 26 |
|
| 27 |
self.assertEqual(readline.get_history_item(0), None) |
| 28 |
self.assertEqual(readline.get_history_item(1), "first line") |
| 29 |
self.assertEqual(readline.get_history_item(2), "second line") |
| 30 |
|
| 31 |
readline.replace_history_item(0, "replaced line") |
| 32 |
self.assertEqual(readline.get_history_item(0), None) |
| 33 |
self.assertEqual(readline.get_history_item(1), "replaced line") |
| 34 |
self.assertEqual(readline.get_history_item(2), "second line") |
| 35 |
|
| 36 |
self.assertEqual(readline.get_current_history_length(), 2) |
| 37 |
|
| 38 |
readline.remove_history_item(0) |
| 39 |
self.assertEqual(readline.get_history_item(0), None) |
| 40 |
self.assertEqual(readline.get_history_item(1), "second line") |
| 41 |
|
| 42 |
self.assertEqual(readline.get_current_history_length(), 1) |
| 43 |
|
| 44 |
|
| 45 |
class TestReadline(unittest.TestCase): |
| 46 |
|
| 47 |
@unittest.skipIf(readline._READLINE_VERSION < 0x0601 |
| 48 |
and "libedit" not in readline.__doc__, |
| 49 |
"not supported in this library version") |
| 50 |
def test_init(self): |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
rc, stdout, stderr = assert_python_ok('-c', 'import readline', |
| 55 |
TERM='xterm-256color') |
| 56 |
self.assertEqual(stdout, b'') |
| 57 |
|
| 58 |
|
| 59 |
def test_main(): |
| 60 |
run_unittest(TestHistoryManipulation, TestReadline) |
| 61 |
|
| 62 |
if __name__ == "__main__": |
| 63 |
test_main() |