当前位置: 首页>>代码示例>>Python>>正文


Python accessories.TestTerminal类代码示例

本文整理汇总了Python中accessories.TestTerminal的典型用法代码示例。如果您正苦于以下问题:Python TestTerminal类的具体用法?Python TestTerminal怎么用?Python TestTerminal使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了TestTerminal类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_esc_delay_cbreak_timout_0

def test_esc_delay_cbreak_timout_0():
    """esc_delay still in effect with timeout of 0 ("nonblocking")."""
    pid, master_fd = pty.fork()
    if pid is 0:  # child
        try:
            cov = __import__('cov_core_init').init()
        except ImportError:
            cov = None
        term = TestTerminal()
        os.write(sys.__stdout__.fileno(), SEMAPHORE)
        with term.cbreak():
            stime = time.time()
            inp = term.inkey(timeout=0)
            measured_time = (time.time() - stime) * 100
            os.write(sys.__stdout__.fileno(), (
                '%s %i' % (inp.name, measured_time,)).encode('ascii'))
            sys.stdout.flush()
        if cov is not None:
            cov.stop()
            cov.save()
        os._exit(0)

    with echo_off(master_fd):
        os.write(master_fd, u'\x1b'.encode('ascii'))
        read_until_semaphore(master_fd)
        stime = time.time()
        key_name, duration_ms = read_until_eof(master_fd).split()

    pid, status = os.waitpid(pid, 0)
    assert key_name == u'KEY_ESCAPE'
    assert os.WEXITSTATUS(status) == 0
    assert math.floor(time.time() - stime) == 0.0
    assert 35 <= int(duration_ms) <= 45, int(duration_ms)
开发者ID:0x37N0w4N,项目名称:MARA_Framework,代码行数:33,代码来源:test_keyboard.py

示例2: child

 def child(kind):
     t = TestTerminal(kind=kind, stream=StringIO())
     assert t._init_descriptor == sys.__stdout__.fileno()
     assert isinstance(t.height, int)
     assert isinstance(t.width, int)
     assert t.height == t._height_and_width()[0]
     assert t.width == t._height_and_width()[1]
开发者ID:AliMehrpour,项目名称:qark,代码行数:7,代码来源:test_core.py

示例3: child

 def child():
     term = TestTerminal(stream=StringIO.StringIO())
     with term.cbreak():
         stime = time.time()
         inp = term.inkey(timeout=1)
         assert (inp == u'')
         assert (math.floor(time.time() - stime) == 1.0)
开发者ID:0x37N0w4N,项目名称:MARA_Framework,代码行数:7,代码来源:test_keyboard.py

示例4: test_inkey_0s_cbreak_input

def test_inkey_0s_cbreak_input():
    "0-second inkey with input; Keypress should be immediately returned."
    pid, master_fd = pty.fork()
    if pid is 0:
        try:
            cov = __import__('cov_core_init').init()
        except ImportError:
            cov = None
        # child pauses, writes semaphore and begins awaiting input
        term = TestTerminal()
        read_until_semaphore(sys.__stdin__.fileno(), semaphore=SEMAPHORE)
        os.write(sys.__stdout__.fileno(), SEMAPHORE)
        with term.cbreak():
            inp = term.inkey(timeout=0)
            os.write(sys.__stdout__.fileno(), inp.encode('utf-8'))
        if cov is not None:
            cov.stop()
            cov.save()
        os._exit(0)

    with echo_off(master_fd):
        os.write(master_fd, SEND_SEMAPHORE)
        os.write(master_fd, u'x'.encode('ascii'))
        read_until_semaphore(master_fd)
        stime = time.time()
        output = read_until_eof(master_fd)

    pid, status = os.waitpid(pid, 0)
    assert output == u'x'
    assert os.WEXITSTATUS(status) == 0
    assert math.floor(time.time() - stime) == 0.0
开发者ID:0x37N0w4N,项目名称:MARA_Framework,代码行数:31,代码来源:test_keyboard.py

示例5: child_mnemonics_wontmove

 def child_mnemonics_wontmove(kind):
     from blessed.sequences import measure_length
     t = TestTerminal(kind=kind)
     assert (0 == measure_length(u'', t))
     # not even a mbs
     assert (0 == measure_length(u'xyzzy', t))
     # negative numbers, though printable as %d, do not result
     # in movement; just garbage. Also not a valid sequence.
     assert (0 == measure_length(t.cuf(-333), t))
     assert (len(t.clear_eol) == measure_length(t.clear_eol, t))
     # various erases don't *move*
     assert (len(t.clear_bol) == measure_length(t.clear_bol, t))
     assert (len(t.clear_eos) == measure_length(t.clear_eos, t))
     assert (len(t.bold) == measure_length(t.bold, t))
     # various paints don't move
     assert (len(t.red) == measure_length(t.red, t))
     assert (len(t.civis) == measure_length(t.civis, t))
     if t.cvvis:
         assert (len(t.cvvis) == measure_length(t.cvvis, t))
     assert (len(t.underline) == measure_length(t.underline, t))
     assert (len(t.reverse) == measure_length(t.reverse, t))
     for _num in range(t.number_of_colors):
         assert (len(t.color(_num)) == measure_length(t.color(_num), t))
     assert (len(t.normal) == measure_length(t.normal, t))
     assert (len(t.normal_cursor) == measure_length(t.normal_cursor, t))
     assert (len(t.hide_cursor) == measure_length(t.hide_cursor, t))
     assert (len(t.save) == measure_length(t.save, t))
     assert (len(t.italic) == measure_length(t.italic, t))
     assert (len(t.standout) == measure_length(t.standout, t)
             ), (t.standout, t._wont_move)
开发者ID:lowks,项目名称:blessed,代码行数:30,代码来源:test_length_sequence.py

示例6: test_inkey_0s_cbreak_multibyte_utf8

def test_inkey_0s_cbreak_multibyte_utf8():
    "0-second inkey with multibyte utf-8 input; should decode immediately."
    # utf-8 bytes represent "latin capital letter upsilon".
    pid, master_fd = pty.fork()
    if pid is 0:  # child
        try:
            cov = __import__('cov_core_init').init()
        except ImportError:
            cov = None
        term = TestTerminal()
        read_until_semaphore(sys.__stdin__.fileno(), semaphore=SEMAPHORE)
        os.write(sys.__stdout__.fileno(), SEMAPHORE)
        with term.cbreak():
            inp = term.inkey(timeout=0)
            os.write(sys.__stdout__.fileno(), inp.encode('utf-8'))
        if cov is not None:
            cov.stop()
            cov.save()
        os._exit(0)

    with echo_off(master_fd):
        os.write(master_fd, SEND_SEMAPHORE)
        os.write(master_fd, u'\u01b1'.encode('utf-8'))
        read_until_semaphore(master_fd)
        stime = time.time()
        output = read_until_eof(master_fd)
    pid, status = os.waitpid(pid, 0)
    assert output == u'Ʊ'
    assert os.WEXITSTATUS(status) == 0
    assert math.floor(time.time() - stime) == 0.0
开发者ID:0x37N0w4N,项目名称:MARA_Framework,代码行数:30,代码来源:test_keyboard.py

示例7: test_inkey_1s_cbreak_input

def test_inkey_1s_cbreak_input():
    "1-second inkey w/multibyte sequence; should return after ~1 second."
    pid, master_fd = pty.fork()
    if pid is 0:  # child
        try:
            cov = __import__('cov_core_init').init()
        except ImportError:
            cov = None
        term = TestTerminal()
        os.write(sys.__stdout__.fileno(), SEMAPHORE)
        with term.cbreak():
            inp = term.inkey(timeout=3)
            os.write(sys.__stdout__.fileno(), inp.name.encode('utf-8'))
            sys.stdout.flush()
        if cov is not None:
            cov.stop()
            cov.save()
        os._exit(0)

    with echo_off(master_fd):
        read_until_semaphore(master_fd)
        stime = time.time()
        time.sleep(1)
        os.write(master_fd, u'\x1b[C'.encode('ascii'))
        output = read_until_eof(master_fd)

    pid, status = os.waitpid(pid, 0)
    assert output == u'KEY_RIGHT'
    assert os.WEXITSTATUS(status) == 0
    assert math.floor(time.time() - stime) == 1.0
开发者ID:0x37N0w4N,项目名称:MARA_Framework,代码行数:30,代码来源:test_keyboard.py

示例8: child

 def child():
     with tempfile.NamedTemporaryFile() as stream:
         term = TestTerminal(stream=stream)
         with mock.patch("tty.setraw") as mock_setraw:
             with term.raw():
                 assert not mock_setraw.called
         assert term.keyboard_fd is None
开发者ID:lowks,项目名称:blessed,代码行数:7,代码来源:test_keyboard.py

示例9: child

    def child(kind):
        t = TestTerminal(kind=kind)
        # test simple sugar,
        if t.bold:
            expected_output = u''.join((t.bold, u'hi', t.normal))
        else:
            expected_output = u'hi'
        assert t.bold(u'hi') == expected_output
        # Plain strs for Python 2.x
        if t.green:
            expected_output = u''.join((t.green, 'hi', t.normal))
        else:
            expected_output = u'hi'
        assert t.green('hi') == expected_output
        # Test unicode
        if t.underline:
            expected_output = u''.join((t.underline, u'boö', t.normal))
        else:
            expected_output = u'boö'
        assert (t.underline(u'boö') == expected_output)

        if t.subscript:
            expected_output = u''.join((t.subscript, u'[1]', t.normal))
        else:
            expected_output = u'[1]'

        assert (t.subscript(u'[1]') == expected_output)
开发者ID:0x37N0w4N,项目名称:MARA_Framework,代码行数:27,代码来源:test_sequences.py

示例10: child

 def child():
     t = TestTerminal()
     try:
         my_wrapped = t.wrap(u'------- -------------', WIDTH)
     except ValueError, err:
         assert err.args[0] == (
             "invalid width %r(%s) (must be integer > 0)" % (
                 WIDTH, type(WIDTH)))
开发者ID:0x37N0w4N,项目名称:MARA_Framework,代码行数:8,代码来源:test_wrap.py

示例11: child_without_styling

    def child_without_styling():
        """No side effect for location as a context manager without styling."""
        t = TestTerminal(stream=StringIO(), force_styling=None)

        with t.location(3, 4):
            t.stream.write(u'hi')

        assert t.stream.getvalue() == u'hi'
开发者ID:0x37N0w4N,项目名称:MARA_Framework,代码行数:8,代码来源:test_sequences.py

示例12: child_with_styling

 def child_with_styling(kind):
     t = TestTerminal(kind=kind, stream=StringIO(), force_styling=True)
     with t.location(3, 4):
         t.stream.write(u'hi')
     expected_output = u''.join(
         (unicode_cap('sc'),
          unicode_parm('cup', 4, 3),
          u'hi', unicode_cap('rc')))
     assert (t.stream.getvalue() == expected_output)
开发者ID:0x37N0w4N,项目名称:MARA_Framework,代码行数:9,代码来源:test_sequences.py

示例13: child

    def child():
        term = TestTerminal(kind='xterm-256color')

        # given,
        given = term.bold_red(u'コンニチハ, セカイ!')
        expected = sum((2, 2, 2, 2, 2, 1, 1, 2, 2, 2, 1,))

        # exercise,
        assert term.length(given) == expected
开发者ID:lowks,项目名称:blessed,代码行数:9,代码来源:test_length_sequence.py

示例14: child_mnemonics_willmove

 def child_mnemonics_willmove(kind):
     from blessed.sequences import measure_length
     t = TestTerminal(kind=kind)
     # movements
     assert (len(t.move(98, 76)) ==
             measure_length(t.move(98, 76), t))
     assert (len(t.move(54)) ==
             measure_length(t.move(54), t))
     assert not t.cud1 or (len(t.cud1) ==
                           measure_length(t.cud1, t))
     assert not t.cub1 or (len(t.cub1) ==
                           measure_length(t.cub1, t))
     assert not t.cuf1 or (len(t.cuf1) ==
                           measure_length(t.cuf1, t))
     assert not t.cuu1 or (len(t.cuu1) ==
                           measure_length(t.cuu1, t))
     assert not t.cub or (len(t.cub(333)) ==
                          measure_length(t.cub(333), t))
     assert not t.cuf or (len(t.cuf(333)) ==
                          measure_length(t.cuf(333), t))
     assert not t.home or (len(t.home) ==
                           measure_length(t.home, t))
     assert not t.restore or (len(t.restore) ==
                              measure_length(t.restore, t))
     assert not t.clear or (len(t.clear) ==
                            measure_length(t.clear, t))
开发者ID:lowks,项目名称:blessed,代码行数:26,代码来源:test_length_sequence.py

示例15: test_kbhit_interrupted_nonetype_no_continue

def test_kbhit_interrupted_nonetype_no_continue():
    "kbhit() may be interrupted when _intr_continue=False with timeout None."
    pid, master_fd = pty.fork()
    if pid is 0:
        try:
            cov = __import__('cov_core_init').init()
        except ImportError:
            cov = None

        # child pauses, writes semaphore and begins awaiting input
        global got_sigwinch
        got_sigwinch = False

        def on_resize(sig, action):
            global got_sigwinch
            got_sigwinch = True

        term = TestTerminal()
        signal.signal(signal.SIGWINCH, on_resize)
        read_until_semaphore(sys.__stdin__.fileno(), semaphore=SEMAPHORE)
        os.write(sys.__stdout__.fileno(), SEMAPHORE)
        with term.raw():
            term.inkey(timeout=None, _intr_continue=False)
        os.write(sys.__stdout__.fileno(), b'complete')
        assert got_sigwinch is True
        if cov is not None:
            cov.stop()
            cov.save()
        os._exit(0)

    with echo_off(master_fd):
        os.write(master_fd, SEND_SEMAPHORE)
        read_until_semaphore(master_fd)
        stime = time.time()
        time.sleep(0.05)
        os.kill(pid, signal.SIGWINCH)
        os.write(master_fd, b'X')
        output = read_until_eof(master_fd)

    pid, status = os.waitpid(pid, 0)
    assert output == u'complete'
    assert os.WEXITSTATUS(status) == 0
    assert math.floor(time.time() - stime) == 0.0
开发者ID:0x37N0w4N,项目名称:MARA_Framework,代码行数:43,代码来源:test_keyboard.py


注:本文中的accessories.TestTerminal类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。