Show More
@@ -1,63 +1,100 | |||
|
1 | 1 | """Tests for two-process terminal frontend |
|
2 | 2 | |
|
3 | 3 | Currently only has the most simple test possible, starting a console and running |
|
4 | 4 | a single command. |
|
5 | 5 | |
|
6 | 6 | Authors: |
|
7 | 7 | |
|
8 | 8 | * Min RK |
|
9 | 9 | """ |
|
10 | 10 | |
|
11 | 11 | #----------------------------------------------------------------------------- |
|
12 | 12 | # Imports |
|
13 | 13 | #----------------------------------------------------------------------------- |
|
14 | 14 | |
|
15 | 15 | import sys |
|
16 | 16 | import time |
|
17 | 17 | |
|
18 | 18 | import nose.tools as nt |
|
19 | 19 | from nose import SkipTest |
|
20 | 20 | |
|
21 | 21 | import IPython.testing.tools as tt |
|
22 | 22 | from IPython.testing import decorators as dec |
|
23 | 23 | from IPython.utils import py3compat |
|
24 | 24 | |
|
25 | 25 | #----------------------------------------------------------------------------- |
|
26 | 26 | # Tests |
|
27 | 27 | #----------------------------------------------------------------------------- |
|
28 | 28 | |
|
29 | 29 | @dec.skip_win32 |
|
30 | 30 | def test_console_starts(): |
|
31 | 31 | """test that `ipython console` starts a terminal""" |
|
32 | 32 | from IPython.external import pexpect |
|
33 | 33 | |
|
34 | 34 | args = ['console', '--colors=NoColor'] |
|
35 | 35 | # FIXME: remove workaround for 2.6 support |
|
36 | 36 | if sys.version_info[:2] > (2,6): |
|
37 | 37 | args = ['-m', 'IPython'] + args |
|
38 | 38 | cmd = sys.executable |
|
39 | 39 | else: |
|
40 | 40 | cmd = 'ipython' |
|
41 | 41 | |
|
42 | 42 | try: |
|
43 | 43 | p = pexpect.spawn(cmd, args=args) |
|
44 | 44 | except IOError: |
|
45 | 45 | raise SkipTest("Couldn't find command %s" % cmd) |
|
46 | 46 | |
|
47 | 47 | # timeout after one minute |
|
48 | 48 | t = 60 |
|
49 | 49 | idx = p.expect([r'In \[\d+\]', pexpect.EOF], timeout=t) |
|
50 | 50 | p.sendline('5') |
|
51 | 51 | idx = p.expect([r'Out\[\d+\]: 5', pexpect.EOF], timeout=t) |
|
52 | 52 | idx = p.expect([r'In \[\d+\]', pexpect.EOF], timeout=t) |
|
53 | 53 | # send ctrl-D;ctrl-D to exit |
|
54 | 54 | p.sendeof() |
|
55 | 55 | p.sendeof() |
|
56 | 56 | p.expect([pexpect.EOF, pexpect.TIMEOUT], timeout=t) |
|
57 | 57 | if p.isalive(): |
|
58 | 58 | p.terminate() |
|
59 | 59 | |
|
60 | 60 | def test_help_output(): |
|
61 | 61 | """ipython console --help-all works""" |
|
62 | 62 | tt.help_all_output_test('console') |
|
63 | 63 | |
|
64 | ||
|
65 | def test_display_text(): | |
|
66 | "Ensure display protocol plain/text key is supported" | |
|
67 | # equivalent of: | |
|
68 | # | |
|
69 | # x = %lsmagic | |
|
70 | # from IPython.display import display; display(x); | |
|
71 | ||
|
72 | from IPython.external import pexpect | |
|
73 | ||
|
74 | args = ['console', '--colors=NoColor'] | |
|
75 | # FIXME: remove workaround for 2.6 support | |
|
76 | if sys.version_info[:2] > (2,6): | |
|
77 | args = ['-m', 'IPython'] + args | |
|
78 | cmd = sys.executable | |
|
79 | else: | |
|
80 | cmd = 'ipython' | |
|
81 | ||
|
82 | try: | |
|
83 | p = pexpect.spawn(cmd, args=args) | |
|
84 | except IOError: | |
|
85 | raise SkipTest("Couldn't find command %s" % cmd) | |
|
86 | ||
|
87 | # timeout after one minute | |
|
88 | t = 60 | |
|
89 | 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() |
General Comments 0
You need to be logged in to leave comments.
Login now