本文整理汇总了Python中accessories.TestTerminal.inkey方法的典型用法代码示例。如果您正苦于以下问题:Python TestTerminal.inkey方法的具体用法?Python TestTerminal.inkey怎么用?Python TestTerminal.inkey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类accessories.TestTerminal
的用法示例。
在下文中一共展示了TestTerminal.inkey方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_esc_delay_cbreak_timout_0
# 需要导入模块: from accessories import TestTerminal [as 别名]
# 或者: from accessories.TestTerminal import inkey [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)
示例2: test_inkey_0s_cbreak_multibyte_utf8
# 需要导入模块: from accessories import TestTerminal [as 别名]
# 或者: from accessories.TestTerminal import inkey [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
示例3: test_inkey_1s_cbreak_input
# 需要导入模块: from accessories import TestTerminal [as 别名]
# 或者: from accessories.TestTerminal import inkey [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
示例4: test_inkey_0s_cbreak_input
# 需要导入模块: from accessories import TestTerminal [as 别名]
# 或者: from accessories.TestTerminal import inkey [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 inkey [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: test_kbhit_interrupted_nonetype_no_continue
# 需要导入模块: from accessories import TestTerminal [as 别名]
# 或者: from accessories.TestTerminal import inkey [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
示例7: test_inkey_0s_raw_ctrl_c
# 需要导入模块: from accessories import TestTerminal [as 别名]
# 或者: from accessories.TestTerminal import inkey [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