Show More
@@ -478,19 +478,20 b' class Pdb(OldPdb):' | |||
|
478 | 478 | """The debugger interface to magic_pdef""" |
|
479 | 479 | namespaces = [('Locals', self.curframe.f_locals), |
|
480 | 480 | ('Globals', self.curframe.f_globals)] |
|
481 |
self.shell. |
|
|
481 | self.shell.find_line_magic('pdef')(arg, namespaces=namespaces) | |
|
482 | 482 | |
|
483 | 483 | def do_pdoc(self, arg): |
|
484 | 484 | """The debugger interface to magic_pdoc""" |
|
485 | 485 | namespaces = [('Locals', self.curframe.f_locals), |
|
486 | 486 | ('Globals', self.curframe.f_globals)] |
|
487 |
self.shell. |
|
|
487 | self.shell.find_line_magic('pdoc')(arg, namespaces=namespaces) | |
|
488 | 488 | |
|
489 | 489 | def do_pinfo(self, arg): |
|
490 | 490 | """The debugger equivalant of ?obj""" |
|
491 | 491 | namespaces = [('Locals', self.curframe.f_locals), |
|
492 | 492 | ('Globals', self.curframe.f_globals)] |
|
493 |
self.shell. |
|
|
493 | self.shell.find_line_magic('pinfo')("pinfo %s" % arg, | |
|
494 | namespaces=namespaces) | |
|
494 | 495 | |
|
495 | 496 | def checkline(self, filename, lineno): |
|
496 | 497 | """Check whether specified line seems to be executable. |
@@ -1487,7 +1487,7 b' class InteractiveShell(SingletonConfigurable):' | |||
|
1487 | 1487 | """Generic interface to the inspector system. |
|
1488 | 1488 | |
|
1489 | 1489 | This function is meant to be called by pdef, pdoc & friends.""" |
|
1490 | info = self._object_find(oname) | |
|
1490 | info = self._object_find(oname, namespaces) | |
|
1491 | 1491 | if info.found: |
|
1492 | 1492 | pmethod = getattr(self.inspector, meth) |
|
1493 | 1493 | formatter = format_screen if info.ismagic else None |
@@ -12,6 +12,8 b'' | |||
|
12 | 12 | # Imports |
|
13 | 13 | #----------------------------------------------------------------------------- |
|
14 | 14 | |
|
15 | import sys | |
|
16 | ||
|
15 | 17 | # third-party |
|
16 | 18 | import nose.tools as nt |
|
17 | 19 | |
@@ -19,6 +21,38 b' import nose.tools as nt' | |||
|
19 | 21 | from IPython.core import debugger |
|
20 | 22 | |
|
21 | 23 | #----------------------------------------------------------------------------- |
|
24 | # Helper classes, from CPython's Pdb test suite | |
|
25 | #----------------------------------------------------------------------------- | |
|
26 | ||
|
27 | class _FakeInput(object): | |
|
28 | """ | |
|
29 | A fake input stream for pdb's interactive debugger. Whenever a | |
|
30 | line is read, print it (to simulate the user typing it), and then | |
|
31 | return it. The set of lines to return is specified in the | |
|
32 | constructor; they should not have trailing newlines. | |
|
33 | """ | |
|
34 | def __init__(self, lines): | |
|
35 | self.lines = iter(lines) | |
|
36 | ||
|
37 | def readline(self): | |
|
38 | line = next(self.lines) | |
|
39 | print line | |
|
40 | return line+'\n' | |
|
41 | ||
|
42 | class PdbTestInput(object): | |
|
43 | """Context manager that makes testing Pdb in doctests easier.""" | |
|
44 | ||
|
45 | def __init__(self, input): | |
|
46 | self.input = input | |
|
47 | ||
|
48 | def __enter__(self): | |
|
49 | self.real_stdin = sys.stdin | |
|
50 | sys.stdin = _FakeInput(self.input) | |
|
51 | ||
|
52 | def __exit__(self, *exc): | |
|
53 | sys.stdin = self.real_stdin | |
|
54 | ||
|
55 | #----------------------------------------------------------------------------- | |
|
22 | 56 | # Tests |
|
23 | 57 | #----------------------------------------------------------------------------- |
|
24 | 58 | |
@@ -33,3 +67,57 b' def test_longer_repr():' | |||
|
33 | 67 | # in-place, since that global is used directly by the stdlib's pdb module. |
|
34 | 68 | t = debugger.Tracer() |
|
35 | 69 | nt.assert_equal(trepr(a), ar) |
|
70 | ||
|
71 | def test_ipdb_magics(): | |
|
72 | '''Test calling some IPython magics from ipdb. | |
|
73 | ||
|
74 | First, set up some test functions and classes which we can inspect. | |
|
75 | ||
|
76 | >>> class ExampleClass(object): | |
|
77 | ... """Docstring for ExampleClass.""" | |
|
78 | ... def __init__(self): | |
|
79 | ... """Docstring for ExampleClass.__init__""" | |
|
80 | ... pass | |
|
81 | ... def __str__(self): | |
|
82 | ... return "ExampleClass()" | |
|
83 | ||
|
84 | >>> def example_function(x, y, z="hello"): | |
|
85 | ... """Docstring for example_function.""" | |
|
86 | ... pass | |
|
87 | ||
|
88 | Create a function which triggers ipdb. | |
|
89 | ||
|
90 | >>> def trigger_ipdb(): | |
|
91 | ... a = ExampleClass() | |
|
92 | ... debugger.Pdb().set_trace() | |
|
93 | ||
|
94 | >>> with PdbTestInput([ | |
|
95 | ... 'pdef example_function', | |
|
96 | ... 'pdoc ExampleClass', | |
|
97 | ... 'pinfo a', | |
|
98 | ... 'continue', | |
|
99 | ... ]): | |
|
100 | ... trigger_ipdb() | |
|
101 | --Return-- | |
|
102 | None | |
|
103 | > <doctest ...>(3)trigger_ipdb() | |
|
104 | 1 def trigger_ipdb(): | |
|
105 | 2 a = ExampleClass() | |
|
106 | ----> 3 debugger.Pdb().set_trace() | |
|
107 | <BLANKLINE> | |
|
108 | ipdb> pdef example_function | |
|
109 | example_function(x, y, z='hello') | |
|
110 | ipdb> pdoc ExampleClass | |
|
111 | Class Docstring: | |
|
112 | Docstring for ExampleClass. | |
|
113 | Constructor Docstring: | |
|
114 | Docstring for ExampleClass.__init__ | |
|
115 | ipdb> pinfo a | |
|
116 | Type: ExampleClass | |
|
117 | String Form:ExampleClass() | |
|
118 | Namespace: Locals | |
|
119 | File: ... | |
|
120 | Docstring: Docstring for ExampleClass. | |
|
121 | Constructor Docstring:Docstring for ExampleClass.__init__ | |
|
122 | ipdb> continue | |
|
123 | ''' |
General Comments 0
You need to be logged in to leave comments.
Login now