Lines Matching defs:readline
2 Very minimal unittests for parts of the readline module.
18 # Skip tests if there is no readline module
19 readline = import_module('readline')
21 if hasattr(readline, "_READLINE_LIBRARY_VERSION"):
22 is_editline = ("EditLine wrapper" in readline._READLINE_LIBRARY_VERSION)
24 is_editline = (readline.__doc__ and "libedit" in readline.__doc__)
31 if hasattr(readline, "_READLINE_VERSION"):
32 print(f"readline version: {readline._READLINE_VERSION:#x}")
33 print(f"readline runtime version: {readline._READLINE_RUNTIME_VERSION:#x}")
34 if hasattr(readline, "_READLINE_LIBRARY_VERSION"):
35 print(f"readline library version: {readline._READLINE_LIBRARY_VERSION!r}")
39 @unittest.skipUnless(hasattr(readline, "clear_history"),
45 "real" readline have the same interface for history manipulation. That's
50 readline.clear_history()
52 readline.add_history("first line")
53 readline.add_history("second line")
55 self.assertEqual(readline.get_history_item(0), None)
56 self.assertEqual(readline.get_history_item(1), "first line")
57 self.assertEqual(readline.get_history_item(2), "second line")
59 readline.replace_history_item(0, "replaced line")
60 self.assertEqual(readline.get_history_item(0), None)
61 self.assertEqual(readline.get_history_item(1), "replaced line")
62 self.assertEqual(readline.get_history_item(2), "second line")
64 self.assertEqual(readline.get_current_history_length(), 2)
66 readline.remove_history_item(0)
67 self.assertEqual(readline.get_history_item(0), None)
68 self.assertEqual(readline.get_history_item(1), "second line")
70 self.assertEqual(readline.get_current_history_length(), 1)
72 @unittest.skipUnless(hasattr(readline, "append_history_file"),
81 readline.clear_history()
82 readline.add_history("first line")
83 readline.add_history("second line")
84 readline.write_history_file(hfilename)
86 readline.clear_history()
87 self.assertEqual(readline.get_current_history_length(), 0)
89 readline.read_history_file(hfilename)
90 self.assertEqual(readline.get_current_history_length(), 2)
91 self.assertEqual(readline.get_history_item(1), "first line")
92 self.assertEqual(readline.get_history_item(2), "second line")
95 readline.append_history_file(1, hfilename)
96 readline.clear_history()
97 readline.read_history_file(hfilename)
98 self.assertEqual(readline.get_current_history_length(), 3)
99 self.assertEqual(readline.get_history_item(1), "first line")
100 self.assertEqual(readline.get_history_item(2), "second line")
101 self.assertEqual(readline.get_history_item(3), "second line")
106 readline.append_history_file(1, hfilename)
116 readline.write_history_file(hfilename)
119 readline.clear_history()
121 readline.add_history("entrée 1")
124 readline.add_history("entrée 2")
125 readline.replace_history_item(1, "entrée 22")
126 readline.write_history_file(TESTFN)
128 readline.clear_history()
129 readline.read_history_file(TESTFN)
133 readline.add_history("dummy")
134 self.assertEqual(readline.get_history_item(1), "entrée 1")
135 self.assertEqual(readline.get_history_item(2), "entrée 22")
140 @unittest.skipIf(readline._READLINE_VERSION < 0x0601 and not is_editline,
144 # written into stdout when the readline module is imported and stdout
146 rc, stdout, stderr = assert_python_ok('-c', 'import readline',
151 import readline
152 readline.set_auto_history({})
154 print("History length:", readline.get_current_history_length())
174 # readline or ncurses ignores non-ASCII bytes on read.
178 readline.add_history("\xEB\xEF")
182 script = r"""import readline
184 is_editline = readline.__doc__ and "libedit" in readline.__doc__
187 set_pre_input_hook = getattr(readline, "set_pre_input_hook", None)
194 readline.parse_and_bind(r'bind ^B ed-prev-char')
195 readline.parse_and_bind(r'bind "\t" rl_complete')
196 readline.parse_and_bind(r'bind -s ^A "{}"'.format(macro))
198 readline.parse_and_bind(r'Control-b: backward-char')
199 readline.parse_and_bind(r'"\t": complete')
200 readline.parse_and_bind(r'set disable-completion off')
201 readline.parse_and_bind(r'set show-all-if-ambiguous off')
202 readline.parse_and_bind(r'set show-all-if-unmodified off')
203 readline.parse_and_bind(r'Control-a: "{}"'.format(macro))
206 readline.insert_text(inserted)
207 readline.redisplay()
215 print("line", ascii(readline.get_line_buffer()))
216 print("indexes", readline.get_begidx(), readline.get_endidx())
223 readline.set_completer(completer)
228 readline.set_completion_display_matches_hook(display)
231 print("history", ascii(readline.get_history_item(1)))
249 # start and end values calls back into readline.c's
253 if not is_editline and hasattr(readline, "set_pre_input_hook"):
263 # - readline: history size was added in 6.0
264 # See https://cnswww.cns.cwru.edu/php/chet/readline/CHANGES
267 @unittest.skipIf(readline._READLINE_VERSION < 0x600,
268 "this readline version does not support history-size")
280 # history_size * 2 items crashes readline
287 import readline
290 readline.read_history_file(history_file)
292 readline.write_history_file(history_file)