Show More
@@ -16,11 +16,13 b' import sys' | |||
|
16 | 16 | import nose.tools as nt |
|
17 | 17 | from IPython.utils.process import process_handler |
|
18 | 18 | from IPython.utils.tempdir import NamedFileInTemporaryDirectory |
|
19 | from IPython.testing.decorators import skip_win32 | |
|
19 | 20 | |
|
20 | 21 | #----------------------------------------------------------------------------- |
|
21 | 22 | # Tests |
|
22 | 23 | #----------------------------------------------------------------------------- |
|
23 | 24 | |
|
25 | ||
|
24 | 26 | _sample_embed = b""" |
|
25 | 27 | from __future__ import print_function |
|
26 | 28 | import IPython |
@@ -55,3 +57,69 b' def test_ipython_embed():' | |||
|
55 | 57 | nt.assert_in('IPython', std) |
|
56 | 58 | nt.assert_in('bye!', std) |
|
57 | 59 | |
|
60 | @skip_win32 | |
|
61 | def test_nest_embed(): | |
|
62 | """test that `IPython.embed()` is nestable""" | |
|
63 | from IPython.external import pexpect | |
|
64 | ipy_prompt = r']:' #ansi color codes give problems matching beyond this | |
|
65 | ||
|
66 | ||
|
67 | child = pexpect.spawn('%s -m IPython'%(sys.executable, )) | |
|
68 | child.expect(ipy_prompt) | |
|
69 | child.sendline("from __future__ import print_function") | |
|
70 | child.expect(ipy_prompt) | |
|
71 | child.sendline("import IPython") | |
|
72 | child.expect(ipy_prompt) | |
|
73 | child.sendline("ip0 = get_ipython()") | |
|
74 | #enter first nested embed | |
|
75 | child.sendline("IPython.embed()") | |
|
76 | #skip the banner until we get to a prompt | |
|
77 | try: | |
|
78 | prompted = -1 | |
|
79 | while prompted != 0: | |
|
80 | prompted = child.expect([ipy_prompt, '\r\n']) | |
|
81 | except pexpect.TIMEOUT as e: | |
|
82 | print(e) | |
|
83 | #child.interact() | |
|
84 | child.sendline("embed1 = get_ipython()"); child.expect(ipy_prompt) | |
|
85 | child.sendline("print('true' if embed1 is not ip0 else 'false')") | |
|
86 | assert(child.expect(['true\r\n', 'false\r\n']) == 0) | |
|
87 | child.expect(ipy_prompt) | |
|
88 | child.sendline("print('true' if IPython.get_ipython() is embed1 else 'false')") | |
|
89 | assert(child.expect(['true\r\n', 'false\r\n']) == 0) | |
|
90 | child.expect(ipy_prompt) | |
|
91 | #enter second nested embed | |
|
92 | child.sendline("IPython.embed()") | |
|
93 | #skip the banner until we get to a prompt | |
|
94 | try: | |
|
95 | prompted = -1 | |
|
96 | while prompted != 0: | |
|
97 | prompted = child.expect([ipy_prompt, '\r\n']) | |
|
98 | except pexpect.TIMEOUT as e: | |
|
99 | print(e) | |
|
100 | #child.interact() | |
|
101 | child.sendline("embed2 = get_ipython()"); child.expect(ipy_prompt) | |
|
102 | child.sendline("print('true' if embed2 is not embed1 else 'false')") | |
|
103 | assert(child.expect(['true\r\n', 'false\r\n']) == 0) | |
|
104 | child.expect(ipy_prompt) | |
|
105 | child.sendline("print('true' if embed2 is IPython.get_ipython() else 'false')") | |
|
106 | assert(child.expect(['true\r\n', 'false\r\n']) == 0) | |
|
107 | child.expect(ipy_prompt) | |
|
108 | child.sendline('exit') | |
|
109 | #back at first embed | |
|
110 | child.expect(ipy_prompt) | |
|
111 | child.sendline("print('true' if get_ipython() is embed1 else 'false')") | |
|
112 | assert(child.expect(['true\r\n', 'false\r\n']) == 0) | |
|
113 | child.expect(ipy_prompt) | |
|
114 | child.sendline("print('true' if IPython.get_ipython() is embed1 else 'false')") | |
|
115 | assert(child.expect(['true\r\n', 'false\r\n']) == 0) | |
|
116 | child.expect(ipy_prompt) | |
|
117 | child.sendline('exit') | |
|
118 | #back at launching scope | |
|
119 | child.expect(ipy_prompt) | |
|
120 | child.sendline("print('true' if get_ipython() is ip0 else 'false')") | |
|
121 | assert(child.expect(['true\r\n', 'false\r\n']) == 0) | |
|
122 | child.expect(ipy_prompt) | |
|
123 | child.sendline("print('true' if IPython.get_ipython() is ip0 else 'false')") | |
|
124 | assert(child.expect(['true\r\n', 'false\r\n']) == 0) | |
|
125 | child.expect(ipy_prompt) |
General Comments 0
You need to be logged in to leave comments.
Login now