##// END OF EJS Templates
update parallel magic tests with capture_output API...
MinRK -
Show More
@@ -57,10 +57,9 class TestParallelMagics(ClusterTestCase, ParametricTestCase):
57 57 ip.magic(
58 58 'px import sys,time;print(a);sys.stdout.flush();time.sleep(0.2)'
59 59 )
60 out = io.stdout
61 self.assertTrue('[stdout:' in out, out)
62 self.assertFalse('\n\n' in out)
63 self.assertTrue(out.rstrip().endswith('10'))
60 self.assertIn('[stdout:', io.stdout)
61 self.assertNotIn('\n\n', io.stdout)
62 assert io.stdout.rstrip().endswith('10')
64 63 self.assertRaisesRemote(ZeroDivisionError, ip.magic, 'px 1/0')
65 64
66 65 def _check_generated_stderr(self, stderr, n):
@@ -89,20 +88,20 class TestParallelMagics(ClusterTestCase, ParametricTestCase):
89 88 for block in (True, False):
90 89 v.block = block
91 90 ip.magic("pxconfig --verbose")
92 with capture_output() as io:
91 with capture_output(display=False) as io:
93 92 ip.run_cell_magic("px", "", "1")
94 93 if block:
95 self.assertTrue(io.stdout.startswith("Parallel"), io.stdout)
94 assert io.stdout.startswith("Parallel"), io.stdout
96 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 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 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 106 def test_cellpx_groupby_engine(self):
108 107 """%%px --group-outputs=engine"""
@@ -113,10 +112,10 class TestParallelMagics(ClusterTestCase, ParametricTestCase):
113 112
114 113 v['generate_output'] = generate_output
115 114
116 with capture_output() as io:
115 with capture_output(display=False) as io:
117 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 119 lines = io.stdout.splitlines()
121 120 expected = [
122 121 r'\[stdout:\d+\]',
@@ -147,10 +146,10 class TestParallelMagics(ClusterTestCase, ParametricTestCase):
147 146
148 147 v['generate_output'] = generate_output
149 148
150 with capture_output() as io:
149 with capture_output(display=False) as io:
151 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 153 lines = io.stdout.splitlines()
155 154 expected = []
156 155 expected.extend([
@@ -188,10 +187,10 class TestParallelMagics(ClusterTestCase, ParametricTestCase):
188 187
189 188 v['generate_output'] = generate_output
190 189
191 with capture_output() as io:
190 with capture_output(display=False) as io:
192 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 194 lines = io.stdout.splitlines()
196 195
197 196 expected = []
@@ -246,7 +245,7 class TestParallelMagics(ClusterTestCase, ParametricTestCase):
246 245 v.activate()
247 246 v.block=True
248 247
249 with capture_output() as io:
248 with capture_output(display=False) as io:
250 249 ip.magic('autopx')
251 250 ip.run_cell('\n'.join(('a=5','b=12345','c=0')))
252 251 ip.run_cell('b*=2')
@@ -304,12 +303,9 class TestParallelMagics(ClusterTestCase, ParametricTestCase):
304 303
305 304 for name in ('a', 'b'):
306 305 ip.magic('px ' + name)
307 with capture_output() as io:
306 with capture_output(display=False) as io:
308 307 ip.magic('pxresult')
309 output = 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)
308 self.assertIn(str(data[name]), io.stdout)
313 309
314 310 @dec.skipif_not_matplotlib
315 311 def test_px_pylab(self):
@@ -322,13 +318,12 class TestParallelMagics(ClusterTestCase, ParametricTestCase):
322 318 with capture_output() as io:
323 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 324 ip.magic("px plot(rand(100))")
329
330 self.assertTrue('Out[' in io.stdout, io.stdout)
331 self.assertTrue('matplotlib.lines' in io.stdout, io.stdout)
325 self.assertIn('Out[', io.stdout)
326 self.assertIn('matplotlib.lines', io.stdout)
332 327
333 328 def test_pxconfig(self):
334 329 ip = get_ipython()
@@ -356,12 +351,12 class TestParallelMagics(ClusterTestCase, ParametricTestCase):
356 351 self.assertEqual(view.targets, rc.ids)
357 352 ip.magic('pxconfig --verbose')
358 353 for cell in ("pass", "1/0"):
359 with capture_output() as io:
354 with capture_output(display=False) as io:
360 355 try:
361 356 ip.run_cell_magic("px", "--targets all", cell)
362 357 except pmod.RemoteError:
363 358 pass
364 self.assertTrue('engine(s): all' in io.stdout)
359 self.assertIn('engine(s): all', io.stdout)
365 360 self.assertEqual(view.targets, rc.ids)
366 361
367 362
@@ -374,12 +369,12 class TestParallelMagics(ClusterTestCase, ParametricTestCase):
374 369 self.assertEqual(view.targets, rc.ids)
375 370 ip.magic('pxconfig --verbose')
376 371 for cell in ("pass", "1/0"):
377 with capture_output() as io:
372 with capture_output(display=False) as io:
378 373 try:
379 374 ip.run_cell_magic("px", "--block", cell)
380 375 except pmod.RemoteError:
381 376 pass
382 self.assertFalse('Async' in io.stdout)
383 self.assertFalse(view.block)
377 self.assertNotIn('Async', io.stdout)
378 self.assertEqual(view.block, False)
384 379
385 380
General Comments 0
You need to be logged in to leave comments. Login now