Skip to content

Commit d1c2782

Browse files
committed
-
1 parent c1c29a9 commit d1c2782

File tree

5 files changed

+35
-36
lines changed

5 files changed

+35
-36
lines changed

ipykernel/inprocess/client.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -178,18 +178,6 @@ def _dispatch_to_kernel(self, msg):
178178
idents, reply_msg = self.session.recv(stream, copy=False)
179179
self.shell_channel.call_handlers_later(reply_msg)
180180

181-
def get_shell_msg(self, block=True, timeout=None):
182-
return self.shell_channel.get_msg(block, timeout)
183-
184-
def get_iopub_msg(self, block=True, timeout=None):
185-
return self.iopub_channel.get_msg(block, timeout)
186-
187-
def get_stdin_msg(self, block=True, timeout=None):
188-
return self.stdin_channel.get_msg(block, timeout)
189-
190-
def get_control_msg(self, block=True, timeout=None):
191-
return self.control_channel.get_msg(block, timeout)
192-
193181

194182
#-----------------------------------------------------------------------------
195183
# ABC Registration

ipykernel/inprocess/tests/test_kernel.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def test_pylab(self):
6565
"""Does %pylab work in the in-process kernel?"""
6666
kc = self.kc
6767
kc.execute('%pylab')
68-
out, err = assemble_output(kc.get_iopub_msg)
68+
out, err = assemble_output(kc.iopub_channel)
6969
self.assertIn('matplotlib', out)
7070

7171
def test_raw_input(self):
@@ -96,7 +96,7 @@ def test_stdout(self):
9696
kc = BlockingInProcessKernelClient(kernel=kernel, session=kernel.session)
9797
kernel.frontends.append(kc)
9898
kc.execute('print("bar")')
99-
out, err = assemble_output(kc.get_iopub_msg)
99+
out, err = assemble_output(kc.iopub_channel)
100100
assert out == 'bar\n'
101101

102102
def test_getpass_stream(self):

ipykernel/tests/test_kernel.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def _check_master(kc, expected=True, stream="stdout"):
2929
execute(kc=kc, code="import sys")
3030
flush_channels(kc)
3131
msg_id, content = execute(kc=kc, code="print (sys.%s._is_master_process())" % stream)
32-
stdout, stderr = assemble_output(kc.get_iopub_msg)
32+
stdout, stderr = assemble_output(kc.iopub_channel)
3333
assert stdout.strip() == repr(expected)
3434

3535

@@ -44,8 +44,9 @@ def _check_status(content):
4444
def test_simple_print():
4545
"""simple print statement in kernel"""
4646
with kernel() as kc:
47+
iopub = kc.iopub_channel
4748
msg_id, content = execute(kc=kc, code="print ('hi')")
48-
stdout, stderr = assemble_output(kc.get_iopub_msg)
49+
stdout, stderr = assemble_output(iopub)
4950
assert stdout == 'hi\n'
5051
assert stderr == ''
5152
_check_master(kc, expected=True)
@@ -55,7 +56,7 @@ def test_sys_path():
5556
"""test that sys.path doesn't get messed up by default"""
5657
with kernel() as kc:
5758
msg_id, content = execute(kc=kc, code="import sys; print(repr(sys.path))")
58-
stdout, stderr = assemble_output(kc.get_iopub_msg)
59+
stdout, stderr = assemble_output(kc.iopub_channel)
5960
# for error-output on failure
6061
sys.stderr.write(stderr)
6162

@@ -68,7 +69,7 @@ def test_sys_path_profile_dir():
6869

6970
with new_kernel(['--profile-dir', locate_profile('default')]) as kc:
7071
msg_id, content = execute(kc=kc, code="import sys; print(repr(sys.path))")
71-
stdout, stderr = assemble_output(kc.get_iopub_msg)
72+
stdout, stderr = assemble_output(kc.iopub_channel)
7273
# for error-output on failure
7374
sys.stderr.write(stderr)
7475

@@ -84,6 +85,8 @@ def test_sys_path_profile_dir():
8485
def test_subprocess_print():
8586
"""printing from forked mp.Process"""
8687
with new_kernel() as kc:
88+
iopub = kc.iopub_channel
89+
8790
_check_master(kc, expected=True)
8891
flush_channels(kc)
8992
np = 5
@@ -97,7 +100,7 @@ def test_subprocess_print():
97100
])
98101

99102
msg_id, content = execute(kc=kc, code=code)
100-
stdout, stderr = assemble_output(kc.get_iopub_msg)
103+
stdout, stderr = assemble_output(iopub)
101104
nt.assert_equal(stdout.count("hello"), np, stdout)
102105
for n in range(np):
103106
nt.assert_equal(stdout.count(str(n)), 1, stdout)
@@ -110,6 +113,8 @@ def test_subprocess_print():
110113
def test_subprocess_noprint():
111114
"""mp.Process without print doesn't trigger iostream mp_mode"""
112115
with kernel() as kc:
116+
iopub = kc.iopub_channel
117+
113118
np = 5
114119
code = '\n'.join([
115120
"import multiprocessing as mp",
@@ -119,7 +124,7 @@ def test_subprocess_noprint():
119124
])
120125

121126
msg_id, content = execute(kc=kc, code=code)
122-
stdout, stderr = assemble_output(kc.get_iopub_msg)
127+
stdout, stderr = assemble_output(iopub)
123128
assert stdout == ''
124129
assert stderr == ''
125130

@@ -135,6 +140,8 @@ def test_subprocess_noprint():
135140
def test_subprocess_error():
136141
"""error in mp.Process doesn't crash"""
137142
with new_kernel() as kc:
143+
iopub = kc.iopub_channel
144+
138145
code = '\n'.join([
139146
"import multiprocessing as mp",
140147
"p = mp.Process(target=int, args=('hi',))",
@@ -143,7 +150,7 @@ def test_subprocess_error():
143150
])
144151

145152
msg_id, content = execute(kc=kc, code=code)
146-
stdout, stderr = assemble_output(kc.get_iopub_msg)
153+
stdout, stderr = assemble_output(iopub)
147154
assert stdout == ''
148155
assert "ValueError" in stderr
149156

@@ -155,6 +162,8 @@ def test_subprocess_error():
155162
def test_raw_input():
156163
"""test input"""
157164
with kernel() as kc:
165+
iopub = kc.iopub_channel
166+
158167
input_f = "input"
159168
theprompt = "prompt> "
160169
code = 'print({input_f}("{theprompt}"))'.format(**locals())
@@ -167,7 +176,7 @@ def test_raw_input():
167176
kc.input(text)
168177
reply = kc.get_shell_msg(block=True, timeout=TIMEOUT)
169178
assert reply['content']['status'] == 'ok'
170-
stdout, stderr = assemble_output(kc.get_iopub_msg)
179+
stdout, stderr = assemble_output(iopub)
171180
assert stdout == text + "\n"
172181

173182

@@ -304,17 +313,19 @@ def test_unc_paths():
304313
file_path = os.path.splitdrive(os.path.dirname(drive_file_path))[1]
305314
unc_file_path = os.path.join(unc_root, file_path[1:])
306315

316+
iopub = kc.iopub_channel
317+
307318
kc.execute("cd {0:s}".format(unc_file_path))
308319
reply = kc.get_shell_msg(block=True, timeout=TIMEOUT)
309320
assert reply['content']['status'] == 'ok'
310-
out, err = assemble_output(kc.get_iopub_msg)
321+
out, err = assemble_output(iopub)
311322
assert unc_file_path in out
312323

313324
flush_channels(kc)
314325
kc.execute(code="ls")
315326
reply = kc.get_shell_msg(block=True, timeout=TIMEOUT)
316327
assert reply['content']['status'] == 'ok'
317-
out, err = assemble_output(kc.get_iopub_msg)
328+
out, err = assemble_output(iopub)
318329
assert 'unc.txt' in out
319330

320331
kc.execute(code="cd")

ipykernel/tests/test_message_spec.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -288,21 +288,21 @@ def test_execute_silent():
288288
msg_id, reply = execute(code='x=1', silent=True)
289289

290290
# flush status=idle
291-
status = KC.get_iopub_msg(timeout=TIMEOUT)
291+
status = KC.iopub_channel.get_msg(timeout=TIMEOUT)
292292
validate_message(status, 'status', msg_id)
293293
assert status['content']['execution_state'] == 'idle'
294294

295-
nt.assert_raises(Empty, KC.get_iopub_msg, timeout=0.1)
295+
nt.assert_raises(Empty, KC.iopub_channel.get_msg, timeout=0.1)
296296
count = reply['execution_count']
297297

298298
msg_id, reply = execute(code='x=2', silent=True)
299299

300300
# flush status=idle
301-
status = KC.get_iopub_msg(timeout=TIMEOUT)
301+
status = KC.iopub_channel.get_msg(timeout=TIMEOUT)
302302
validate_message(status, 'status', msg_id)
303303
assert status['content']['execution_state'] == 'idle'
304304

305-
nt.assert_raises(Empty, KC.get_iopub_msg, timeout=0.1)
305+
nt.assert_raises(Empty, KC.iopub_channel.get_msg, timeout=0.1)
306306
count_2 = reply['execution_count']
307307
assert count_2 == count
308308

@@ -314,7 +314,7 @@ def test_execute_error():
314314
assert reply['status'] == 'error'
315315
assert reply['ename'] == 'ZeroDivisionError'
316316

317-
error = KC.get_iopub_msg(timeout=TIMEOUT)
317+
error = KC.iopub_channel.get_msg(timeout=TIMEOUT)
318318
validate_message(error, 'error', msg_id)
319319

320320

@@ -560,7 +560,7 @@ def test_stream():
560560

561561
msg_id, reply = execute("print('hi')")
562562

563-
stdout = KC.get_iopub_msg(timeout=TIMEOUT)
563+
stdout = KC.iopub_channel.get_msg(timeout=TIMEOUT)
564564
validate_message(stdout, 'stream', msg_id)
565565
content = stdout['content']
566566
assert content['text'] == 'hi\n'
@@ -571,7 +571,7 @@ def test_display_data():
571571

572572
msg_id, reply = execute("from IPython.display import display; display(1)")
573573

574-
display = KC.get_iopub_msg(timeout=TIMEOUT)
574+
display = KC.iopub_channel.get_msg(timeout=TIMEOUT)
575575
validate_message(display, 'display_data', parent=msg_id)
576576
data = display['content']['data']
577577
assert data['text/plain'] == '1'

ipykernel/tests/utils.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ def flush_channels(kc=None):
4343

4444
if kc is None:
4545
kc = KC
46-
for get_msg in (kc.get_shell_msg, kc.get_iopub_msg):
46+
for channel in (kc.shell_channel, kc.iopub_channel):
4747
while True:
4848
try:
49-
msg = get_msg(block=True, timeout=0.1)
49+
msg = channel.get_msg(block=True, timeout=0.1)
5050
except Empty:
5151
break
5252
else:
@@ -149,12 +149,12 @@ def new_kernel(argv=None):
149149
kwargs['extra_arguments'] = argv
150150
return manager.run_kernel(**kwargs)
151151

152-
def assemble_output(get_msg):
152+
def assemble_output(iopub):
153153
"""assemble stdout/err from an execution"""
154154
stdout = ''
155155
stderr = ''
156156
while True:
157-
msg = get_msg(block=True, timeout=1)
157+
msg = iopub.get_msg(block=True, timeout=1)
158158
msg_type = msg['msg_type']
159159
content = msg['content']
160160
if msg_type == 'status' and content['execution_state'] == 'idle':
@@ -174,7 +174,7 @@ def assemble_output(get_msg):
174174

175175
def wait_for_idle(kc):
176176
while True:
177-
msg = kc.get_iopub_msg(block=True, timeout=1)
177+
msg = kc.iopub_channel.get_msg(block=True, timeout=1)
178178
msg_type = msg['msg_type']
179179
content = msg['content']
180180
if msg_type == 'status' and content['execution_state'] == 'idle':

0 commit comments

Comments
 (0)