##// END OF EJS Templates
Test for debugger interruption.
Itamar Turner-Trauring -
Show More
@@ -648,10 +648,3 b' def set_trace(frame=None):'
648 If frame is not specified, debugging starts from caller's frame.
648 If frame is not specified, debugging starts from caller's frame.
649 """
649 """
650 Pdb().set_trace(frame or sys._getframe().f_back)
650 Pdb().set_trace(frame or sys._getframe().f_back)
651
652
653 # Override built-in Pdb, since that version doesn't allow interrupting:
654 import pdb
655 pdb.set_trace = set_trace
656 pdb.Pdb = Pdb
657 del pdb
@@ -6,6 +6,8 b''
6
6
7 import sys
7 import sys
8 import warnings
8 import warnings
9 from tempfile import NamedTemporaryFile
10 from subprocess import check_output
9
11
10 import nose.tools as nt
12 import nose.tools as nt
11
13
@@ -220,3 +222,44 b' def can_exit():'
220
222
221 >>> sys.settrace(old_trace)
223 >>> sys.settrace(old_trace)
222 '''
224 '''
225
226
227 interruptible_debugger = """\
228 import threading
229 import time
230 from os import _exit
231
232 from IPython.core.debugger import set_trace
233
234 def interrupt():
235 time.sleep(0.1)
236 import os, signal
237 os.kill(os.getpid(), signal.SIGINT)
238 threading.Thread(target=interrupt).start()
239
240 # Timeout if the interrupt doesn't happen:
241 def interrupt():
242 time.sleep(2)
243 _exit(7)
244 threading.Thread(target=interrupt, daemon=True).start()
245
246 def main():
247 set_trace()
248
249 if __name__ == '__main__':
250 try:
251 main()
252 except KeyboardInterrupt:
253 print("PASSED")
254 """
255
256
257 def test_interruptible_core_debugger():
258 """The debugger can be interrupted."""
259 with NamedTemporaryFile("w") as f:
260 f.write(interruptible_debugger)
261 f.flush()
262 result = check_output([sys.executable, f.name],
263 encoding=sys.getdefaultencoding())
264 # Wait for it to start:
265 assert "PASSED" in result
General Comments 0
You need to be logged in to leave comments. Login now