##// END OF EJS Templates
refactor starting and stopping pexpect
Paul Ivanov -
Show More
@@ -29,33 +29,11 from IPython.utils import py3compat
29 29 @dec.skip_win32
30 30 def test_console_starts():
31 31 """test that `ipython console` starts a terminal"""
32 from IPython.external import pexpect
33
34 args = ['console', '--colors=NoColor']
35 # FIXME: remove workaround for 2.6 support
36 if sys.version_info[:2] > (2,6):
37 args = ['-m', 'IPython'] + args
38 cmd = sys.executable
39 else:
40 cmd = 'ipython'
41
42 try:
43 p = pexpect.spawn(cmd, args=args)
44 except IOError:
45 raise SkipTest("Couldn't find command %s" % cmd)
46
47 # timeout after one minute
48 t = 60
49 idx = p.expect([r'In \[\d+\]', pexpect.EOF], timeout=t)
32 p, pexpect, t = start_console()
50 33 p.sendline('5')
51 34 idx = p.expect([r'Out\[\d+\]: 5', pexpect.EOF], timeout=t)
52 35 idx = p.expect([r'In \[\d+\]', pexpect.EOF], timeout=t)
53 # send ctrl-D;ctrl-D to exit
54 p.sendeof()
55 p.sendeof()
56 p.expect([pexpect.EOF, pexpect.TIMEOUT], timeout=t)
57 if p.isalive():
58 p.terminate()
36 stop_console(p, pexpect, t)
59 37
60 38 def test_help_output():
61 39 """ipython console --help-all works"""
@@ -68,7 +46,25 def test_display_text():
68 46 #
69 47 # x = %lsmagic
70 48 # from IPython.display import display; display(x);
49 p, pexpect, t = start_console()
50 p.sendline('x = %lsmagic')
51 idx = p.expect([r'In \[\d+\]', pexpect.EOF], timeout=t)
52 p.sendline('from IPython.display import display; display(x);')
53 p.expect([r'Available line magics:', pexpect.EOF], timeout=t)
54 stop_console(p, pexpect, t)
55
56 def stop_console(p, pexpect, t):
57 "Stop a running `ipython console` running via pexpect"
58 # send ctrl-D;ctrl-D to exit
59 p.sendeof()
60 p.sendeof()
61 p.expect([pexpect.EOF, pexpect.TIMEOUT], timeout=t)
62 if p.isalive():
63 p.terminate()
64
71 65
66 def start_console():
67 "Start `ipython console` using pexpect"
72 68 from IPython.external import pexpect
73 69
74 70 args = ['console', '--colors=NoColor']
@@ -87,14 +83,4 def test_display_text():
87 83 # timeout after one minute
88 84 t = 60
89 85 idx = p.expect([r'In \[\d+\]', pexpect.EOF], timeout=t)
90 p.sendline('x = %lsmagic')
91 idx = p.expect([r'In \[\d+\]', pexpect.EOF], timeout=t)
92 p.sendline('from IPython.display import display; display(x);')
93 p.expect([r'Available line magics:', pexpect.EOF], timeout=t)
94
95 # send ctrl-D;ctrl-D to exit
96 p.sendeof()
97 p.sendeof()
98 p.expect([pexpect.EOF, pexpect.TIMEOUT], timeout=t)
99 if p.isalive():
100 p.terminate()
86 return p, pexpect, t
General Comments 0
You need to be logged in to leave comments. Login now