Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add basic tests for calling pdef/pdoc/pinfo from ipdb.

  • Loading branch information...
commit 604b310a05e4baea631d54c1aa25bf63e391faf9 1 parent 4767539
@bfroehle authored
Showing with 88 additions and 0 deletions.
  1. +88 −0 IPython/core/tests/test_debugger.py
View
88 IPython/core/tests/test_debugger.py
@@ -12,6 +12,8 @@
# Imports
#-----------------------------------------------------------------------------
+import sys
+
# third-party
import nose.tools as nt
@@ -19,6 +21,38 @@
from IPython.core import debugger
#-----------------------------------------------------------------------------
+# Helper classes, from CPython's Pdb test suite
+#-----------------------------------------------------------------------------
+
+class _FakeInput(object):
+ """
+ A fake input stream for pdb's interactive debugger. Whenever a
+ line is read, print it (to simulate the user typing it), and then
+ return it. The set of lines to return is specified in the
+ constructor; they should not have trailing newlines.
+ """
+ def __init__(self, lines):
+ self.lines = iter(lines)
+
+ def readline(self):
+ line = next(self.lines)
+ print line
+ return line+'\n'
+
+class PdbTestInput(object):
+ """Context manager that makes testing Pdb in doctests easier."""
+
+ def __init__(self, input):
+ self.input = input
+
+ def __enter__(self):
+ self.real_stdin = sys.stdin
+ sys.stdin = _FakeInput(self.input)
+
+ def __exit__(self, *exc):
+ sys.stdin = self.real_stdin
+
+#-----------------------------------------------------------------------------
# Tests
#-----------------------------------------------------------------------------
@@ -33,3 +67,57 @@ def test_longer_repr():
# in-place, since that global is used directly by the stdlib's pdb module.
t = debugger.Tracer()
nt.assert_equal(trepr(a), ar)
+
+def test_ipdb_magics():
+ '''Test calling some IPython magics from ipdb.
+
+ First, set up some test functions and classes which we can inspect.
+
+ >>> class ExampleClass(object):
+ ... """Docstring for ExampleClass."""
+ ... def __init__(self):
+ ... """Docstring for ExampleClass.__init__"""
+ ... pass
+ ... def __str__(self):
+ ... return "ExampleClass()"
+
+ >>> def example_function(x, y, z="hello"):
+ ... """Docstring for example_function."""
+ ... pass
+
+ Create a function which triggers ipdb.
+
+ >>> def trigger_ipdb():
+ ... a = ExampleClass()
+ ... debugger.Pdb().set_trace()
+
+ >>> with PdbTestInput([
+ ... 'pdef example_function',
+ ... 'pdoc ExampleClass',
+ ... 'pinfo a',
+ ... 'continue',
+ ... ]):
+ ... trigger_ipdb()
+ --Return--
+ None
+ > <doctest ...>(3)trigger_ipdb()
+ 1 def trigger_ipdb():
+ 2 a = ExampleClass()
+ ----> 3 debugger.Pdb().set_trace()
+ <BLANKLINE>
+ ipdb> pdef example_function
+ example_function(x, y, z='hello')
+ ipdb> pdoc ExampleClass
+ Class Docstring:
+ Docstring for ExampleClass.
+ Constructor Docstring:
+ Docstring for ExampleClass.__init__
+ ipdb> pinfo a
+ Type: ExampleClass
+ String Form:ExampleClass()
+ Namespace: Locals
+ File: ...
+ Docstring: Docstring for ExampleClass.
+ Constructor Docstring:Docstring for ExampleClass.__init__
+ ipdb> continue
+ '''
Please sign in to comment.
Something went wrong with that request. Please try again.