test_console.py
83 lines
| 2.3 KiB
| text/x-python
|
PythonLexer
MinRK
|
r5630 | """Tests for two-process terminal frontend | ||
MinRK
|
r11357 | Currently only has the most simple test possible, starting a console and running | ||
MinRK
|
r5630 | a single command. | ||
Authors: | ||||
* Min RK | ||||
""" | ||||
#----------------------------------------------------------------------------- | ||||
# Imports | ||||
#----------------------------------------------------------------------------- | ||||
MinRK
|
r11357 | import sys | ||
MinRK
|
r5630 | |||
from nose import SkipTest | ||||
MinRK
|
r12354 | import IPython.testing.tools as tt | ||
MinRK
|
r5630 | from IPython.testing import decorators as dec | ||
#----------------------------------------------------------------------------- | ||||
MinRK
|
r12354 | # Tests | ||
MinRK
|
r5630 | #----------------------------------------------------------------------------- | ||
@dec.skip_win32 | ||||
def test_console_starts(): | ||||
"""test that `ipython console` starts a terminal""" | ||||
Paul Ivanov
|
r13819 | p, pexpect, t = start_console() | ||
MinRK
|
r5630 | p.sendline('5') | ||
MinRK
|
r11796 | idx = p.expect([r'Out\[\d+\]: 5', pexpect.EOF], timeout=t) | ||
idx = p.expect([r'In \[\d+\]', pexpect.EOF], timeout=t) | ||||
Paul Ivanov
|
r13819 | stop_console(p, pexpect, t) | ||
MinRK
|
r12354 | |||
def test_help_output(): | ||||
"""ipython console --help-all works""" | ||||
tt.help_all_output_test('console') | ||||
Paul Ivanov
|
r13818 | |||
def test_display_text(): | ||||
"Ensure display protocol plain/text key is supported" | ||||
# equivalent of: | ||||
# | ||||
# x = %lsmagic | ||||
# from IPython.display import display; display(x); | ||||
Paul Ivanov
|
r13819 | p, pexpect, t = start_console() | ||
p.sendline('x = %lsmagic') | ||||
idx = p.expect([r'In \[\d+\]', pexpect.EOF], timeout=t) | ||||
p.sendline('from IPython.display import display; display(x);') | ||||
p.expect([r'Available line magics:', pexpect.EOF], timeout=t) | ||||
stop_console(p, pexpect, t) | ||||
def stop_console(p, pexpect, t): | ||||
"Stop a running `ipython console` running via pexpect" | ||||
# send ctrl-D;ctrl-D to exit | ||||
p.sendeof() | ||||
p.sendeof() | ||||
p.expect([pexpect.EOF, pexpect.TIMEOUT], timeout=t) | ||||
if p.isalive(): | ||||
p.terminate() | ||||
Paul Ivanov
|
r13818 | |||
Paul Ivanov
|
r13819 | def start_console(): | ||
"Start `ipython console` using pexpect" | ||||
Paul Ivanov
|
r13818 | from IPython.external import pexpect | ||
args = ['console', '--colors=NoColor'] | ||||
# FIXME: remove workaround for 2.6 support | ||||
if sys.version_info[:2] > (2,6): | ||||
args = ['-m', 'IPython'] + args | ||||
cmd = sys.executable | ||||
else: | ||||
cmd = 'ipython' | ||||
try: | ||||
p = pexpect.spawn(cmd, args=args) | ||||
except IOError: | ||||
raise SkipTest("Couldn't find command %s" % cmd) | ||||
# timeout after one minute | ||||
t = 60 | ||||
idx = p.expect([r'In \[\d+\]', pexpect.EOF], timeout=t) | ||||
Paul Ivanov
|
r13819 | return p, pexpect, t | ||