Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbrochart committed Jan 11, 2021
1 parent 61fb170 commit 9b47377
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 19 deletions.
20 changes: 15 additions & 5 deletions ipykernel/tests/test_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,12 @@ def test_interrupt_during_input():
msg_id = kc.execute("input()")
time.sleep(1) # Make sure it's actually waiting for input.
km.interrupt_kernel()
# If we failed to interrupt interrupt, this will timeout:
reply = kc.get_shell_msg(timeout=TIMEOUT)
from .test_message_spec import validate_message
while True:
# If we failed to interrupt interrupt, this will timeout:
reply = kc.get_shell_msg(timeout=TIMEOUT)
if reply['parent_header']['msg_id'] == msg_id:
break
validate_message(reply, 'execute_reply', msg_id)


Expand All @@ -385,9 +388,16 @@ def test_interrupt_during_pdb_set_trace():
msg_id2 = kc.execute("3 + 4")
time.sleep(1) # Make sure it's actually waiting for input.
km.interrupt_kernel()
# If we failed to interrupt interrupt, this will timeout:
from .test_message_spec import validate_message
reply = kc.get_shell_msg(timeout=TIMEOUT)
while True:
# If we failed to interrupt interrupt, this will timeout:
reply = kc.get_shell_msg(timeout=TIMEOUT)
if reply['parent_header']['msg_id'] == msg_id:
break
validate_message(reply, 'execute_reply', msg_id)
reply = kc.get_shell_msg(timeout=TIMEOUT)
while True:
# If we failed to interrupt interrupt, this will timeout:
reply = kc.get_shell_msg(timeout=TIMEOUT)
if reply['parent_header']['msg_id'] == msg_id2:
break
validate_message(reply, 'execute_reply', msg_id2)
65 changes: 52 additions & 13 deletions ipykernel/tests/test_message_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,10 @@ def test_execute():
flush_channels()

msg_id = KC.execute(code='x=1')
reply = KC.get_shell_msg(timeout=TIMEOUT)
while True:
reply = KC.get_shell_msg(timeout=TIMEOUT)
if reply['parent_header']['msg_id'] == msg_id:
break
validate_message(reply, 'execute_reply', msg_id)


Expand Down Expand Up @@ -405,7 +408,10 @@ def test_oinfo():
flush_channels()

msg_id = KC.inspect('a')
reply = KC.get_shell_msg(timeout=TIMEOUT)
while True:
reply = KC.get_shell_msg(timeout=TIMEOUT)
if reply['parent_header']['msg_id'] == msg_id:
break
validate_message(reply, 'inspect_reply', msg_id)


Expand All @@ -415,7 +421,10 @@ def test_oinfo_found():
msg_id, reply = execute(code='a=5')

msg_id = KC.inspect('a')
reply = KC.get_shell_msg(timeout=TIMEOUT)
while True:
reply = KC.get_shell_msg(timeout=TIMEOUT)
if reply['parent_header']['msg_id'] == msg_id:
break
validate_message(reply, 'inspect_reply', msg_id)
content = reply['content']
assert content['found']
Expand All @@ -430,7 +439,10 @@ def test_oinfo_detail():
msg_id, reply = execute(code='ip=get_ipython()')

msg_id = KC.inspect('ip.object_inspect', cursor_pos=10, detail_level=1)
reply = KC.get_shell_msg(timeout=TIMEOUT)
while True:
reply = KC.get_shell_msg(timeout=TIMEOUT)
if reply['parent_header']['msg_id'] == msg_id:
break
validate_message(reply, 'inspect_reply', msg_id)
content = reply['content']
assert content['found']
Expand All @@ -443,7 +455,10 @@ def test_oinfo_not_found():
flush_channels()

msg_id = KC.inspect('dne')
reply = KC.get_shell_msg(timeout=TIMEOUT)
while True:
reply = KC.get_shell_msg(timeout=TIMEOUT)
if reply['parent_header']['msg_id'] == msg_id:
break
validate_message(reply, 'inspect_reply', msg_id)
content = reply['content']
assert not content['found']
Expand All @@ -455,7 +470,10 @@ def test_complete():
msg_id, reply = execute(code="alpha = albert = 5")

msg_id = KC.complete('al', 2)
reply = KC.get_shell_msg(timeout=TIMEOUT)
while True:
reply = KC.get_shell_msg(timeout=TIMEOUT)
if reply['parent_header']['msg_id'] == msg_id:
break
validate_message(reply, 'complete_reply', msg_id)
matches = reply['content']['matches']
for name in ('alpha', 'albert'):
Expand All @@ -466,7 +484,10 @@ def test_kernel_info_request():
flush_channels()

msg_id = KC.kernel_info()
reply = KC.get_shell_msg(timeout=TIMEOUT)
while True:
reply = KC.get_shell_msg(timeout=TIMEOUT)
if reply['parent_header']['msg_id'] == msg_id:
break
validate_message(reply, 'kernel_info_reply', msg_id)


Expand All @@ -477,7 +498,10 @@ def test_connect_request():
return msg['header']['msg_id']

msg_id = KC.kernel_info()
reply = KC.get_shell_msg(timeout=TIMEOUT)
while True:
reply = KC.get_shell_msg(timeout=TIMEOUT)
if reply['parent_header']['msg_id'] == msg_id:
break
validate_message(reply, 'connect_reply', msg_id)


Expand All @@ -486,7 +510,10 @@ def test_comm_info_request():
if not hasattr(KC, 'comm_info'):
raise SkipTest()
msg_id = KC.comm_info()
reply = KC.get_shell_msg(timeout=TIMEOUT)
while True:
reply = KC.get_shell_msg(timeout=TIMEOUT)
if reply['parent_header']['msg_id'] == msg_id:
break
validate_message(reply, 'comm_info_reply', msg_id)


Expand All @@ -512,7 +539,10 @@ def test_is_complete():
flush_channels()

msg_id = KC.is_complete("a = 1")
reply = KC.get_shell_msg(timeout=TIMEOUT)
while True:
reply = KC.get_shell_msg(timeout=TIMEOUT)
if reply['parent_header']['msg_id'] == msg_id:
break
validate_message(reply, 'is_complete_reply', msg_id)

def test_history_range():
Expand All @@ -522,7 +552,10 @@ def test_history_range():
reply_exec = KC.get_shell_msg(timeout=TIMEOUT)

msg_id = KC.history(hist_access_type = 'range', raw = True, output = True, start = 1, stop = 2, session = 0)
reply = KC.get_shell_msg(timeout=TIMEOUT)
while True:
reply = KC.get_shell_msg(timeout=TIMEOUT)
if reply['parent_header']['msg_id'] == msg_id:
break
validate_message(reply, 'history_reply', msg_id)
content = reply['content']
assert len(content['history']) == 1
Expand All @@ -534,7 +567,10 @@ def test_history_tail():
reply_exec = KC.get_shell_msg(timeout=TIMEOUT)

msg_id = KC.history(hist_access_type = 'tail', raw = True, output = True, n = 1, session = 0)
reply = KC.get_shell_msg(timeout=TIMEOUT)
while True:
reply = KC.get_shell_msg(timeout=TIMEOUT)
if reply['parent_header']['msg_id'] == msg_id:
break
validate_message(reply, 'history_reply', msg_id)
content = reply['content']
assert len(content['history']) == 1
Expand All @@ -546,7 +582,10 @@ def test_history_search():
reply_exec = KC.get_shell_msg(timeout=TIMEOUT)

msg_id = KC.history(hist_access_type = 'search', raw = True, output = True, n = 1, pattern = '*', session = 0)
reply = KC.get_shell_msg(timeout=TIMEOUT)
while True:
reply = KC.get_shell_msg(timeout=TIMEOUT)
if reply['parent_header']['msg_id'] == msg_id:
break
validate_message(reply, 'history_reply', msg_id)
content = reply['content']
assert len(content['history']) == 1
Expand Down
5 changes: 4 additions & 1 deletion ipykernel/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ def execute(code='', kc=None, **kwargs):
if kc is None:
kc = KC
msg_id = kc.execute(code=code, **kwargs)
reply = kc.get_shell_msg(timeout=TIMEOUT)
while True:
reply = kc.get_shell_msg(timeout=TIMEOUT)
if reply['parent_header']['msg_id'] == msg_id:
break
validate_message(reply, 'execute_reply', msg_id)
busy = kc.get_iopub_msg(timeout=TIMEOUT)
validate_message(busy, 'status', msg_id)
Expand Down

0 comments on commit 9b47377

Please sign in to comment.