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