pypy /pypy/module/_minimal_curses/test/test_curses.py

Language Python Lines 109
MD5 Hash eb4d5223204ca4f7b9547be8d5865c9c Estimated Cost $2,080 (why?)
Repository https://bitbucket.org/pypy/pypy/ View Raw File View Project SPDX
  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
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
from pypy import pypydir
from rpython.tool.udir import udir
import py
import sys
# tests here are run as snippets through a pexpected python subprocess


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

class TestCurses(object):
    """ We need to fork here, to prevent
    the setup to be done
    """
    def _spawn(self, *args, **kwds):
        import pexpect
        kwds.setdefault('timeout', 600)
        print 'SPAWN:', args, kwds
        child = pexpect.spawn(*args, **kwds)
        child.logfile = sys.stdout
        return child

    def spawn(self, argv):
        py_py = py.path.local(pypydir).join('bin', 'pyinteractive.py')
        return self._spawn(sys.executable, [str(py_py)] + argv)

    def setup_class(self):
        try:
            import pexpect
        except ImportError:
            py.test.skip('pexpect not found')

    def test_setupterm(self):
        source = py.code.Source("""
        import _minimal_curses
        try:
            _minimal_curses.tigetstr('cup')
        except _minimal_curses.error:
            print 'ok!'
        """)
        f = udir.join("test_setupterm.py")
        f.write(source)
        child = self.spawn(['--withmod-_minimal_curses', str(f)])
        child.expect('ok!')

    def test_tigetstr(self):
        source = py.code.Source("""
        import _minimal_curses
        _minimal_curses.setupterm()
        assert _minimal_curses.tigetstr('cup') == '\x1b[%i%p1%d;%p2%dH'
        print 'ok!'
        """)
        f = udir.join("test_tigetstr.py")
        f.write(source)
        child = self.spawn(['--withmod-_minimal_curses', str(f)])
        child.expect('ok!')

    def test_tparm(self):
        source = py.code.Source("""
        import _minimal_curses
        _minimal_curses.setupterm()
        assert _minimal_curses.tparm(_minimal_curses.tigetstr('cup'), 5, 3) == '\033[6;4H'
        print 'ok!'
        """)
        f = udir.join("test_tparm.py")
        f.write(source)
        child = self.spawn(['--withmod-_minimal_curses', str(f)])
        child.expect('ok!')

class TestCCurses(object):
    """ Test compiled version
    """
    def test_csetupterm(self):
        from rpython.translator.c.test.test_genc import compile
        from pypy.module._minimal_curses import interp_curses
        def runs_setupterm():
            interp_curses._curses_setupterm_null(1)

        fn = compile(runs_setupterm, [])
        fn()

    def test_ctgetstr(self):
        from rpython.translator.c.test.test_genc import compile
        from pypy.module._minimal_curses import interp_curses
        def runs_ctgetstr():
            interp_curses._curses_setupterm("xterm", 1)
            return interp_curses._curses_tigetstr('cup')

        fn = compile(runs_ctgetstr, [])
        res = fn()
        assert res == '\x1b[%i%p1%d;%p2%dH'

    def test_ctparm(self):
        from rpython.translator.c.test.test_genc import compile
        from pypy.module._minimal_curses import interp_curses
        def runs_tparm():
            interp_curses._curses_setupterm("xterm", 1)
            cup = interp_curses._curses_tigetstr('cup')
            return interp_curses._curses_tparm(cup, [5, 3])

        fn = compile(runs_tparm, [])
        res = fn()
        assert res == '\033[6;4H'
Back to Top