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


Python TestTerminal.raw方法代码示例

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


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

示例1: child

# 需要导入模块: from accessories import TestTerminal [as 别名]
# 或者: from accessories.TestTerminal import raw [as 别名]
 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,代码行数:9,代码来源:test_keyboard.py

示例2: test_kbhit_interrupted_nonetype_no_continue

# 需要导入模块: from accessories import TestTerminal [as 别名]
# 或者: from accessories.TestTerminal import raw [as 别名]
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,代码行数:45,代码来源:test_keyboard.py

示例3: test_inkey_0s_raw_ctrl_c

# 需要导入模块: from accessories import TestTerminal [as 别名]
# 或者: from accessories.TestTerminal import raw [as 别名]
def test_inkey_0s_raw_ctrl_c():
    "0-second inkey with raw allows receiving ^C."
    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)
        with term.raw():
            os.write(sys.__stdout__.fileno(), RECV_SEMAPHORE)
            inp = term.inkey(timeout=0)
            os.write(sys.__stdout__.fileno(), inp.encode('latin1'))
        if cov is not None:
            cov.stop()
            cov.save()
        os._exit(0)

    with echo_off(master_fd):
        os.write(master_fd, SEND_SEMAPHORE)
        # ensure child is in raw mode before sending ^C,
        read_until_semaphore(master_fd)
        os.write(master_fd, u'\x03'.encode('latin1'))
        stime = time.time()
        output = read_until_eof(master_fd)
    pid, status = os.waitpid(pid, 0)
    if os.environ.get('TRAVIS', None) is not None:
        # For some reason, setraw has no effect travis-ci,
        # is still accepts ^C, causing system exit on py26,
        # but exit 0 on py27, and either way on py33
        # .. strange, huh?
        assert output in (u'', u'\x03')
        assert os.WEXITSTATUS(status) in (0, 2)
    else:
        assert (output == u'\x03' or
                output == u'' and not os.isatty(0))
        assert os.WEXITSTATUS(status) == 0
    assert math.floor(time.time() - stime) == 0.0
开发者ID:0x37N0w4N,项目名称:MARA_Framework,代码行数:41,代码来源:test_keyboard.py


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