def test_embed_kernel_namespace():
"""IPython.embed_kernel() inherits calling namespace"""
cmd = '\n'.join([
'from IPython import embed_kernel',
'def go():',
' a=5',
' b="hi there"',
' embed_kernel()',
'go()',
'',
])
with setup_kernel(cmd) as client:
# oinfo a (int)
msg_id = client.inspect('a')
msg = client.get_shell_msg(block=True, timeout=TIMEOUT)
content = msg['content']
nt.assert_true(content['found'])
text = content['data']['text/plain']
nt.assert_in(u'5', text)
# oinfo b (str)
msg_id = client.inspect('b')
msg = client.get_shell_msg(block=True, timeout=TIMEOUT)
content = msg['content']
nt.assert_true(content['found'])
text = content['data']['text/plain']
nt.assert_in(u'hi there', text)
# oinfo c (undefined)
msg_id = client.inspect('c')
msg = client.get_shell_msg(block=True, timeout=TIMEOUT)
content = msg['content']
nt.assert_false(content['found'])
评论列表
文章目录