Skip to content

Commit 2fe7fab

Browse files
committed
add simple test
1 parent 97e283c commit 2fe7fab

File tree

1 file changed

+56
-2
lines changed

1 file changed

+56
-2
lines changed

ipyparallel/tests/test_magics.py

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ def _check_generated_stderr(self, stderr, n):
5050
for ex in expect:
5151
assert re.search(ex, line) is not None, "Expected %r in %r" % (ex, line)
5252

53+
def _check_expected_lines_unordered(self, expected, lines):
54+
for expect in expected:
55+
found = False
56+
for line in lines:
57+
found = found | (re.search(expect, line) is not None)
58+
if found:
59+
break
60+
assert found, "Expected %r in output" % (expect,)
61+
5362
def test_cellpx_block_args(self):
5463
"""%%px --[no]block flags work"""
5564
ip = get_ipython()
@@ -207,8 +216,53 @@ def test_cellpx_groupby_type(self):
207216

208217
def test_cellpx_stream(self):
209218
"""%%px --stream"""
210-
# TODO
211-
pass
219+
ip = get_ipython()
220+
v = self.client[:]
221+
v.block = True
222+
v.activate()
223+
224+
v['generate_output'] = generate_output
225+
226+
with capture_output(display=False) as io:
227+
ip.run_cell_magic('px', '--stream', 'generate_output()')
228+
229+
self.assertNotIn('\n\n', io.stdout)
230+
lines = io.stdout.splitlines()
231+
expected = []
232+
expected.extend(
233+
[
234+
r'\[stdout:\d+\] stdout',
235+
r'\[stdout:\d+\] stdout2',
236+
]
237+
* len(v)
238+
)
239+
expected.extend(
240+
[
241+
r'\[output:\d+\]',
242+
r'IPython\.core\.display\.HTML',
243+
r'IPython\.core\.display\.Math',
244+
]
245+
* len(v)
246+
)
247+
expected.extend([r'Out\[\d+:\d+\]:.*IPython\.core\.display\.Math'] * len(v))
248+
249+
self.assertEqual(len(lines), len(expected), io.stdout)
250+
# Check that all expected lines are in the output
251+
self._check_expected_lines_unordered(expected, lines)
252+
253+
# Do the same for stderr
254+
self.assertNotIn('\n\n', io.stderr)
255+
lines = io.stderr.splitlines()
256+
expected = []
257+
expected.extend(
258+
[
259+
r'\[stderr:\d+\] stderr',
260+
r'\[stderr:\d+\] stderr2',
261+
]
262+
* len(v)
263+
)
264+
self.assertEqual(len(lines), len(expected), io.stderr)
265+
self._check_expected_lines_unordered(expected, lines)
212266

213267
def test_px_nonblocking(self):
214268
ip = get_ipython()

0 commit comments

Comments
 (0)