Debian Codegraph @

extra_tests/test_pyrepl/test_readline.py

raw symbols SCIP
1 import pytest
2
3 from .infrastructure import sane_term
4
5 import sys
6 from pyrepl import readline
7
8 @pytest.mark.skipif("os.name != 'posix' or 'darwin' in sys.platform or "
9 "'freebsd' in sys.platform")
10 def test_raw_input():
11 import os
12 import pty
13 from pyrepl.readline import _ReadlineWrapper
14
15 master, slave = pty.openpty()
16 readline_wrapper = _ReadlineWrapper(slave, slave)
17 os.write(master, b'input\n')
18
19 with sane_term():
20 result = readline_wrapper.input('prompt:')
21 assert result == 'input'
22 # A bytes string on python2, a unicode string on python3.
23 assert isinstance(result, str)
24
25 def test_get_line_buffer_is_str():
26 from pyrepl import readline
27 assert isinstance(readline.get_line_buffer(), str)
28
29 def test_nonascii_history():
30 import sys
31 import os
32 TESTFN = "{}_{}_tmp".format("@test", os.getpid())
33
34 is_editline = readline.__doc__ and "libedit" in readline.__doc__
35
36 readline.clear_history()
37 try:
38 readline.add_history("entrée 1")
39 except UnicodeEncodeError as err:
40 skip("Locale cannot encode test data: " + format(err))
41 readline.add_history("entrée 2")
42 readline.replace_history_item(1, "entrée 22")
43 readline.write_history_file(TESTFN)
44 readline.clear_history()
45 readline.read_history_file(TESTFN)
46 if is_editline:
47 # An add_history() call seems to be required for get_history_
48 # item() to register items from the file
49 readline.add_history("dummy")
50 assert readline.get_history_item(1) == "entrée 1"
51 assert readline.get_history_item(2) == "entrée 22"
52
53 def test_insert_text_leading_tab():
54 """
55 A literal tab can be inserted at the beginning of a line.
56
57 See <https://bugs.python.org/issue25660>
58 """
59 readline.insert_text("\t")
60 assert readline.get_line_buffer() == "\t"