Commits

Anonymous committed 818f7c3

[svn r74839] Make the pdb displayhook compatible with the standard displayhook: do not print Nones. Add a test for that.

Comments (0)

Files changed (2)

         """Custom displayhook for the exec in default(), which prevents
         assignment of the _ variable in the builtins.
         """
-        print repr(obj)
+        # reproduce the behavior of the standard displayhook, not printing None
+        if obj is not None:
+            print repr(obj)
 
     def default(self, line):
         if line[:1] == '!': line = line[1:]

Lib/test/test_pdb.py

         sys.stdin = self.real_stdin
 
 
+def write(x):
+    print x
+
+def test_pdb_displayhook():
+    """This tests the custom displayhook for pdb.
+
+    >>> def test_function(foo, bar):
+    ...     import pdb; pdb.Pdb().set_trace()
+    ...     pass
+
+    >>> with PdbTestInput([
+    ...     'foo',
+    ...     'bar',
+    ...     'for i in range(5): write(i)',
+    ...     'continue',
+    ... ]):
+    ...     test_function(1, None)
+    > <doctest test.test_pdb.test_pdb_displayhook[0]>(3)test_function()
+    -> pass
+    (Pdb) foo
+    1
+    (Pdb) bar
+    (Pdb) for i in range(5): write(i)
+    0
+    1
+    2
+    3
+    4
+    (Pdb) continue
+    """
+
+
 def test_pdb_skip_modules():
     """This illustrates the simple case of module skipping.
 
 
     >>> with PdbTestInput([
     ...     'step',
-    ...     'continue'
+    ...     'continue',
     ... ]):
     ...     skip_module()
     > <doctest test.test_pdb.test_pdb_skip_modules[0]>(4)skip_module()