Show More
@@ -477,19 +477,20 b' class Pdb(OldPdb):' | |||||
477 | """The debugger interface to magic_pdef""" |
|
477 | """The debugger interface to magic_pdef""" | |
478 | namespaces = [('Locals', self.curframe.f_locals), |
|
478 | namespaces = [('Locals', self.curframe.f_locals), | |
479 | ('Globals', self.curframe.f_globals)] |
|
479 | ('Globals', self.curframe.f_globals)] | |
480 |
self.shell. |
|
480 | self.shell.find_line_magic('pdef')(arg, namespaces=namespaces) | |
481 |
|
481 | |||
482 | def do_pdoc(self, arg): |
|
482 | def do_pdoc(self, arg): | |
483 | """The debugger interface to magic_pdoc""" |
|
483 | """The debugger interface to magic_pdoc""" | |
484 | namespaces = [('Locals', self.curframe.f_locals), |
|
484 | namespaces = [('Locals', self.curframe.f_locals), | |
485 | ('Globals', self.curframe.f_globals)] |
|
485 | ('Globals', self.curframe.f_globals)] | |
486 |
self.shell. |
|
486 | self.shell.find_line_magic('pdoc')(arg, namespaces=namespaces) | |
487 |
|
487 | |||
488 | def do_pinfo(self, arg): |
|
488 | def do_pinfo(self, arg): | |
489 | """The debugger equivalant of ?obj""" |
|
489 | """The debugger equivalant of ?obj""" | |
490 | namespaces = [('Locals', self.curframe.f_locals), |
|
490 | namespaces = [('Locals', self.curframe.f_locals), | |
491 | ('Globals', self.curframe.f_globals)] |
|
491 | ('Globals', self.curframe.f_globals)] | |
492 |
self.shell. |
|
492 | self.shell.find_line_magic('pinfo')("pinfo %s" % arg, | |
|
493 | namespaces=namespaces) | |||
493 |
|
494 | |||
494 | def checkline(self, filename, lineno): |
|
495 | def checkline(self, filename, lineno): | |
495 | """Check whether specified line seems to be executable. |
|
496 | """Check whether specified line seems to be executable. |
@@ -1478,7 +1478,7 b' class InteractiveShell(SingletonConfigurable):' | |||||
1478 | """Generic interface to the inspector system. |
|
1478 | """Generic interface to the inspector system. | |
1479 |
|
1479 | |||
1480 | This function is meant to be called by pdef, pdoc & friends.""" |
|
1480 | This function is meant to be called by pdef, pdoc & friends.""" | |
1481 | info = self._object_find(oname) |
|
1481 | info = self._object_find(oname, namespaces) | |
1482 | if info.found: |
|
1482 | if info.found: | |
1483 | pmethod = getattr(self.inspector, meth) |
|
1483 | pmethod = getattr(self.inspector, meth) | |
1484 | formatter = format_screen if info.ismagic else None |
|
1484 | formatter = format_screen if info.ismagic else None |
@@ -12,6 +12,8 b'' | |||||
12 | # Imports |
|
12 | # Imports | |
13 | #----------------------------------------------------------------------------- |
|
13 | #----------------------------------------------------------------------------- | |
14 |
|
14 | |||
|
15 | import sys | |||
|
16 | ||||
15 | # third-party |
|
17 | # third-party | |
16 | import nose.tools as nt |
|
18 | import nose.tools as nt | |
17 |
|
19 | |||
@@ -19,6 +21,38 b' import nose.tools as nt' | |||||
19 | from IPython.core import debugger |
|
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 | # Tests |
|
56 | # Tests | |
23 | #----------------------------------------------------------------------------- |
|
57 | #----------------------------------------------------------------------------- | |
24 |
|
58 | |||
@@ -33,3 +67,57 b' def test_longer_repr():' | |||||
33 | # in-place, since that global is used directly by the stdlib's pdb module. |
|
67 | # in-place, since that global is used directly by the stdlib's pdb module. | |
34 | t = debugger.Tracer() |
|
68 | t = debugger.Tracer() | |
35 | nt.assert_equals(trepr(a), ar) |
|
69 | nt.assert_equals(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