Debian Codegraph @

tests/test_debug_magic.py

raw
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
24 @skip_win32
25 def test_debug_magic_passes_through_generators():
26 """
27 This test that we can correctly pass through frames of a generator post-mortem.
28 """
29 import pexpect
30 import re
31
32 in_prompt = re.compile(rb"In ?\[\d+\]:")
33 ipdb_prompt = "ipdb>"
34 env = os.environ.copy()
35 child = pexpect.spawn(
36 sys.executable,
37 ["-m", "IPython", "--colors=nocolor", "--simple-prompt"],
38 env=env,
39 )
40 child.timeout = 15 * IPYTHON_TESTING_TIMEOUT_SCALE
41
42 child.expect(in_prompt)
43
44 child.timeout = 2 * IPYTHON_TESTING_TIMEOUT_SCALE
45
46 child.sendline("def f(x):")
47 child.sendline(" raise Exception")
48 child.sendline("")
49
50 child.expect(in_prompt)
51 child.sendline("gen = (f(x) for x in [0])")
52 child.sendline("")
53
54 child.expect(in_prompt)
55 child.sendline("for x in gen:")
56 child.sendline(" pass")
57 child.sendline("")
58
59 child.timeout = 10 * IPYTHON_TESTING_TIMEOUT_SCALE
60
61 child.expect("Exception:")
62
63 child.expect(in_prompt)
64 child.sendline(r"%debug")
65 child.expect("----> 2 raise Exception")
66
67 child.expect(ipdb_prompt)
68 child.sendline("u")
69 child.expect_exact(r"----> 1 gen = (f(x) for x in [0])")
70
71 child.expect(ipdb_prompt)
72 child.sendline("u")
73 child.expect_exact("----> 1 for x in gen:")
74
75 child.expect(ipdb_prompt)
76 child.sendline("u")
77 child.expect_exact(
78 "*** all frames above skipped (hidden frames and ignored modules). Use `skip_hidden False` for hidden frames or unignore_module for ignored modules."
79 )
80
81 child.expect(ipdb_prompt)
82 child.sendline("exit")
83
84 child.expect(in_prompt)
85 child.sendline("exit")
86
87 child.close()