File: test_readline.py

package info (click to toggle)
pypy3 7.3.11%2Bdfsg-2%2Bdeb12u3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 201,024 kB
  • sloc: python: 1,950,308; ansic: 517,580; sh: 21,417; asm: 14,419; cpp: 4,263; makefile: 4,228; objc: 761; xml: 530; exp: 499; javascript: 314; pascal: 244; lisp: 45; csh: 11; awk: 4
file content (56 lines) | stat: -rw-r--r-- 1,733 bytes parent folder | download | duplicates (2)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# -*- coding: utf-8 -*-
import sys
import pytest

def setup_module(mod):
    try:
        import curses
        curses.setupterm()
    except:
        pytest.skip("Cannot test this here")


class AppTestReadline:
    spaceconfig = dict(usemodules=[
        'unicodedata', 'select', 'signal', 
        '_minimal_curses', 'faulthandler', '_socket', 'binascii',
        '_posixsubprocess',
    ])
    if sys.platform == 'win32':
        pass
    else:
        spaceconfig['usemodules'] += ['fcntl', 'termios']

    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"