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


Python TestTerminal.cbreak方法代码示例

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


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

示例1: test_inkey_1s_cbreak_input

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

示例2: test_esc_delay_cbreak_timout_0

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

示例3: test_inkey_0s_cbreak_multibyte_utf8

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

示例4: test_inkey_0s_cbreak_input

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

示例5: child

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

示例6: child

# 需要导入模块: from accessories import TestTerminal [as 别名]
# 或者: from accessories.TestTerminal import cbreak [as 别名]
 def child():
     with tempfile.NamedTemporaryFile() as stream:
         term = TestTerminal(stream=stream)
         with mock.patch("tty.setcbreak") as mock_setcbreak:
             with term.cbreak():
                 assert not mock_setcbreak.called
             assert term.keyboard_fd is None
开发者ID:lowks,项目名称:blessed,代码行数:9,代码来源:test_keyboard.py


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