From 69dfe8d80ed77215b4bfe84138ef070d6c0c7b16 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Wed, 16 Sep 2009 16:36:39 +0000 Subject: Make the pdb displayhook compatible with the standard displayhook: do not print Nones. Add a test for that. --- Lib/pdb.py | 4 +++- Lib/test/test_pdb.py | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/Lib/pdb.py b/Lib/pdb.py index eae6296..0751c17 100755 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -210,7 +210,9 @@ class Pdb(bdb.Bdb, cmd.Cmd): """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:] diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index a15538c..6017edc 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -26,6 +26,38 @@ class PdbTestInput(object): 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) + > (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. @@ -36,7 +68,7 @@ def test_pdb_skip_modules(): >>> with PdbTestInput([ ... 'step', - ... 'continue' + ... 'continue', ... ]): ... skip_module() > (4)skip_module() -- cgit v0.12