1 """Test embedding of IPython""" 2 3 #----------------------------------------------------------------------------- 4 # Copyright (C) 2013 The IPython Development Team 5 # 6 # Distributed under the terms of the BSD License. The full license is in 7 # the file COPYING, distributed as part of this software. 8 #----------------------------------------------------------------------------- 9 10 #----------------------------------------------------------------------------- 11 # Imports 12 #----------------------------------------------------------------------------- 13 14 import os 15 import sys 16 from IPython.testing.decorators import skip_win32 17 from IPython.testing import IPYTHON_TESTING_TIMEOUT_SCALE 18 19 #----------------------------------------------------------------------------- 20 # Tests 21 #----------------------------------------------------------------------------- 22 23 @skip_win32 24 def test_debug_magic_passes_through_generators(): 25 """ 26 This test that we can correctly pass through frames of a generator post-mortem. 27 """ 28 import pexpect 29 import re 30 in_prompt = re.compile(br'In ?\[\d+\]:') 31 ipdb_prompt = 'ipdb>' 32 env = os.environ.copy() 33 child = pexpect.spawn(sys.executable, ['-m', 'IPython', '--colors=nocolor', '--simple-prompt'], 34 env=env) 35 child.timeout = 15 * IPYTHON_TESTING_TIMEOUT_SCALE 36 37 child.expect(in_prompt) 38 39 child.timeout = 2 * IPYTHON_TESTING_TIMEOUT_SCALE 40 41 child.sendline("def f(x):") 42 child.sendline(" raise Exception") 43 child.sendline("") 44 45 child.expect(in_prompt) 46 child.sendline("gen = (f(x) for x in [0])") 47 child.sendline("") 48 49 child.expect(in_prompt) 50 child.sendline("for x in gen:") 51 child.sendline(" pass") 52 child.sendline("") 53 54 child.timeout = 10 * IPYTHON_TESTING_TIMEOUT_SCALE 55 56 child.expect('Exception:') 57 58 child.expect(in_prompt) 59 child.sendline(r'%debug') 60 child.expect('----> 2 raise Exception') 61 62 child.expect(ipdb_prompt) 63 child.sendline('u') 64 child.expect_exact(r'----> 1 gen = (f(x) for x in [0])') 65 66 child.expect(ipdb_prompt) 67 child.sendline('u') 68 child.expect_exact('----> 1 for x in gen:') 69 70 child.expect(ipdb_prompt) 71 child.sendline("u") 72 child.expect_exact( 73 "*** all frames above hidden, use `skip_hidden False` to get get into those." 74 ) 75 76 child.expect(ipdb_prompt) 77 child.sendline('exit') 78 79 child.expect(in_prompt) 80 child.sendline('exit') 81 82 child.close() 83