本文整理汇总了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
示例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)
示例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
示例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
示例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)
示例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