Show More
@@ -1,385 +1,380 b'' | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 | """Test Parallel magics |
|
2 | """Test Parallel magics | |
3 |
|
3 | |||
4 | Authors: |
|
4 | Authors: | |
5 |
|
5 | |||
6 | * Min RK |
|
6 | * Min RK | |
7 | """ |
|
7 | """ | |
8 | #------------------------------------------------------------------------------- |
|
8 | #------------------------------------------------------------------------------- | |
9 | # Copyright (C) 2011 The IPython Development Team |
|
9 | # Copyright (C) 2011 The IPython Development Team | |
10 | # |
|
10 | # | |
11 | # Distributed under the terms of the BSD License. The full license is in |
|
11 | # Distributed under the terms of the BSD License. The full license is in | |
12 | # the file COPYING, distributed as part of this software. |
|
12 | # the file COPYING, distributed as part of this software. | |
13 | #------------------------------------------------------------------------------- |
|
13 | #------------------------------------------------------------------------------- | |
14 |
|
14 | |||
15 | #------------------------------------------------------------------------------- |
|
15 | #------------------------------------------------------------------------------- | |
16 | # Imports |
|
16 | # Imports | |
17 | #------------------------------------------------------------------------------- |
|
17 | #------------------------------------------------------------------------------- | |
18 |
|
18 | |||
19 | import re |
|
19 | import re | |
20 | import sys |
|
20 | import sys | |
21 | import time |
|
21 | import time | |
22 |
|
22 | |||
23 | import zmq |
|
23 | import zmq | |
24 | from nose import SkipTest |
|
24 | from nose import SkipTest | |
25 |
|
25 | |||
26 | from IPython.testing import decorators as dec |
|
26 | from IPython.testing import decorators as dec | |
27 | from IPython.testing.ipunittest import ParametricTestCase |
|
27 | from IPython.testing.ipunittest import ParametricTestCase | |
28 | from IPython.utils.io import capture_output |
|
28 | from IPython.utils.io import capture_output | |
29 |
|
29 | |||
30 | from IPython import parallel as pmod |
|
30 | from IPython import parallel as pmod | |
31 | from IPython.parallel import error |
|
31 | from IPython.parallel import error | |
32 | from IPython.parallel import AsyncResult |
|
32 | from IPython.parallel import AsyncResult | |
33 | from IPython.parallel.util import interactive |
|
33 | from IPython.parallel.util import interactive | |
34 |
|
34 | |||
35 | from IPython.parallel.tests import add_engines |
|
35 | from IPython.parallel.tests import add_engines | |
36 |
|
36 | |||
37 | from .clienttest import ClusterTestCase, generate_output |
|
37 | from .clienttest import ClusterTestCase, generate_output | |
38 |
|
38 | |||
39 | def setup(): |
|
39 | def setup(): | |
40 | add_engines(3, total=True) |
|
40 | add_engines(3, total=True) | |
41 |
|
41 | |||
42 | class TestParallelMagics(ClusterTestCase, ParametricTestCase): |
|
42 | class TestParallelMagics(ClusterTestCase, ParametricTestCase): | |
43 |
|
43 | |||
44 | def test_px_blocking(self): |
|
44 | def test_px_blocking(self): | |
45 | ip = get_ipython() |
|
45 | ip = get_ipython() | |
46 | v = self.client[-1:] |
|
46 | v = self.client[-1:] | |
47 | v.activate() |
|
47 | v.activate() | |
48 | v.block=True |
|
48 | v.block=True | |
49 |
|
49 | |||
50 | ip.magic('px a=5') |
|
50 | ip.magic('px a=5') | |
51 | self.assertEqual(v['a'], [5]) |
|
51 | self.assertEqual(v['a'], [5]) | |
52 | ip.magic('px a=10') |
|
52 | ip.magic('px a=10') | |
53 | self.assertEqual(v['a'], [10]) |
|
53 | self.assertEqual(v['a'], [10]) | |
54 | # just 'print a' works ~99% of the time, but this ensures that |
|
54 | # just 'print a' works ~99% of the time, but this ensures that | |
55 | # the stdout message has arrived when the result is finished: |
|
55 | # the stdout message has arrived when the result is finished: | |
56 | with capture_output() as io: |
|
56 | with capture_output() as io: | |
57 | ip.magic( |
|
57 | ip.magic( | |
58 | 'px import sys,time;print(a);sys.stdout.flush();time.sleep(0.2)' |
|
58 | 'px import sys,time;print(a);sys.stdout.flush();time.sleep(0.2)' | |
59 | ) |
|
59 | ) | |
60 |
|
|
60 | self.assertIn('[stdout:', io.stdout) | |
61 |
self.assert |
|
61 | self.assertNotIn('\n\n', io.stdout) | |
62 | self.assertFalse('\n\n' in out) |
|
62 | assert io.stdout.rstrip().endswith('10') | |
63 | self.assertTrue(out.rstrip().endswith('10')) |
|
|||
64 | self.assertRaisesRemote(ZeroDivisionError, ip.magic, 'px 1/0') |
|
63 | self.assertRaisesRemote(ZeroDivisionError, ip.magic, 'px 1/0') | |
65 |
|
64 | |||
66 | def _check_generated_stderr(self, stderr, n): |
|
65 | def _check_generated_stderr(self, stderr, n): | |
67 | expected = [ |
|
66 | expected = [ | |
68 | r'\[stderr:\d+\]', |
|
67 | r'\[stderr:\d+\]', | |
69 | '^stderr$', |
|
68 | '^stderr$', | |
70 | '^stderr2$', |
|
69 | '^stderr2$', | |
71 | ] * n |
|
70 | ] * n | |
72 |
|
71 | |||
73 |
self.assert |
|
72 | self.assertNotIn('\n\n', stderr) | |
74 | lines = stderr.splitlines() |
|
73 | lines = stderr.splitlines() | |
75 | self.assertEqual(len(lines), len(expected), stderr) |
|
74 | self.assertEqual(len(lines), len(expected), stderr) | |
76 | for line,expect in zip(lines, expected): |
|
75 | for line,expect in zip(lines, expected): | |
77 | if isinstance(expect, str): |
|
76 | if isinstance(expect, str): | |
78 | expect = [expect] |
|
77 | expect = [expect] | |
79 | for ex in expect: |
|
78 | for ex in expect: | |
80 |
|
|
79 | assert re.search(ex, line) is not None, "Expected %r in %r" % (ex, line) | |
81 |
|
80 | |||
82 | def test_cellpx_block_args(self): |
|
81 | def test_cellpx_block_args(self): | |
83 | """%%px --[no]block flags work""" |
|
82 | """%%px --[no]block flags work""" | |
84 | ip = get_ipython() |
|
83 | ip = get_ipython() | |
85 | v = self.client[-1:] |
|
84 | v = self.client[-1:] | |
86 | v.activate() |
|
85 | v.activate() | |
87 | v.block=False |
|
86 | v.block=False | |
88 |
|
87 | |||
89 | for block in (True, False): |
|
88 | for block in (True, False): | |
90 | v.block = block |
|
89 | v.block = block | |
91 | ip.magic("pxconfig --verbose") |
|
90 | ip.magic("pxconfig --verbose") | |
92 | with capture_output() as io: |
|
91 | with capture_output(display=False) as io: | |
93 | ip.run_cell_magic("px", "", "1") |
|
92 | ip.run_cell_magic("px", "", "1") | |
94 | if block: |
|
93 | if block: | |
95 |
|
|
94 | assert io.stdout.startswith("Parallel"), io.stdout | |
96 | else: |
|
95 | else: | |
97 |
|
|
96 | assert io.stdout.startswith("Async"), io.stdout | |
98 |
|
97 | |||
99 | with capture_output() as io: |
|
98 | with capture_output(display=False) as io: | |
100 | ip.run_cell_magic("px", "--block", "1") |
|
99 | ip.run_cell_magic("px", "--block", "1") | |
101 |
|
|
100 | assert io.stdout.startswith("Parallel"), io.stdout | |
102 |
|
101 | |||
103 | with capture_output() as io: |
|
102 | with capture_output(display=False) as io: | |
104 | ip.run_cell_magic("px", "--noblock", "1") |
|
103 | ip.run_cell_magic("px", "--noblock", "1") | |
105 |
|
|
104 | assert io.stdout.startswith("Async"), io.stdout | |
106 |
|
105 | |||
107 | def test_cellpx_groupby_engine(self): |
|
106 | def test_cellpx_groupby_engine(self): | |
108 | """%%px --group-outputs=engine""" |
|
107 | """%%px --group-outputs=engine""" | |
109 | ip = get_ipython() |
|
108 | ip = get_ipython() | |
110 | v = self.client[:] |
|
109 | v = self.client[:] | |
111 | v.block = True |
|
110 | v.block = True | |
112 | v.activate() |
|
111 | v.activate() | |
113 |
|
112 | |||
114 | v['generate_output'] = generate_output |
|
113 | v['generate_output'] = generate_output | |
115 |
|
114 | |||
116 | with capture_output() as io: |
|
115 | with capture_output(display=False) as io: | |
117 | ip.run_cell_magic('px', '--group-outputs=engine', 'generate_output()') |
|
116 | ip.run_cell_magic('px', '--group-outputs=engine', 'generate_output()') | |
118 |
|
117 | |||
119 |
self.assert |
|
118 | self.assertNotIn('\n\n', io.stdout) | |
120 | lines = io.stdout.splitlines() |
|
119 | lines = io.stdout.splitlines() | |
121 | expected = [ |
|
120 | expected = [ | |
122 | r'\[stdout:\d+\]', |
|
121 | r'\[stdout:\d+\]', | |
123 | 'stdout', |
|
122 | 'stdout', | |
124 | 'stdout2', |
|
123 | 'stdout2', | |
125 | r'\[output:\d+\]', |
|
124 | r'\[output:\d+\]', | |
126 | r'IPython\.core\.display\.HTML', |
|
125 | r'IPython\.core\.display\.HTML', | |
127 | r'IPython\.core\.display\.Math', |
|
126 | r'IPython\.core\.display\.Math', | |
128 | r'Out\[\d+:\d+\]:.*IPython\.core\.display\.Math', |
|
127 | r'Out\[\d+:\d+\]:.*IPython\.core\.display\.Math', | |
129 | ] * len(v) |
|
128 | ] * len(v) | |
130 |
|
129 | |||
131 | self.assertEqual(len(lines), len(expected), io.stdout) |
|
130 | self.assertEqual(len(lines), len(expected), io.stdout) | |
132 | for line,expect in zip(lines, expected): |
|
131 | for line,expect in zip(lines, expected): | |
133 | if isinstance(expect, str): |
|
132 | if isinstance(expect, str): | |
134 | expect = [expect] |
|
133 | expect = [expect] | |
135 | for ex in expect: |
|
134 | for ex in expect: | |
136 |
|
|
135 | assert re.search(ex, line) is not None, "Expected %r in %r" % (ex, line) | |
137 |
|
136 | |||
138 | self._check_generated_stderr(io.stderr, len(v)) |
|
137 | self._check_generated_stderr(io.stderr, len(v)) | |
139 |
|
138 | |||
140 |
|
139 | |||
141 | def test_cellpx_groupby_order(self): |
|
140 | def test_cellpx_groupby_order(self): | |
142 | """%%px --group-outputs=order""" |
|
141 | """%%px --group-outputs=order""" | |
143 | ip = get_ipython() |
|
142 | ip = get_ipython() | |
144 | v = self.client[:] |
|
143 | v = self.client[:] | |
145 | v.block = True |
|
144 | v.block = True | |
146 | v.activate() |
|
145 | v.activate() | |
147 |
|
146 | |||
148 | v['generate_output'] = generate_output |
|
147 | v['generate_output'] = generate_output | |
149 |
|
148 | |||
150 | with capture_output() as io: |
|
149 | with capture_output(display=False) as io: | |
151 | ip.run_cell_magic('px', '--group-outputs=order', 'generate_output()') |
|
150 | ip.run_cell_magic('px', '--group-outputs=order', 'generate_output()') | |
152 |
|
151 | |||
153 |
self.assert |
|
152 | self.assertNotIn('\n\n', io.stdout) | |
154 | lines = io.stdout.splitlines() |
|
153 | lines = io.stdout.splitlines() | |
155 | expected = [] |
|
154 | expected = [] | |
156 | expected.extend([ |
|
155 | expected.extend([ | |
157 | r'\[stdout:\d+\]', |
|
156 | r'\[stdout:\d+\]', | |
158 | 'stdout', |
|
157 | 'stdout', | |
159 | 'stdout2', |
|
158 | 'stdout2', | |
160 | ] * len(v)) |
|
159 | ] * len(v)) | |
161 | expected.extend([ |
|
160 | expected.extend([ | |
162 | r'\[output:\d+\]', |
|
161 | r'\[output:\d+\]', | |
163 | 'IPython.core.display.HTML', |
|
162 | 'IPython.core.display.HTML', | |
164 | ] * len(v)) |
|
163 | ] * len(v)) | |
165 | expected.extend([ |
|
164 | expected.extend([ | |
166 | r'\[output:\d+\]', |
|
165 | r'\[output:\d+\]', | |
167 | 'IPython.core.display.Math', |
|
166 | 'IPython.core.display.Math', | |
168 | ] * len(v)) |
|
167 | ] * len(v)) | |
169 | expected.extend([ |
|
168 | expected.extend([ | |
170 | r'Out\[\d+:\d+\]:.*IPython\.core\.display\.Math' |
|
169 | r'Out\[\d+:\d+\]:.*IPython\.core\.display\.Math' | |
171 | ] * len(v)) |
|
170 | ] * len(v)) | |
172 |
|
171 | |||
173 | self.assertEqual(len(lines), len(expected), io.stdout) |
|
172 | self.assertEqual(len(lines), len(expected), io.stdout) | |
174 | for line,expect in zip(lines, expected): |
|
173 | for line,expect in zip(lines, expected): | |
175 | if isinstance(expect, str): |
|
174 | if isinstance(expect, str): | |
176 | expect = [expect] |
|
175 | expect = [expect] | |
177 | for ex in expect: |
|
176 | for ex in expect: | |
178 |
|
|
177 | assert re.search(ex, line) is not None, "Expected %r in %r" % (ex, line) | |
179 |
|
178 | |||
180 | self._check_generated_stderr(io.stderr, len(v)) |
|
179 | self._check_generated_stderr(io.stderr, len(v)) | |
181 |
|
180 | |||
182 | def test_cellpx_groupby_type(self): |
|
181 | def test_cellpx_groupby_type(self): | |
183 | """%%px --group-outputs=type""" |
|
182 | """%%px --group-outputs=type""" | |
184 | ip = get_ipython() |
|
183 | ip = get_ipython() | |
185 | v = self.client[:] |
|
184 | v = self.client[:] | |
186 | v.block = True |
|
185 | v.block = True | |
187 | v.activate() |
|
186 | v.activate() | |
188 |
|
187 | |||
189 | v['generate_output'] = generate_output |
|
188 | v['generate_output'] = generate_output | |
190 |
|
189 | |||
191 | with capture_output() as io: |
|
190 | with capture_output(display=False) as io: | |
192 | ip.run_cell_magic('px', '--group-outputs=type', 'generate_output()') |
|
191 | ip.run_cell_magic('px', '--group-outputs=type', 'generate_output()') | |
193 |
|
192 | |||
194 |
self.assert |
|
193 | self.assertNotIn('\n\n', io.stdout) | |
195 | lines = io.stdout.splitlines() |
|
194 | lines = io.stdout.splitlines() | |
196 |
|
195 | |||
197 | expected = [] |
|
196 | expected = [] | |
198 | expected.extend([ |
|
197 | expected.extend([ | |
199 | r'\[stdout:\d+\]', |
|
198 | r'\[stdout:\d+\]', | |
200 | 'stdout', |
|
199 | 'stdout', | |
201 | 'stdout2', |
|
200 | 'stdout2', | |
202 | ] * len(v)) |
|
201 | ] * len(v)) | |
203 | expected.extend([ |
|
202 | expected.extend([ | |
204 | r'\[output:\d+\]', |
|
203 | r'\[output:\d+\]', | |
205 | r'IPython\.core\.display\.HTML', |
|
204 | r'IPython\.core\.display\.HTML', | |
206 | r'IPython\.core\.display\.Math', |
|
205 | r'IPython\.core\.display\.Math', | |
207 | ] * len(v)) |
|
206 | ] * len(v)) | |
208 | expected.extend([ |
|
207 | expected.extend([ | |
209 | (r'Out\[\d+:\d+\]', r'IPython\.core\.display\.Math') |
|
208 | (r'Out\[\d+:\d+\]', r'IPython\.core\.display\.Math') | |
210 | ] * len(v)) |
|
209 | ] * len(v)) | |
211 |
|
210 | |||
212 | self.assertEqual(len(lines), len(expected), io.stdout) |
|
211 | self.assertEqual(len(lines), len(expected), io.stdout) | |
213 | for line,expect in zip(lines, expected): |
|
212 | for line,expect in zip(lines, expected): | |
214 | if isinstance(expect, str): |
|
213 | if isinstance(expect, str): | |
215 | expect = [expect] |
|
214 | expect = [expect] | |
216 | for ex in expect: |
|
215 | for ex in expect: | |
217 |
|
|
216 | assert re.search(ex, line) is not None, "Expected %r in %r" % (ex, line) | |
218 |
|
217 | |||
219 | self._check_generated_stderr(io.stderr, len(v)) |
|
218 | self._check_generated_stderr(io.stderr, len(v)) | |
220 |
|
219 | |||
221 |
|
220 | |||
222 | def test_px_nonblocking(self): |
|
221 | def test_px_nonblocking(self): | |
223 | ip = get_ipython() |
|
222 | ip = get_ipython() | |
224 | v = self.client[-1:] |
|
223 | v = self.client[-1:] | |
225 | v.activate() |
|
224 | v.activate() | |
226 | v.block=False |
|
225 | v.block=False | |
227 |
|
226 | |||
228 | ip.magic('px a=5') |
|
227 | ip.magic('px a=5') | |
229 | self.assertEqual(v['a'], [5]) |
|
228 | self.assertEqual(v['a'], [5]) | |
230 | ip.magic('px a=10') |
|
229 | ip.magic('px a=10') | |
231 | self.assertEqual(v['a'], [10]) |
|
230 | self.assertEqual(v['a'], [10]) | |
232 | ip.magic('pxconfig --verbose') |
|
231 | ip.magic('pxconfig --verbose') | |
233 | with capture_output() as io: |
|
232 | with capture_output() as io: | |
234 | ar = ip.magic('px print (a)') |
|
233 | ar = ip.magic('px print (a)') | |
235 |
self.assert |
|
234 | self.assertIsInstance(ar, AsyncResult) | |
236 |
self.assert |
|
235 | self.assertIn('Async', io.stdout) | |
237 |
self.assert |
|
236 | self.assertNotIn('[stdout:', io.stdout) | |
238 |
self.assert |
|
237 | self.assertNotIn('\n\n', io.stdout) | |
239 |
|
238 | |||
240 | ar = ip.magic('px 1/0') |
|
239 | ar = ip.magic('px 1/0') | |
241 | self.assertRaisesRemote(ZeroDivisionError, ar.get) |
|
240 | self.assertRaisesRemote(ZeroDivisionError, ar.get) | |
242 |
|
241 | |||
243 | def test_autopx_blocking(self): |
|
242 | def test_autopx_blocking(self): | |
244 | ip = get_ipython() |
|
243 | ip = get_ipython() | |
245 | v = self.client[-1] |
|
244 | v = self.client[-1] | |
246 | v.activate() |
|
245 | v.activate() | |
247 | v.block=True |
|
246 | v.block=True | |
248 |
|
247 | |||
249 | with capture_output() as io: |
|
248 | with capture_output(display=False) as io: | |
250 | ip.magic('autopx') |
|
249 | ip.magic('autopx') | |
251 | ip.run_cell('\n'.join(('a=5','b=12345','c=0'))) |
|
250 | ip.run_cell('\n'.join(('a=5','b=12345','c=0'))) | |
252 | ip.run_cell('b*=2') |
|
251 | ip.run_cell('b*=2') | |
253 | ip.run_cell('print (b)') |
|
252 | ip.run_cell('print (b)') | |
254 | ip.run_cell('b') |
|
253 | ip.run_cell('b') | |
255 | ip.run_cell("b/c") |
|
254 | ip.run_cell("b/c") | |
256 | ip.magic('autopx') |
|
255 | ip.magic('autopx') | |
257 |
|
256 | |||
258 | output = io.stdout |
|
257 | output = io.stdout | |
259 |
|
258 | |||
260 |
|
|
259 | assert output.startswith('%autopx enabled'), output | |
261 |
|
|
260 | assert output.rstrip().endswith('%autopx disabled'), output | |
262 |
self.assert |
|
261 | self.assertIn('ZeroDivisionError', output) | |
263 |
self.assert |
|
262 | self.assertIn('\nOut[', output) | |
264 |
self.assert |
|
263 | self.assertIn(': 24690', output) | |
265 | ar = v.get_result(-1) |
|
264 | ar = v.get_result(-1) | |
266 | self.assertEqual(v['a'], 5) |
|
265 | self.assertEqual(v['a'], 5) | |
267 | self.assertEqual(v['b'], 24690) |
|
266 | self.assertEqual(v['b'], 24690) | |
268 | self.assertRaisesRemote(ZeroDivisionError, ar.get) |
|
267 | self.assertRaisesRemote(ZeroDivisionError, ar.get) | |
269 |
|
268 | |||
270 | def test_autopx_nonblocking(self): |
|
269 | def test_autopx_nonblocking(self): | |
271 | ip = get_ipython() |
|
270 | ip = get_ipython() | |
272 | v = self.client[-1] |
|
271 | v = self.client[-1] | |
273 | v.activate() |
|
272 | v.activate() | |
274 | v.block=False |
|
273 | v.block=False | |
275 |
|
274 | |||
276 | with capture_output() as io: |
|
275 | with capture_output() as io: | |
277 | ip.magic('autopx') |
|
276 | ip.magic('autopx') | |
278 | ip.run_cell('\n'.join(('a=5','b=10','c=0'))) |
|
277 | ip.run_cell('\n'.join(('a=5','b=10','c=0'))) | |
279 | ip.run_cell('print (b)') |
|
278 | ip.run_cell('print (b)') | |
280 | ip.run_cell('import time; time.sleep(0.1)') |
|
279 | ip.run_cell('import time; time.sleep(0.1)') | |
281 | ip.run_cell("b/c") |
|
280 | ip.run_cell("b/c") | |
282 | ip.run_cell('b*=2') |
|
281 | ip.run_cell('b*=2') | |
283 | ip.magic('autopx') |
|
282 | ip.magic('autopx') | |
284 |
|
283 | |||
285 | output = io.stdout.rstrip() |
|
284 | output = io.stdout.rstrip() | |
286 |
|
285 | |||
287 |
|
|
286 | assert output.startswith('%autopx enabled'), output | |
288 |
|
|
287 | assert output.endswith('%autopx disabled'), output | |
289 |
self.assert |
|
288 | self.assertNotIn('ZeroDivisionError', output) | |
290 | ar = v.get_result(-2) |
|
289 | ar = v.get_result(-2) | |
291 | self.assertRaisesRemote(ZeroDivisionError, ar.get) |
|
290 | self.assertRaisesRemote(ZeroDivisionError, ar.get) | |
292 | # prevent TaskAborted on pulls, due to ZeroDivisionError |
|
291 | # prevent TaskAborted on pulls, due to ZeroDivisionError | |
293 | time.sleep(0.5) |
|
292 | time.sleep(0.5) | |
294 | self.assertEqual(v['a'], 5) |
|
293 | self.assertEqual(v['a'], 5) | |
295 | # b*=2 will not fire, due to abort |
|
294 | # b*=2 will not fire, due to abort | |
296 | self.assertEqual(v['b'], 10) |
|
295 | self.assertEqual(v['b'], 10) | |
297 |
|
296 | |||
298 | def test_result(self): |
|
297 | def test_result(self): | |
299 | ip = get_ipython() |
|
298 | ip = get_ipython() | |
300 | v = self.client[-1] |
|
299 | v = self.client[-1] | |
301 | v.activate() |
|
300 | v.activate() | |
302 | data = dict(a=111,b=222) |
|
301 | data = dict(a=111,b=222) | |
303 | v.push(data, block=True) |
|
302 | v.push(data, block=True) | |
304 |
|
303 | |||
305 | for name in ('a', 'b'): |
|
304 | for name in ('a', 'b'): | |
306 | ip.magic('px ' + name) |
|
305 | ip.magic('px ' + name) | |
307 | with capture_output() as io: |
|
306 | with capture_output(display=False) as io: | |
308 | ip.magic('pxresult') |
|
307 | ip.magic('pxresult') | |
309 | output = io.stdout |
|
308 | self.assertIn(str(data[name]), io.stdout) | |
310 | msg = "expected %s output to include %s, but got: %s" % \ |
|
|||
311 | ('%pxresult', str(data[name]), output) |
|
|||
312 | self.assertTrue(str(data[name]) in output, msg) |
|
|||
313 |
|
309 | |||
314 | @dec.skipif_not_matplotlib |
|
310 | @dec.skipif_not_matplotlib | |
315 | def test_px_pylab(self): |
|
311 | def test_px_pylab(self): | |
316 | """%pylab works on engines""" |
|
312 | """%pylab works on engines""" | |
317 | ip = get_ipython() |
|
313 | ip = get_ipython() | |
318 | v = self.client[-1] |
|
314 | v = self.client[-1] | |
319 | v.block = True |
|
315 | v.block = True | |
320 | v.activate() |
|
316 | v.activate() | |
321 |
|
317 | |||
322 | with capture_output() as io: |
|
318 | with capture_output() as io: | |
323 | ip.magic("px %pylab inline") |
|
319 | ip.magic("px %pylab inline") | |
324 |
|
320 | |||
325 |
self.assert |
|
321 | self.assertIn("Populating the interactive namespace from numpy and matplotlib", io.stdout) | |
326 |
|
322 | |||
327 | with capture_output() as io: |
|
323 | with capture_output(display=False) as io: | |
328 | ip.magic("px plot(rand(100))") |
|
324 | ip.magic("px plot(rand(100))") | |
329 |
|
325 | self.assertIn('Out[', io.stdout) | ||
330 |
self.assert |
|
326 | self.assertIn('matplotlib.lines', io.stdout) | |
331 | self.assertTrue('matplotlib.lines' in io.stdout, io.stdout) |
|
|||
332 |
|
327 | |||
333 | def test_pxconfig(self): |
|
328 | def test_pxconfig(self): | |
334 | ip = get_ipython() |
|
329 | ip = get_ipython() | |
335 | rc = self.client |
|
330 | rc = self.client | |
336 | v = rc.activate(-1, '_tst') |
|
331 | v = rc.activate(-1, '_tst') | |
337 | self.assertEqual(v.targets, rc.ids[-1]) |
|
332 | self.assertEqual(v.targets, rc.ids[-1]) | |
338 | ip.magic("%pxconfig_tst -t :") |
|
333 | ip.magic("%pxconfig_tst -t :") | |
339 | self.assertEqual(v.targets, rc.ids) |
|
334 | self.assertEqual(v.targets, rc.ids) | |
340 | ip.magic("%pxconfig_tst -t ::2") |
|
335 | ip.magic("%pxconfig_tst -t ::2") | |
341 | self.assertEqual(v.targets, rc.ids[::2]) |
|
336 | self.assertEqual(v.targets, rc.ids[::2]) | |
342 | ip.magic("%pxconfig_tst -t 1::2") |
|
337 | ip.magic("%pxconfig_tst -t 1::2") | |
343 | self.assertEqual(v.targets, rc.ids[1::2]) |
|
338 | self.assertEqual(v.targets, rc.ids[1::2]) | |
344 | ip.magic("%pxconfig_tst -t 1") |
|
339 | ip.magic("%pxconfig_tst -t 1") | |
345 | self.assertEqual(v.targets, 1) |
|
340 | self.assertEqual(v.targets, 1) | |
346 | ip.magic("%pxconfig_tst --block") |
|
341 | ip.magic("%pxconfig_tst --block") | |
347 | self.assertEqual(v.block, True) |
|
342 | self.assertEqual(v.block, True) | |
348 | ip.magic("%pxconfig_tst --noblock") |
|
343 | ip.magic("%pxconfig_tst --noblock") | |
349 | self.assertEqual(v.block, False) |
|
344 | self.assertEqual(v.block, False) | |
350 |
|
345 | |||
351 | def test_cellpx_targets(self): |
|
346 | def test_cellpx_targets(self): | |
352 | """%%px --targets doesn't change defaults""" |
|
347 | """%%px --targets doesn't change defaults""" | |
353 | ip = get_ipython() |
|
348 | ip = get_ipython() | |
354 | rc = self.client |
|
349 | rc = self.client | |
355 | view = rc.activate(rc.ids) |
|
350 | view = rc.activate(rc.ids) | |
356 | self.assertEqual(view.targets, rc.ids) |
|
351 | self.assertEqual(view.targets, rc.ids) | |
357 | ip.magic('pxconfig --verbose') |
|
352 | ip.magic('pxconfig --verbose') | |
358 | for cell in ("pass", "1/0"): |
|
353 | for cell in ("pass", "1/0"): | |
359 | with capture_output() as io: |
|
354 | with capture_output(display=False) as io: | |
360 | try: |
|
355 | try: | |
361 | ip.run_cell_magic("px", "--targets all", cell) |
|
356 | ip.run_cell_magic("px", "--targets all", cell) | |
362 | except pmod.RemoteError: |
|
357 | except pmod.RemoteError: | |
363 | pass |
|
358 | pass | |
364 |
self.assert |
|
359 | self.assertIn('engine(s): all', io.stdout) | |
365 | self.assertEqual(view.targets, rc.ids) |
|
360 | self.assertEqual(view.targets, rc.ids) | |
366 |
|
361 | |||
367 |
|
362 | |||
368 | def test_cellpx_block(self): |
|
363 | def test_cellpx_block(self): | |
369 | """%%px --block doesn't change default""" |
|
364 | """%%px --block doesn't change default""" | |
370 | ip = get_ipython() |
|
365 | ip = get_ipython() | |
371 | rc = self.client |
|
366 | rc = self.client | |
372 | view = rc.activate(rc.ids) |
|
367 | view = rc.activate(rc.ids) | |
373 | view.block = False |
|
368 | view.block = False | |
374 | self.assertEqual(view.targets, rc.ids) |
|
369 | self.assertEqual(view.targets, rc.ids) | |
375 | ip.magic('pxconfig --verbose') |
|
370 | ip.magic('pxconfig --verbose') | |
376 | for cell in ("pass", "1/0"): |
|
371 | for cell in ("pass", "1/0"): | |
377 | with capture_output() as io: |
|
372 | with capture_output(display=False) as io: | |
378 | try: |
|
373 | try: | |
379 | ip.run_cell_magic("px", "--block", cell) |
|
374 | ip.run_cell_magic("px", "--block", cell) | |
380 | except pmod.RemoteError: |
|
375 | except pmod.RemoteError: | |
381 | pass |
|
376 | pass | |
382 |
self.assert |
|
377 | self.assertNotIn('Async', io.stdout) | |
383 |
self.assert |
|
378 | self.assertEqual(view.block, False) | |
384 |
|
379 | |||
385 |
|
380 |
General Comments 0
You need to be logged in to leave comments.
Login now