Show More
@@ -59,40 +59,43 b' def test_ipdb_magics():' | |||||
59 |
|
59 | |||
60 | First, set up some test functions and classes which we can inspect. |
|
60 | First, set up some test functions and classes which we can inspect. | |
61 |
|
61 | |||
62 |
|
|
62 | In [1]: class ExampleClass(object): | |
63 | ... """Docstring for ExampleClass.""" |
|
63 | ...: """Docstring for ExampleClass.""" | |
64 | ... def __init__(self): |
|
64 | ...: def __init__(self): | |
65 | ... """Docstring for ExampleClass.__init__""" |
|
65 | ...: """Docstring for ExampleClass.__init__""" | |
66 | ... pass |
|
66 | ...: pass | |
67 | ... def __str__(self): |
|
67 | ...: def __str__(self): | |
68 | ... return "ExampleClass()" |
|
68 | ...: return "ExampleClass()" | |
69 |
|
69 | |||
70 |
|
|
70 | In [2]: def example_function(x, y, z="hello"): | |
71 | ... """Docstring for example_function.""" |
|
71 | ...: """Docstring for example_function.""" | |
72 | ... pass |
|
72 | ...: pass | |
73 |
|
73 | |||
74 |
|
|
74 | In [3]: old_trace = sys.gettrace() | |
75 |
|
75 | |||
76 | Create a function which triggers ipdb. |
|
76 | Create a function which triggers ipdb. | |
77 |
|
77 | |||
78 |
|
|
78 | In [4]: def trigger_ipdb(): | |
79 | ... a = ExampleClass() |
|
79 | ...: a = ExampleClass() | |
80 | ... debugger.Pdb().set_trace() |
|
80 | ...: debugger.Pdb().set_trace() | |
81 |
|
81 | |||
82 | >>> with PdbTestInput([ |
|
82 | Run ipdb with faked input & check output. Because of a difference between | |
83 | ... 'pdef example_function', |
|
83 | Python 3.13 & older versions, the first bit of the output is inconsistent. | |
84 | ... 'pdoc ExampleClass', |
|
84 | We need to use ... to accommodate that, so the examples have to use IPython | |
85 | ... 'up', |
|
85 | prompts so that ... is distinct from the Python PS2 prompt. | |
86 | ... 'down', |
|
86 | ||
87 | ... 'list', |
|
87 | In [5]: with PdbTestInput([ | |
88 | ... 'pinfo a', |
|
88 | ...: 'pdef example_function', | |
89 | ... 'll', |
|
89 | ...: 'pdoc ExampleClass', | |
90 |
|
|
90 | ...: 'up', | |
91 | ... ]): |
|
91 | ...: 'down', | |
92 | ... trigger_ipdb() |
|
92 | ...: 'list', | |
93 | --Return-- |
|
93 | ...: 'pinfo a', | |
94 | None |
|
94 | ...: 'll', | |
95 | > <doctest ...>(3)trigger_ipdb() |
|
95 | ...: 'continue', | |
|
96 | ...: ]): | |||
|
97 | ...: trigger_ipdb() | |||
|
98 | ...> <doctest ...>(3)trigger_ipdb() | |||
96 | 1 def trigger_ipdb(): |
|
99 | 1 def trigger_ipdb(): | |
97 | 2 a = ExampleClass() |
|
100 | 2 a = ExampleClass() | |
98 | ----> 3 debugger.Pdb().set_trace() |
|
101 | ----> 3 debugger.Pdb().set_trace() | |
@@ -112,8 +115,7 b' def test_ipdb_magics():' | |||||
112 | 10 ]): |
|
115 | 10 ]): | |
113 | ---> 11 trigger_ipdb() |
|
116 | ---> 11 trigger_ipdb() | |
114 | <BLANKLINE> |
|
117 | <BLANKLINE> | |
115 | ipdb> down |
|
118 | ipdb> down... | |
116 | None |
|
|||
117 | > <doctest ...>(3)trigger_ipdb() |
|
119 | > <doctest ...>(3)trigger_ipdb() | |
118 | 1 def trigger_ipdb(): |
|
120 | 1 def trigger_ipdb(): | |
119 | 2 a = ExampleClass() |
|
121 | 2 a = ExampleClass() | |
@@ -139,7 +141,7 b' def test_ipdb_magics():' | |||||
139 |
|
141 | |||
140 | Restore previous trace function, e.g. for coverage.py |
|
142 | Restore previous trace function, e.g. for coverage.py | |
141 |
|
143 | |||
142 |
|
|
144 | In [6]: sys.settrace(old_trace) | |
143 | ''' |
|
145 | ''' | |
144 |
|
146 | |||
145 | def test_ipdb_magics2(): |
|
147 | def test_ipdb_magics2(): |
General Comments 0
You need to be logged in to leave comments.
Login now