Skip to content

Commit e63c018

Browse files
committed
add tests
1 parent d00ff33 commit e63c018

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

ipykernel/inprocess/tests/test_kernel.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,27 @@ def test_stdout(self):
9999
out, err = assemble_output(kc.iopub_channel)
100100
assert out == 'bar\n'
101101

102+
@pytest.mark.skipif(
103+
sys.platform == 'win32',
104+
reason="not ment to work on windows"
105+
)
106+
def test_capfd(self):
107+
""" Does correctly capture fd
108+
"""
109+
kernel = InProcessKernel()
110+
111+
with capture_output() as io:
112+
kernel.shell.run_cell('print("foo")')
113+
assert io.stdout == 'foo\n'
114+
115+
kc = BlockingInProcessKernelClient(kernel=kernel, session=kernel.session)
116+
kernel.frontends.append(kc)
117+
kc.execute('import os')
118+
kc.execute('os.system("echo capfd")')
119+
out, err = assemble_output(kc.iopub_channel)
120+
assert out == 'capfd\n'
121+
122+
102123
def test_getpass_stream(self):
103124
"Tests that kernel getpass accept the stream parameter"
104125
kernel = InProcessKernel()

ipykernel/tests/test_kernel.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
def _check_master(kc, expected=True, stream="stdout"):
2929
execute(kc=kc, code="import sys")
3030
flush_channels(kc)
31-
msg_id, content = execute(kc=kc, code="print (sys.%s._is_master_process())" % stream)
31+
msg_id, content = execute(kc=kc, code="print(sys.%s._is_master_process())" % stream)
3232
stdout, stderr = assemble_output(kc.iopub_channel)
3333
assert stdout.strip() == repr(expected)
3434

@@ -51,6 +51,18 @@ def test_simple_print():
5151
assert stderr == ''
5252
_check_master(kc, expected=True)
5353

54+
@pytest.mark.skipif(sys.platform=='win32', reason='Not meant to work on windows')
55+
def test_capture_fd():
56+
"""simple print statement in kernel"""
57+
with kernel() as kc:
58+
iopub = kc.iopub_channel
59+
msg_id, content = execute(kc=kc, code="import os; os.system('echo capsys')")
60+
stdout, stderr = assemble_output(iopub)
61+
assert stdout == 'capsys\n'
62+
assert stderr == ''
63+
_check_master(kc, expected=True)
64+
65+
5466

5567
def test_sys_path():
5668
"""test that sys.path doesn't get messed up by default"""

0 commit comments

Comments
 (0)