##// END OF EJS Templates
Merge pull request #4107 from minrk/parallel-magics-fix...
Thomas Kluyver -
r12304:f0e4a0f0 merge
parent child Browse files
Show More
@@ -57,10 +57,9 b' class TestParallelMagics(ClusterTestCase, ParametricTestCase):'
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 self.assertIn('[stdout:', io.stdout)
61 self.assertTrue('[stdout:' in out, out)
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):
@@ -70,14 +69,14 b' class TestParallelMagics(ClusterTestCase, ParametricTestCase):'
70 '^stderr2$',
69 '^stderr2$',
71 ] * n
70 ] * n
72
71
73 self.assertFalse('\n\n' in stderr, stderr)
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 self.assertTrue(re.search(ex, line) is not None, "Expected %r in %r" % (ex, line))
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"""
@@ -89,20 +88,20 b' class TestParallelMagics(ClusterTestCase, ParametricTestCase):'
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 self.assertTrue(io.stdout.startswith("Parallel"), io.stdout)
94 assert io.stdout.startswith("Parallel"), io.stdout
96 else:
95 else:
97 self.assertTrue(io.stdout.startswith("Async"), io.stdout)
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 self.assertTrue(io.stdout.startswith("Parallel"), io.stdout)
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 self.assertTrue(io.stdout.startswith("Async"), io.stdout)
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"""
@@ -113,10 +112,10 b' class TestParallelMagics(ClusterTestCase, ParametricTestCase):'
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.assertFalse('\n\n' in io.stdout)
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+\]',
@@ -133,7 +132,7 b' class TestParallelMagics(ClusterTestCase, ParametricTestCase):'
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 self.assertTrue(re.search(ex, line) is not None, "Expected %r in %r" % (ex, line))
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
@@ -147,10 +146,10 b' class TestParallelMagics(ClusterTestCase, ParametricTestCase):'
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.assertFalse('\n\n' in io.stdout)
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([
@@ -175,7 +174,7 b' class TestParallelMagics(ClusterTestCase, ParametricTestCase):'
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 self.assertTrue(re.search(ex, line) is not None, "Expected %r in %r" % (ex, line))
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
@@ -188,10 +187,10 b' class TestParallelMagics(ClusterTestCase, ParametricTestCase):'
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.assertFalse('\n\n' in io.stdout)
193 self.assertNotIn('\n\n', io.stdout)
195 lines = io.stdout.splitlines()
194 lines = io.stdout.splitlines()
196
195
197 expected = []
196 expected = []
@@ -214,7 +213,7 b' class TestParallelMagics(ClusterTestCase, ParametricTestCase):'
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 self.assertTrue(re.search(ex, line) is not None, "Expected %r in %r" % (ex, line))
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
@@ -232,10 +231,10 b' class TestParallelMagics(ClusterTestCase, ParametricTestCase):'
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.assertTrue(isinstance(ar, AsyncResult))
234 self.assertIsInstance(ar, AsyncResult)
236 self.assertTrue('Async' in io.stdout)
235 self.assertIn('Async', io.stdout)
237 self.assertFalse('[stdout:' in io.stdout)
236 self.assertNotIn('[stdout:', io.stdout)
238 self.assertFalse('\n\n' in io.stdout)
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)
@@ -246,7 +245,7 b' class TestParallelMagics(ClusterTestCase, ParametricTestCase):'
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')
@@ -257,11 +256,11 b' class TestParallelMagics(ClusterTestCase, ParametricTestCase):'
257
256
258 output = io.stdout
257 output = io.stdout
259
258
260 self.assertTrue(output.startswith('%autopx enabled'), output)
259 assert output.startswith('%autopx enabled'), output
261 self.assertTrue(output.rstrip().endswith('%autopx disabled'), output)
260 assert output.rstrip().endswith('%autopx disabled'), output
262 self.assertTrue('ZeroDivisionError' in output, output)
261 self.assertIn('ZeroDivisionError', output)
263 self.assertTrue('\nOut[' in output, output)
262 self.assertIn('\nOut[', output)
264 self.assertTrue(': 24690' in output, output)
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)
@@ -284,9 +283,9 b' class TestParallelMagics(ClusterTestCase, ParametricTestCase):'
284
283
285 output = io.stdout.rstrip()
284 output = io.stdout.rstrip()
286
285
287 self.assertTrue(output.startswith('%autopx enabled'))
286 assert output.startswith('%autopx enabled'), output
288 self.assertTrue(output.endswith('%autopx disabled'))
287 assert output.endswith('%autopx disabled'), output
289 self.assertFalse('ZeroDivisionError' in output)
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
@@ -304,12 +303,9 b' class TestParallelMagics(ClusterTestCase, ParametricTestCase):'
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):
@@ -322,13 +318,12 b' class TestParallelMagics(ClusterTestCase, ParametricTestCase):'
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.assertTrue("Populating the interactive namespace from numpy and matplotlib" in io.stdout, io.stdout)
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.assertTrue('Out[' in io.stdout, io.stdout)
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()
@@ -356,12 +351,12 b' class TestParallelMagics(ClusterTestCase, ParametricTestCase):'
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.assertTrue('engine(s): all' in io.stdout)
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
@@ -374,12 +369,12 b' class TestParallelMagics(ClusterTestCase, ParametricTestCase):'
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.assertFalse('Async' in io.stdout)
377 self.assertNotIn('Async', io.stdout)
383 self.assertFalse(view.block)
378 self.assertEqual(view.block, False)
384
379
385
380
General Comments 0
You need to be logged in to leave comments. Login now