Show More
@@ -1,63 +1,100 | |||||
1 | """Tests for two-process terminal frontend |
|
1 | """Tests for two-process terminal frontend | |
2 |
|
2 | |||
3 | Currently only has the most simple test possible, starting a console and running |
|
3 | Currently only has the most simple test possible, starting a console and running | |
4 | a single command. |
|
4 | a single command. | |
5 |
|
5 | |||
6 | Authors: |
|
6 | Authors: | |
7 |
|
7 | |||
8 | * Min RK |
|
8 | * Min RK | |
9 | """ |
|
9 | """ | |
10 |
|
10 | |||
11 | #----------------------------------------------------------------------------- |
|
11 | #----------------------------------------------------------------------------- | |
12 | # Imports |
|
12 | # Imports | |
13 | #----------------------------------------------------------------------------- |
|
13 | #----------------------------------------------------------------------------- | |
14 |
|
14 | |||
15 | import sys |
|
15 | import sys | |
16 | import time |
|
16 | import time | |
17 |
|
17 | |||
18 | import nose.tools as nt |
|
18 | import nose.tools as nt | |
19 | from nose import SkipTest |
|
19 | from nose import SkipTest | |
20 |
|
20 | |||
21 | import IPython.testing.tools as tt |
|
21 | import IPython.testing.tools as tt | |
22 | from IPython.testing import decorators as dec |
|
22 | from IPython.testing import decorators as dec | |
23 | from IPython.utils import py3compat |
|
23 | from IPython.utils import py3compat | |
24 |
|
24 | |||
25 | #----------------------------------------------------------------------------- |
|
25 | #----------------------------------------------------------------------------- | |
26 | # Tests |
|
26 | # Tests | |
27 | #----------------------------------------------------------------------------- |
|
27 | #----------------------------------------------------------------------------- | |
28 |
|
28 | |||
29 | @dec.skip_win32 |
|
29 | @dec.skip_win32 | |
30 | def test_console_starts(): |
|
30 | def test_console_starts(): | |
31 | """test that `ipython console` starts a terminal""" |
|
31 | """test that `ipython console` starts a terminal""" | |
32 | from IPython.external import pexpect |
|
32 | from IPython.external import pexpect | |
33 |
|
33 | |||
34 | args = ['console', '--colors=NoColor'] |
|
34 | args = ['console', '--colors=NoColor'] | |
35 | # FIXME: remove workaround for 2.6 support |
|
35 | # FIXME: remove workaround for 2.6 support | |
36 | if sys.version_info[:2] > (2,6): |
|
36 | if sys.version_info[:2] > (2,6): | |
37 | args = ['-m', 'IPython'] + args |
|
37 | args = ['-m', 'IPython'] + args | |
38 | cmd = sys.executable |
|
38 | cmd = sys.executable | |
39 | else: |
|
39 | else: | |
40 | cmd = 'ipython' |
|
40 | cmd = 'ipython' | |
41 |
|
41 | |||
42 | try: |
|
42 | try: | |
43 | p = pexpect.spawn(cmd, args=args) |
|
43 | p = pexpect.spawn(cmd, args=args) | |
44 | except IOError: |
|
44 | except IOError: | |
45 | raise SkipTest("Couldn't find command %s" % cmd) |
|
45 | raise SkipTest("Couldn't find command %s" % cmd) | |
46 |
|
46 | |||
47 | # timeout after one minute |
|
47 | # timeout after one minute | |
48 | t = 60 |
|
48 | t = 60 | |
49 | idx = p.expect([r'In \[\d+\]', pexpect.EOF], timeout=t) |
|
49 | idx = p.expect([r'In \[\d+\]', pexpect.EOF], timeout=t) | |
50 | p.sendline('5') |
|
50 | p.sendline('5') | |
51 | idx = p.expect([r'Out\[\d+\]: 5', pexpect.EOF], timeout=t) |
|
51 | idx = p.expect([r'Out\[\d+\]: 5', pexpect.EOF], timeout=t) | |
52 | idx = p.expect([r'In \[\d+\]', pexpect.EOF], timeout=t) |
|
52 | idx = p.expect([r'In \[\d+\]', pexpect.EOF], timeout=t) | |
53 | # send ctrl-D;ctrl-D to exit |
|
53 | # send ctrl-D;ctrl-D to exit | |
54 | p.sendeof() |
|
54 | p.sendeof() | |
55 | p.sendeof() |
|
55 | p.sendeof() | |
56 | p.expect([pexpect.EOF, pexpect.TIMEOUT], timeout=t) |
|
56 | p.expect([pexpect.EOF, pexpect.TIMEOUT], timeout=t) | |
57 | if p.isalive(): |
|
57 | if p.isalive(): | |
58 | p.terminate() |
|
58 | p.terminate() | |
59 |
|
59 | |||
60 | def test_help_output(): |
|
60 | def test_help_output(): | |
61 | """ipython console --help-all works""" |
|
61 | """ipython console --help-all works""" | |
62 | tt.help_all_output_test('console') |
|
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