Debian Codegraph @

pypy/module/test_lib_pypy/test_curses.py

raw symbols SCIP
1 import pytest
2 import sys
3 if sys.platform == 'win32':
4 #This module does not exist in windows
5 pytest.skip('no curses on windows')
6
7 # Check that lib_pypy.cffi finds the correct version of _cffi_backend.
8 # Otherwise, the test is skipped. It should never be skipped when run
9 # with "pypy py.test -A" and _curses_build.py has been run with pypy.
10 try:
11 from lib_pypy import _curses_cffi
12 except ImportError:
13 # On CPython, "pip install cffi". On old PyPy's, no chance
14 pytest.skip("install cffi and run lib_pypy/_curses_build.py manually first")
15
16 from lib_pypy import _curses
17
18
19 lib = _curses.lib
20
21
22 def test_color_content(monkeypatch):
23 class patched:
24 OK = lib.OK
25 ERR = lib.ERR
26 def color_content(self, color, r, g, b):
27 r[0], g[0], b[0] = 42, 43, 44
28 return lib.OK
29 monkeypatch.setattr(_curses, '_ensure_initialised_color', lambda: None)
30 monkeypatch.setattr(_curses, 'lib', patched())
31
32 assert _curses.color_content(None) == (42, 43, 44)
33
34
35 def test_setupterm(monkeypatch):
36 class make_setupterm:
37 OK = lib.OK
38 ERR = lib.ERR
39 def __init__(self, err_no):
40 self.err_no = err_no
41 def setupterm(self, term, fd, err):
42 err[0] = self.err_no
43 return lib.ERR
44
45 monkeypatch.setattr(_curses, '_initialised_setupterm', False)
46 monkeypatch.setattr(_curses, 'lib', make_setupterm(0))
47
48 with pytest.raises(Exception) as exc_info:
49 _curses.setupterm()
50
51 assert "could not find terminal" in exc_info.value.args[0]
52
53 monkeypatch.setattr(_curses, 'lib', make_setupterm(-1))
54
55 with pytest.raises(Exception) as exc_info:
56 _curses.setupterm()
57
58 assert "could not find terminfo database" in exc_info.value.args[0]
59
60 monkeypatch.setattr(_curses, 'lib', make_setupterm(42))
61
62 with pytest.raises(Exception) as exc_info:
63 _curses.setupterm()
64
65 assert "unknown error" in exc_info.value.args[0]