File: test_curses.py

package info (click to toggle)
pypy3 7.3.19%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 212,236 kB
  • sloc: python: 2,098,316; ansic: 540,565; sh: 21,462; asm: 14,419; cpp: 4,451; makefile: 4,209; objc: 761; xml: 530; exp: 499; javascript: 314; pascal: 244; lisp: 45; csh: 12; awk: 4
file content (65 lines) | stat: -rw-r--r-- 1,950 bytes parent folder | download | duplicates (8)
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
57
58
59
60
61
62
63
64
65
import pytest
import sys
if sys.platform == 'win32':
    #This module does not exist in windows
    pytest.skip('no curses on windows')

# Check that lib_pypy.cffi finds the correct version of _cffi_backend.
# Otherwise, the test is skipped.  It should never be skipped when run
# with "pypy py.test -A" and _curses_build.py has been run with pypy.
try:
    from lib_pypy import _curses_cffi
except ImportError:
    # On CPython, "pip install cffi".  On old PyPy's, no chance
    pytest.skip("install cffi and run lib_pypy/_curses_build.py manually first")

from lib_pypy import _curses


lib = _curses.lib


def test_color_content(monkeypatch):
    class patched:
        OK = lib.OK
        ERR = lib.ERR
        def color_content(self, color, r, g, b):
            r[0], g[0], b[0] = 42, 43, 44
            return lib.OK
    monkeypatch.setattr(_curses, '_ensure_initialised_color', lambda: None)
    monkeypatch.setattr(_curses, 'lib', patched())

    assert _curses.color_content(None) == (42, 43, 44)


def test_setupterm(monkeypatch):
    class make_setupterm:
        OK = lib.OK
        ERR = lib.ERR
        def __init__(self, err_no):
            self.err_no = err_no
        def setupterm(self, term, fd, err):
            err[0] = self.err_no
            return lib.ERR

    monkeypatch.setattr(_curses, '_initialised_setupterm', False)
    monkeypatch.setattr(_curses, 'lib', make_setupterm(0))

    with pytest.raises(Exception) as exc_info:
        _curses.setupterm()

    assert "could not find terminal" in exc_info.value.args[0]

    monkeypatch.setattr(_curses, 'lib', make_setupterm(-1))

    with pytest.raises(Exception) as exc_info:
        _curses.setupterm()

    assert "could not find terminfo database" in exc_info.value.args[0]

    monkeypatch.setattr(_curses, 'lib', make_setupterm(42))

    with pytest.raises(Exception) as exc_info:
        _curses.setupterm()

    assert "unknown error" in exc_info.value.args[0]