File: test_readline.py

package info (click to toggle)
pypy3 7.0.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 111,848 kB
  • sloc: python: 1,291,746; ansic: 74,281; asm: 5,187; cpp: 3,017; sh: 2,533; makefile: 544; xml: 243; lisp: 45; csh: 21; awk: 4
file content (42 lines) | stat: -rw-r--r-- 1,474 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# -*- coding: utf-8 -*-

class AppTestReadline:
    spaceconfig = dict(usemodules={
        'unicodedata', 'termios', 'select', 'signal', 'fcntl',
        '_minimal_curses', 'faulthandler', '_socket', 'binascii',
        '_posixsubprocess',
    })

    def test_nonascii_history(self):
        import os, readline
        TESTFN = "{}_{}_tmp".format("@test", os.getpid())

        is_editline = readline.__doc__ and "libedit" in readline.__doc__

        readline.clear_history()
        try:
            readline.add_history("entrée 1")
        except UnicodeEncodeError as err:
            skip("Locale cannot encode test data: " + format(err))
        readline.add_history("entrée 2")
        readline.replace_history_item(1, "entrée 22")
        readline.write_history_file(TESTFN)
        readline.clear_history()
        readline.read_history_file(TESTFN)
        if is_editline:
            # An add_history() call seems to be required for get_history_
            # item() to register items from the file
            readline.add_history("dummy")
        assert readline.get_history_item(1) ==  "entrée 1"
        assert readline.get_history_item(2) == "entrée 22"


    def test_insert_text_leading_tab(self):
        """
        A literal tab can be inserted at the beginning of a line.

        See <https://bugs.python.org/issue25660>
        """
        import readline
        readline.insert_text("\t")
        assert readline.get_line_buffer() == b"\t"