Skip to content

Commit 9fa2e02

Browse files
committed
Merged revisions 74838-74839 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r74838 | georg.brandl | 2009-09-16 18:22:12 +0200 (Mi, 16 Sep 2009) | 1 line Remove some more boilerplate from the actual tests in test_pdb. ........ r74839 | georg.brandl | 2009-09-16 18:36:39 +0200 (Mi, 16 Sep 2009) | 1 line Make the pdb displayhook compatible with the standard displayhook: do not print Nones. Add a test for that. ........
1 parent ee8783d commit 9fa2e02

2 files changed

Lines changed: 65 additions & 27 deletions

File tree

Lib/pdb.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,9 @@ def displayhook(self, obj):
208208
"""Custom displayhook for the exec in default(), which prevents
209209
assignment of the _ variable in the builtins.
210210
"""
211-
print(repr(obj))
211+
# reproduce the behavior of the standard displayhook, not printing None
212+
if obj is not None:
213+
print(repr(obj))
212214

213215
def default(self, line):
214216
if line[:1] == '!': line = line[1:]

Lib/test/test_pdb.py

Lines changed: 62 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,70 @@
1212
from test.test_doctest import _FakeInput
1313

1414

15+
class PdbTestInput(object):
16+
"""Context manager that makes testing Pdb in doctests easier."""
17+
18+
def __init__(self, input):
19+
self.input = input
20+
21+
def __enter__(self):
22+
self.real_stdin = sys.stdin
23+
sys.stdin = _FakeInput(self.input)
24+
25+
def __exit__(self, *exc):
26+
sys.stdin = self.real_stdin
27+
28+
29+
def test_pdb_displayhook():
30+
"""This tests the custom displayhook for pdb.
31+
32+
>>> def test_function(foo, bar):
33+
... import pdb; pdb.Pdb().set_trace()
34+
... pass
35+
36+
>>> with PdbTestInput([
37+
... 'foo',
38+
... 'bar',
39+
... 'for i in range(5): print(i)',
40+
... 'continue',
41+
... ]):
42+
... test_function(1, None)
43+
> <doctest test.test_pdb.test_pdb_displayhook[0]>(3)test_function()
44+
-> pass
45+
(Pdb) foo
46+
1
47+
(Pdb) bar
48+
(Pdb) for i in range(5): print(i)
49+
0
50+
1
51+
2
52+
3
53+
4
54+
(Pdb) continue
55+
"""
56+
57+
1558
def test_pdb_skip_modules():
1659
"""This illustrates the simple case of module skipping.
1760
1861
>>> def skip_module():
1962
... import string
2063
... import pdb; pdb.Pdb(skip=['stri*']).set_trace()
2164
... string.capwords('FOO')
22-
>>> real_stdin = sys.stdin
23-
>>> sys.stdin = _FakeInput([
24-
... 'step',
25-
... 'continue',
26-
... ])
2765
28-
>>> try:
66+
>>> with PdbTestInput([
67+
... 'step',
68+
... 'continue',
69+
... ]):
2970
... skip_module()
30-
... finally:
31-
... sys.stdin = real_stdin
3271
> <doctest test.test_pdb.test_pdb_skip_modules[0]>(4)skip_module()
3372
-> string.capwords('FOO')
3473
(Pdb) step
3574
--Return--
3675
> <doctest test.test_pdb.test_pdb_skip_modules[0]>(4)skip_module()->None
3776
-> string.capwords('FOO')
3877
(Pdb) continue
39-
"""
78+
"""
4079

4180

4281
# Module for testing skipping of module that makes a callback
@@ -50,22 +89,19 @@ def test_pdb_skip_modules_with_callback():
5089
>>> def skip_module():
5190
... def callback():
5291
... return None
53-
... import pdb;pdb.Pdb(skip=['module_to_skip*']).set_trace()
92+
... import pdb; pdb.Pdb(skip=['module_to_skip*']).set_trace()
5493
... mod.foo_pony(callback)
55-
>>> real_stdin = sys.stdin
56-
>>> sys.stdin = _FakeInput([
57-
... 'step',
58-
... 'step',
59-
... 'step',
60-
... 'step',
61-
... 'step',
62-
... 'continue',
63-
... ])
64-
65-
>>> try:
94+
95+
>>> with PdbTestInput([
96+
... 'step',
97+
... 'step',
98+
... 'step',
99+
... 'step',
100+
... 'step',
101+
... 'continue',
102+
... ]):
66103
... skip_module()
67-
... finally:
68-
... sys.stdin = real_stdin
104+
... pass # provides something to "step" to
69105
> <doctest test.test_pdb.test_pdb_skip_modules_with_callback[0]>(5)skip_module()
70106
-> mod.foo_pony(callback)
71107
(Pdb) step
@@ -84,10 +120,10 @@ def test_pdb_skip_modules_with_callback():
84120
> <doctest test.test_pdb.test_pdb_skip_modules_with_callback[0]>(5)skip_module()->None
85121
-> mod.foo_pony(callback)
86122
(Pdb) step
87-
> <doctest test.test_pdb.test_pdb_skip_modules_with_callback[3]>(4)<module>()
88-
-> sys.stdin = real_stdin
123+
> <doctest test.test_pdb.test_pdb_skip_modules_with_callback[1]>(10)<module>()
124+
-> pass # provides something to "step" to
89125
(Pdb) continue
90-
"""
126+
"""
91127

92128

93129
def test_main():

0 commit comments

Comments
 (0)