Skip to content

Commit 2eae2a2

Browse files
committed
Add tests
1 parent 28836e6 commit 2eae2a2

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

ipyparallel/tests/test_magics.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Test Parallel magics"""
22
import re
3+
import signal
34
import sys
45
import time
56

@@ -480,3 +481,45 @@ def test_cellpx_block(self):
480481
pass
481482
self.assertNotIn('Async', io.stdout)
482483
self.assertEqual(view.block, False)
484+
485+
def cellpx_keyboard_interrupt_test_helper(self, sig=None):
486+
"""%%px with Keyboard Interrupt on blocking execution"""
487+
488+
ip = get_ipython()
489+
v = self.client[:]
490+
v.block = True
491+
v.activate()
492+
493+
def _sigalarm(sig, frame):
494+
raise KeyboardInterrupt
495+
496+
signal.signal(signal.SIGALRM, _sigalarm)
497+
signal.alarm(2)
498+
with capture_output(display=False) as io:
499+
ip.run_cell_magic(
500+
"px",
501+
"" if sig is None else f"--signal-on-interrupt {sig}",
502+
"print('Entering...'); import time; time.sleep(5); print('Exiting...');",
503+
)
504+
505+
print(io.stdout)
506+
print(io.stderr, file=sys.stderr)
507+
assert (
508+
'Received Keyboard Interrupt. Sending signal {} to engines...'.format(
509+
"SIGINT" if sig is None else sig
510+
)
511+
in io.stderr
512+
)
513+
assert 'Exiting...' not in io.stdout
514+
515+
def test_cellpx_keyboard_interrupt_default(self):
516+
self.cellpx_keyboard_interrupt_test_helper()
517+
518+
def test_cellpx_keyboard_interrupt_SIGINT(self):
519+
self.cellpx_keyboard_interrupt_test_helper("SIGINT")
520+
521+
def test_cellpx_keyboard_interrupt_signal_2(self):
522+
self.cellpx_keyboard_interrupt_test_helper("2")
523+
524+
def test_cellpx_keyboard_interrupt_signal_0(self):
525+
self.cellpx_keyboard_interrupt_test_helper("0")

0 commit comments

Comments
 (0)