##// END OF EJS Templates
update px pylab test to match new output of pylab
Jens Hedegaard Nielsen -
Show More
@@ -1,386 +1,385 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 out = io.stdout
60 out = io.stdout
61 self.assertTrue('[stdout:' in out, out)
61 self.assertTrue('[stdout:' in out, out)
62 self.assertFalse('\n\n' in out)
62 self.assertFalse('\n\n' in out)
63 self.assertTrue(out.rstrip().endswith('10'))
63 self.assertTrue(out.rstrip().endswith('10'))
64 self.assertRaisesRemote(ZeroDivisionError, ip.magic, 'px 1/0')
64 self.assertRaisesRemote(ZeroDivisionError, ip.magic, 'px 1/0')
65
65
66 def _check_generated_stderr(self, stderr, n):
66 def _check_generated_stderr(self, stderr, n):
67 expected = [
67 expected = [
68 r'\[stderr:\d+\]',
68 r'\[stderr:\d+\]',
69 '^stderr$',
69 '^stderr$',
70 '^stderr2$',
70 '^stderr2$',
71 ] * n
71 ] * n
72
72
73 self.assertFalse('\n\n' in stderr, stderr)
73 self.assertFalse('\n\n' in stderr, stderr)
74 lines = stderr.splitlines()
74 lines = stderr.splitlines()
75 self.assertEqual(len(lines), len(expected), stderr)
75 self.assertEqual(len(lines), len(expected), stderr)
76 for line,expect in zip(lines, expected):
76 for line,expect in zip(lines, expected):
77 if isinstance(expect, str):
77 if isinstance(expect, str):
78 expect = [expect]
78 expect = [expect]
79 for ex in expect:
79 for ex in expect:
80 self.assertTrue(re.search(ex, line) is not None, "Expected %r in %r" % (ex, line))
80 self.assertTrue(re.search(ex, line) is not None, "Expected %r in %r" % (ex, line))
81
81
82 def test_cellpx_block_args(self):
82 def test_cellpx_block_args(self):
83 """%%px --[no]block flags work"""
83 """%%px --[no]block flags work"""
84 ip = get_ipython()
84 ip = get_ipython()
85 v = self.client[-1:]
85 v = self.client[-1:]
86 v.activate()
86 v.activate()
87 v.block=False
87 v.block=False
88
88
89 for block in (True, False):
89 for block in (True, False):
90 v.block = block
90 v.block = block
91 ip.magic("pxconfig --verbose")
91 ip.magic("pxconfig --verbose")
92 with capture_output() as io:
92 with capture_output() as io:
93 ip.run_cell_magic("px", "", "1")
93 ip.run_cell_magic("px", "", "1")
94 if block:
94 if block:
95 self.assertTrue(io.stdout.startswith("Parallel"), io.stdout)
95 self.assertTrue(io.stdout.startswith("Parallel"), io.stdout)
96 else:
96 else:
97 self.assertTrue(io.stdout.startswith("Async"), io.stdout)
97 self.assertTrue(io.stdout.startswith("Async"), io.stdout)
98
98
99 with capture_output() as io:
99 with capture_output() as io:
100 ip.run_cell_magic("px", "--block", "1")
100 ip.run_cell_magic("px", "--block", "1")
101 self.assertTrue(io.stdout.startswith("Parallel"), io.stdout)
101 self.assertTrue(io.stdout.startswith("Parallel"), io.stdout)
102
102
103 with capture_output() as io:
103 with capture_output() as io:
104 ip.run_cell_magic("px", "--noblock", "1")
104 ip.run_cell_magic("px", "--noblock", "1")
105 self.assertTrue(io.stdout.startswith("Async"), io.stdout)
105 self.assertTrue(io.stdout.startswith("Async"), io.stdout)
106
106
107 def test_cellpx_groupby_engine(self):
107 def test_cellpx_groupby_engine(self):
108 """%%px --group-outputs=engine"""
108 """%%px --group-outputs=engine"""
109 ip = get_ipython()
109 ip = get_ipython()
110 v = self.client[:]
110 v = self.client[:]
111 v.block = True
111 v.block = True
112 v.activate()
112 v.activate()
113
113
114 v['generate_output'] = generate_output
114 v['generate_output'] = generate_output
115
115
116 with capture_output() as io:
116 with capture_output() as io:
117 ip.run_cell_magic('px', '--group-outputs=engine', 'generate_output()')
117 ip.run_cell_magic('px', '--group-outputs=engine', 'generate_output()')
118
118
119 self.assertFalse('\n\n' in io.stdout)
119 self.assertFalse('\n\n' in io.stdout)
120 lines = io.stdout.splitlines()
120 lines = io.stdout.splitlines()
121 expected = [
121 expected = [
122 r'\[stdout:\d+\]',
122 r'\[stdout:\d+\]',
123 'stdout',
123 'stdout',
124 'stdout2',
124 'stdout2',
125 r'\[output:\d+\]',
125 r'\[output:\d+\]',
126 r'IPython\.core\.display\.HTML',
126 r'IPython\.core\.display\.HTML',
127 r'IPython\.core\.display\.Math',
127 r'IPython\.core\.display\.Math',
128 r'Out\[\d+:\d+\]:.*IPython\.core\.display\.Math',
128 r'Out\[\d+:\d+\]:.*IPython\.core\.display\.Math',
129 ] * len(v)
129 ] * len(v)
130
130
131 self.assertEqual(len(lines), len(expected), io.stdout)
131 self.assertEqual(len(lines), len(expected), io.stdout)
132 for line,expect in zip(lines, expected):
132 for line,expect in zip(lines, expected):
133 if isinstance(expect, str):
133 if isinstance(expect, str):
134 expect = [expect]
134 expect = [expect]
135 for ex in expect:
135 for ex in expect:
136 self.assertTrue(re.search(ex, line) is not None, "Expected %r in %r" % (ex, line))
136 self.assertTrue(re.search(ex, line) is not None, "Expected %r in %r" % (ex, line))
137
137
138 self._check_generated_stderr(io.stderr, len(v))
138 self._check_generated_stderr(io.stderr, len(v))
139
139
140
140
141 def test_cellpx_groupby_order(self):
141 def test_cellpx_groupby_order(self):
142 """%%px --group-outputs=order"""
142 """%%px --group-outputs=order"""
143 ip = get_ipython()
143 ip = get_ipython()
144 v = self.client[:]
144 v = self.client[:]
145 v.block = True
145 v.block = True
146 v.activate()
146 v.activate()
147
147
148 v['generate_output'] = generate_output
148 v['generate_output'] = generate_output
149
149
150 with capture_output() as io:
150 with capture_output() as io:
151 ip.run_cell_magic('px', '--group-outputs=order', 'generate_output()')
151 ip.run_cell_magic('px', '--group-outputs=order', 'generate_output()')
152
152
153 self.assertFalse('\n\n' in io.stdout)
153 self.assertFalse('\n\n' in io.stdout)
154 lines = io.stdout.splitlines()
154 lines = io.stdout.splitlines()
155 expected = []
155 expected = []
156 expected.extend([
156 expected.extend([
157 r'\[stdout:\d+\]',
157 r'\[stdout:\d+\]',
158 'stdout',
158 'stdout',
159 'stdout2',
159 'stdout2',
160 ] * len(v))
160 ] * len(v))
161 expected.extend([
161 expected.extend([
162 r'\[output:\d+\]',
162 r'\[output:\d+\]',
163 'IPython.core.display.HTML',
163 'IPython.core.display.HTML',
164 ] * len(v))
164 ] * len(v))
165 expected.extend([
165 expected.extend([
166 r'\[output:\d+\]',
166 r'\[output:\d+\]',
167 'IPython.core.display.Math',
167 'IPython.core.display.Math',
168 ] * len(v))
168 ] * len(v))
169 expected.extend([
169 expected.extend([
170 r'Out\[\d+:\d+\]:.*IPython\.core\.display\.Math'
170 r'Out\[\d+:\d+\]:.*IPython\.core\.display\.Math'
171 ] * len(v))
171 ] * len(v))
172
172
173 self.assertEqual(len(lines), len(expected), io.stdout)
173 self.assertEqual(len(lines), len(expected), io.stdout)
174 for line,expect in zip(lines, expected):
174 for line,expect in zip(lines, expected):
175 if isinstance(expect, str):
175 if isinstance(expect, str):
176 expect = [expect]
176 expect = [expect]
177 for ex in expect:
177 for ex in expect:
178 self.assertTrue(re.search(ex, line) is not None, "Expected %r in %r" % (ex, line))
178 self.assertTrue(re.search(ex, line) is not None, "Expected %r in %r" % (ex, line))
179
179
180 self._check_generated_stderr(io.stderr, len(v))
180 self._check_generated_stderr(io.stderr, len(v))
181
181
182 def test_cellpx_groupby_type(self):
182 def test_cellpx_groupby_type(self):
183 """%%px --group-outputs=type"""
183 """%%px --group-outputs=type"""
184 ip = get_ipython()
184 ip = get_ipython()
185 v = self.client[:]
185 v = self.client[:]
186 v.block = True
186 v.block = True
187 v.activate()
187 v.activate()
188
188
189 v['generate_output'] = generate_output
189 v['generate_output'] = generate_output
190
190
191 with capture_output() as io:
191 with capture_output() as io:
192 ip.run_cell_magic('px', '--group-outputs=type', 'generate_output()')
192 ip.run_cell_magic('px', '--group-outputs=type', 'generate_output()')
193
193
194 self.assertFalse('\n\n' in io.stdout)
194 self.assertFalse('\n\n' in io.stdout)
195 lines = io.stdout.splitlines()
195 lines = io.stdout.splitlines()
196
196
197 expected = []
197 expected = []
198 expected.extend([
198 expected.extend([
199 r'\[stdout:\d+\]',
199 r'\[stdout:\d+\]',
200 'stdout',
200 'stdout',
201 'stdout2',
201 'stdout2',
202 ] * len(v))
202 ] * len(v))
203 expected.extend([
203 expected.extend([
204 r'\[output:\d+\]',
204 r'\[output:\d+\]',
205 r'IPython\.core\.display\.HTML',
205 r'IPython\.core\.display\.HTML',
206 r'IPython\.core\.display\.Math',
206 r'IPython\.core\.display\.Math',
207 ] * len(v))
207 ] * len(v))
208 expected.extend([
208 expected.extend([
209 (r'Out\[\d+:\d+\]', r'IPython\.core\.display\.Math')
209 (r'Out\[\d+:\d+\]', r'IPython\.core\.display\.Math')
210 ] * len(v))
210 ] * len(v))
211
211
212 self.assertEqual(len(lines), len(expected), io.stdout)
212 self.assertEqual(len(lines), len(expected), io.stdout)
213 for line,expect in zip(lines, expected):
213 for line,expect in zip(lines, expected):
214 if isinstance(expect, str):
214 if isinstance(expect, str):
215 expect = [expect]
215 expect = [expect]
216 for ex in expect:
216 for ex in expect:
217 self.assertTrue(re.search(ex, line) is not None, "Expected %r in %r" % (ex, line))
217 self.assertTrue(re.search(ex, line) is not None, "Expected %r in %r" % (ex, line))
218
218
219 self._check_generated_stderr(io.stderr, len(v))
219 self._check_generated_stderr(io.stderr, len(v))
220
220
221
221
222 def test_px_nonblocking(self):
222 def test_px_nonblocking(self):
223 ip = get_ipython()
223 ip = get_ipython()
224 v = self.client[-1:]
224 v = self.client[-1:]
225 v.activate()
225 v.activate()
226 v.block=False
226 v.block=False
227
227
228 ip.magic('px a=5')
228 ip.magic('px a=5')
229 self.assertEqual(v['a'], [5])
229 self.assertEqual(v['a'], [5])
230 ip.magic('px a=10')
230 ip.magic('px a=10')
231 self.assertEqual(v['a'], [10])
231 self.assertEqual(v['a'], [10])
232 ip.magic('pxconfig --verbose')
232 ip.magic('pxconfig --verbose')
233 with capture_output() as io:
233 with capture_output() as io:
234 ar = ip.magic('px print (a)')
234 ar = ip.magic('px print (a)')
235 self.assertTrue(isinstance(ar, AsyncResult))
235 self.assertTrue(isinstance(ar, AsyncResult))
236 self.assertTrue('Async' in io.stdout)
236 self.assertTrue('Async' in io.stdout)
237 self.assertFalse('[stdout:' in io.stdout)
237 self.assertFalse('[stdout:' in io.stdout)
238 self.assertFalse('\n\n' in io.stdout)
238 self.assertFalse('\n\n' in io.stdout)
239
239
240 ar = ip.magic('px 1/0')
240 ar = ip.magic('px 1/0')
241 self.assertRaisesRemote(ZeroDivisionError, ar.get)
241 self.assertRaisesRemote(ZeroDivisionError, ar.get)
242
242
243 def test_autopx_blocking(self):
243 def test_autopx_blocking(self):
244 ip = get_ipython()
244 ip = get_ipython()
245 v = self.client[-1]
245 v = self.client[-1]
246 v.activate()
246 v.activate()
247 v.block=True
247 v.block=True
248
248
249 with capture_output() as io:
249 with capture_output() as io:
250 ip.magic('autopx')
250 ip.magic('autopx')
251 ip.run_cell('\n'.join(('a=5','b=12345','c=0')))
251 ip.run_cell('\n'.join(('a=5','b=12345','c=0')))
252 ip.run_cell('b*=2')
252 ip.run_cell('b*=2')
253 ip.run_cell('print (b)')
253 ip.run_cell('print (b)')
254 ip.run_cell('b')
254 ip.run_cell('b')
255 ip.run_cell("b/c")
255 ip.run_cell("b/c")
256 ip.magic('autopx')
256 ip.magic('autopx')
257
257
258 output = io.stdout
258 output = io.stdout
259
259
260 self.assertTrue(output.startswith('%autopx enabled'), output)
260 self.assertTrue(output.startswith('%autopx enabled'), output)
261 self.assertTrue(output.rstrip().endswith('%autopx disabled'), output)
261 self.assertTrue(output.rstrip().endswith('%autopx disabled'), output)
262 self.assertTrue('ZeroDivisionError' in output, output)
262 self.assertTrue('ZeroDivisionError' in output, output)
263 self.assertTrue('\nOut[' in output, output)
263 self.assertTrue('\nOut[' in output, output)
264 self.assertTrue(': 24690' in output, output)
264 self.assertTrue(': 24690' in output, output)
265 ar = v.get_result(-1)
265 ar = v.get_result(-1)
266 self.assertEqual(v['a'], 5)
266 self.assertEqual(v['a'], 5)
267 self.assertEqual(v['b'], 24690)
267 self.assertEqual(v['b'], 24690)
268 self.assertRaisesRemote(ZeroDivisionError, ar.get)
268 self.assertRaisesRemote(ZeroDivisionError, ar.get)
269
269
270 def test_autopx_nonblocking(self):
270 def test_autopx_nonblocking(self):
271 ip = get_ipython()
271 ip = get_ipython()
272 v = self.client[-1]
272 v = self.client[-1]
273 v.activate()
273 v.activate()
274 v.block=False
274 v.block=False
275
275
276 with capture_output() as io:
276 with capture_output() as io:
277 ip.magic('autopx')
277 ip.magic('autopx')
278 ip.run_cell('\n'.join(('a=5','b=10','c=0')))
278 ip.run_cell('\n'.join(('a=5','b=10','c=0')))
279 ip.run_cell('print (b)')
279 ip.run_cell('print (b)')
280 ip.run_cell('import time; time.sleep(0.1)')
280 ip.run_cell('import time; time.sleep(0.1)')
281 ip.run_cell("b/c")
281 ip.run_cell("b/c")
282 ip.run_cell('b*=2')
282 ip.run_cell('b*=2')
283 ip.magic('autopx')
283 ip.magic('autopx')
284
284
285 output = io.stdout.rstrip()
285 output = io.stdout.rstrip()
286
286
287 self.assertTrue(output.startswith('%autopx enabled'))
287 self.assertTrue(output.startswith('%autopx enabled'))
288 self.assertTrue(output.endswith('%autopx disabled'))
288 self.assertTrue(output.endswith('%autopx disabled'))
289 self.assertFalse('ZeroDivisionError' in output)
289 self.assertFalse('ZeroDivisionError' in output)
290 ar = v.get_result(-2)
290 ar = v.get_result(-2)
291 self.assertRaisesRemote(ZeroDivisionError, ar.get)
291 self.assertRaisesRemote(ZeroDivisionError, ar.get)
292 # prevent TaskAborted on pulls, due to ZeroDivisionError
292 # prevent TaskAborted on pulls, due to ZeroDivisionError
293 time.sleep(0.5)
293 time.sleep(0.5)
294 self.assertEqual(v['a'], 5)
294 self.assertEqual(v['a'], 5)
295 # b*=2 will not fire, due to abort
295 # b*=2 will not fire, due to abort
296 self.assertEqual(v['b'], 10)
296 self.assertEqual(v['b'], 10)
297
297
298 def test_result(self):
298 def test_result(self):
299 ip = get_ipython()
299 ip = get_ipython()
300 v = self.client[-1]
300 v = self.client[-1]
301 v.activate()
301 v.activate()
302 data = dict(a=111,b=222)
302 data = dict(a=111,b=222)
303 v.push(data, block=True)
303 v.push(data, block=True)
304
304
305 for name in ('a', 'b'):
305 for name in ('a', 'b'):
306 ip.magic('px ' + name)
306 ip.magic('px ' + name)
307 with capture_output() as io:
307 with capture_output() as io:
308 ip.magic('pxresult')
308 ip.magic('pxresult')
309 output = io.stdout
309 output = io.stdout
310 msg = "expected %s output to include %s, but got: %s" % \
310 msg = "expected %s output to include %s, but got: %s" % \
311 ('%pxresult', str(data[name]), output)
311 ('%pxresult', str(data[name]), output)
312 self.assertTrue(str(data[name]) in output, msg)
312 self.assertTrue(str(data[name]) in output, msg)
313
313
314 @dec.skipif_not_matplotlib
314 @dec.skipif_not_matplotlib
315 def test_px_pylab(self):
315 def test_px_pylab(self):
316 """%pylab works on engines"""
316 """%pylab works on engines"""
317 ip = get_ipython()
317 ip = get_ipython()
318 v = self.client[-1]
318 v = self.client[-1]
319 v.block = True
319 v.block = True
320 v.activate()
320 v.activate()
321
321
322 with capture_output() as io:
322 with capture_output() as io:
323 ip.magic("px %pylab inline")
323 ip.magic("px %pylab inline")
324
324
325 self.assertTrue("Welcome to pylab" in io.stdout, io.stdout)
325 self.assertTrue("Populating the interactive namespace from numpy and matplotlib" in io.stdout, io.stdout)
326 self.assertTrue("backend_inline" in io.stdout, io.stdout)
327
326
328 with capture_output() as io:
327 with capture_output() as io:
329 ip.magic("px plot(rand(100))")
328 ip.magic("px plot(rand(100))")
330
329
331 self.assertTrue('Out[' in io.stdout, io.stdout)
330 self.assertTrue('Out[' in io.stdout, io.stdout)
332 self.assertTrue('matplotlib.lines' in io.stdout, io.stdout)
331 self.assertTrue('matplotlib.lines' in io.stdout, io.stdout)
333
332
334 def test_pxconfig(self):
333 def test_pxconfig(self):
335 ip = get_ipython()
334 ip = get_ipython()
336 rc = self.client
335 rc = self.client
337 v = rc.activate(-1, '_tst')
336 v = rc.activate(-1, '_tst')
338 self.assertEqual(v.targets, rc.ids[-1])
337 self.assertEqual(v.targets, rc.ids[-1])
339 ip.magic("%pxconfig_tst -t :")
338 ip.magic("%pxconfig_tst -t :")
340 self.assertEqual(v.targets, rc.ids)
339 self.assertEqual(v.targets, rc.ids)
341 ip.magic("%pxconfig_tst -t ::2")
340 ip.magic("%pxconfig_tst -t ::2")
342 self.assertEqual(v.targets, rc.ids[::2])
341 self.assertEqual(v.targets, rc.ids[::2])
343 ip.magic("%pxconfig_tst -t 1::2")
342 ip.magic("%pxconfig_tst -t 1::2")
344 self.assertEqual(v.targets, rc.ids[1::2])
343 self.assertEqual(v.targets, rc.ids[1::2])
345 ip.magic("%pxconfig_tst -t 1")
344 ip.magic("%pxconfig_tst -t 1")
346 self.assertEqual(v.targets, 1)
345 self.assertEqual(v.targets, 1)
347 ip.magic("%pxconfig_tst --block")
346 ip.magic("%pxconfig_tst --block")
348 self.assertEqual(v.block, True)
347 self.assertEqual(v.block, True)
349 ip.magic("%pxconfig_tst --noblock")
348 ip.magic("%pxconfig_tst --noblock")
350 self.assertEqual(v.block, False)
349 self.assertEqual(v.block, False)
351
350
352 def test_cellpx_targets(self):
351 def test_cellpx_targets(self):
353 """%%px --targets doesn't change defaults"""
352 """%%px --targets doesn't change defaults"""
354 ip = get_ipython()
353 ip = get_ipython()
355 rc = self.client
354 rc = self.client
356 view = rc.activate(rc.ids)
355 view = rc.activate(rc.ids)
357 self.assertEqual(view.targets, rc.ids)
356 self.assertEqual(view.targets, rc.ids)
358 ip.magic('pxconfig --verbose')
357 ip.magic('pxconfig --verbose')
359 for cell in ("pass", "1/0"):
358 for cell in ("pass", "1/0"):
360 with capture_output() as io:
359 with capture_output() as io:
361 try:
360 try:
362 ip.run_cell_magic("px", "--targets all", cell)
361 ip.run_cell_magic("px", "--targets all", cell)
363 except pmod.RemoteError:
362 except pmod.RemoteError:
364 pass
363 pass
365 self.assertTrue('engine(s): all' in io.stdout)
364 self.assertTrue('engine(s): all' in io.stdout)
366 self.assertEqual(view.targets, rc.ids)
365 self.assertEqual(view.targets, rc.ids)
367
366
368
367
369 def test_cellpx_block(self):
368 def test_cellpx_block(self):
370 """%%px --block doesn't change default"""
369 """%%px --block doesn't change default"""
371 ip = get_ipython()
370 ip = get_ipython()
372 rc = self.client
371 rc = self.client
373 view = rc.activate(rc.ids)
372 view = rc.activate(rc.ids)
374 view.block = False
373 view.block = False
375 self.assertEqual(view.targets, rc.ids)
374 self.assertEqual(view.targets, rc.ids)
376 ip.magic('pxconfig --verbose')
375 ip.magic('pxconfig --verbose')
377 for cell in ("pass", "1/0"):
376 for cell in ("pass", "1/0"):
378 with capture_output() as io:
377 with capture_output() as io:
379 try:
378 try:
380 ip.run_cell_magic("px", "--block", cell)
379 ip.run_cell_magic("px", "--block", cell)
381 except pmod.RemoteError:
380 except pmod.RemoteError:
382 pass
381 pass
383 self.assertFalse('Async' in io.stdout)
382 self.assertFalse('Async' in io.stdout)
384 self.assertFalse(view.block)
383 self.assertFalse(view.block)
385
384
386
385
General Comments 0
You need to be logged in to leave comments. Login now