test_doctest.py test_pdb_set_trace_nested(): A new test from Jim Fulton
showing that doctest's pdb.set_trace() support was dramatically broken. doctest.py _OutputRedirectingPdb.trace_dispatch(): Return a local trace function instead of (implicitly) None. Else interaction with pdb was bizarre, noticing only 'call' events. Amazingly, the existing set_trace() tests didn't care.
This commit is contained in:
parent
e0b855fac9
commit
50c6bdb1d6
|
@ -105,8 +105,6 @@ from StringIO import StringIO
|
|||
warnings.filterwarnings("ignore", "is_private", DeprecationWarning,
|
||||
__name__, 0)
|
||||
|
||||
real_pdb_set_trace = pdb.set_trace
|
||||
|
||||
# There are 4 basic classes:
|
||||
# - Example: a <source, want> pair, plus an intra-docstring line number.
|
||||
# - DocTest: a collection of examples, parsed from a docstring, plus
|
||||
|
@ -350,9 +348,10 @@ class _OutputRedirectingPdb(pdb.Pdb):
|
|||
save_stdout = sys.stdout
|
||||
sys.stdout = self.__out
|
||||
# Call Pdb's trace dispatch method.
|
||||
pdb.Pdb.trace_dispatch(self, *args)
|
||||
result = pdb.Pdb.trace_dispatch(self, *args)
|
||||
# Restore stdout.
|
||||
sys.stdout = save_stdout
|
||||
return result
|
||||
|
||||
# [XX] Normalize with respect to os.path.pardir?
|
||||
def _module_relative_path(module, path):
|
||||
|
|
|
@ -1568,7 +1568,7 @@ Run the debugger on the docstring, and then restore sys.stdin.
|
|||
"""
|
||||
|
||||
def test_pdb_set_trace():
|
||||
"""Using pdb.set_trace from a doctest
|
||||
"""Using pdb.set_trace from a doctest.
|
||||
|
||||
You can use pdb.set_trace from a doctest. To do so, you must
|
||||
retrieve the set_trace function from the pdb module at the time
|
||||
|
@ -1624,8 +1624,10 @@ def test_pdb_set_trace():
|
|||
... 'continue', # stop debugging
|
||||
... ''])
|
||||
|
||||
>>> try: runner.run(test)
|
||||
... finally: sys.stdin = real_stdin
|
||||
>>> try:
|
||||
... runner.run(test)
|
||||
... finally:
|
||||
... sys.stdin = real_stdin
|
||||
--Return--
|
||||
> <doctest test.test_doctest.test_pdb_set_trace[8]>(3)calls_set_trace()->None
|
||||
-> import pdb; pdb.set_trace()
|
||||
|
@ -1697,6 +1699,91 @@ def test_pdb_set_trace():
|
|||
(1, 3)
|
||||
"""
|
||||
|
||||
def test_pdb_set_trace_nested():
|
||||
"""This illustrates more-demanding use of set_trace with nested functions.
|
||||
|
||||
>>> class C(object):
|
||||
... def calls_set_trace(self):
|
||||
... y = 1
|
||||
... import pdb; pdb.set_trace()
|
||||
... self.f1()
|
||||
... y = 2
|
||||
... def f1(self):
|
||||
... x = 1
|
||||
... self.f2()
|
||||
... x = 2
|
||||
... def f2(self):
|
||||
... z = 1
|
||||
... z = 2
|
||||
|
||||
>>> calls_set_trace = C().calls_set_trace
|
||||
|
||||
>>> doc = '''
|
||||
... >>> a = 1
|
||||
... >>> calls_set_trace()
|
||||
... '''
|
||||
>>> parser = doctest.DocTestParser()
|
||||
>>> runner = doctest.DocTestRunner(verbose=False)
|
||||
>>> test = parser.get_doctest(doc, globals(), "foo", "foo.py", 0)
|
||||
>>> real_stdin = sys.stdin
|
||||
>>> sys.stdin = _FakeInput([
|
||||
... 'print y', # print data defined in the function
|
||||
... 'step', 'step', 'step', 'step', 'step', 'step', 'print z',
|
||||
... 'up', 'print x',
|
||||
... 'up', 'print y',
|
||||
... 'up', 'print foo',
|
||||
... 'continue', # stop debugging
|
||||
... ''])
|
||||
|
||||
>>> try:
|
||||
... runner.run(test)
|
||||
... finally:
|
||||
... sys.stdin = real_stdin
|
||||
> <doctest test.test_doctest.test_pdb_set_trace_nested[0]>(5)calls_set_trace()
|
||||
-> self.f1()
|
||||
(Pdb) print y
|
||||
1
|
||||
(Pdb) step
|
||||
--Call--
|
||||
> <doctest test.test_doctest.test_pdb_set_trace_nested[0]>(7)f1()
|
||||
-> def f1(self):
|
||||
(Pdb) step
|
||||
> <doctest test.test_doctest.test_pdb_set_trace_nested[0]>(8)f1()
|
||||
-> x = 1
|
||||
(Pdb) step
|
||||
> <doctest test.test_doctest.test_pdb_set_trace_nested[0]>(9)f1()
|
||||
-> self.f2()
|
||||
(Pdb) step
|
||||
--Call--
|
||||
> <doctest test.test_doctest.test_pdb_set_trace_nested[0]>(11)f2()
|
||||
-> def f2(self):
|
||||
(Pdb) step
|
||||
> <doctest test.test_doctest.test_pdb_set_trace_nested[0]>(12)f2()
|
||||
-> z = 1
|
||||
(Pdb) step
|
||||
> <doctest test.test_doctest.test_pdb_set_trace_nested[0]>(13)f2()
|
||||
-> z = 2
|
||||
(Pdb) print z
|
||||
1
|
||||
(Pdb) up
|
||||
> <doctest test.test_doctest.test_pdb_set_trace_nested[0]>(9)f1()
|
||||
-> self.f2()
|
||||
(Pdb) print x
|
||||
1
|
||||
(Pdb) up
|
||||
> <doctest test.test_doctest.test_pdb_set_trace_nested[0]>(5)calls_set_trace()
|
||||
-> self.f1()
|
||||
(Pdb) print y
|
||||
1
|
||||
(Pdb) up
|
||||
> <doctest foo[1]>(1)?()
|
||||
-> calls_set_trace()
|
||||
(Pdb) print foo
|
||||
*** NameError: name 'foo' is not defined
|
||||
(Pdb) continue
|
||||
(0, 2)
|
||||
"""
|
||||
|
||||
def test_DocTestSuite():
|
||||
"""DocTestSuite creates a unittest test suite from a doctest.
|
||||
|
||||
|
|
|
@ -29,7 +29,10 @@ Library
|
|||
attempt is made to execute the remaining handlers. The last exception
|
||||
raised is re-raised.
|
||||
|
||||
- Patch 1061679: Added `__all__` to pickletools.py.
|
||||
- ``doctest``'s new support for adding ``pdb.set_trace()`` calls to
|
||||
doctests was broken in a dramatic but shallow way. Fixed.
|
||||
|
||||
- Patch 1061679: Added ``__all__`` to pickletools.py.
|
||||
|
||||
Build
|
||||
-----
|
||||
|
|
Loading…
Reference in New Issue