[Python-checkins] python/dist/src/Lib doctest.py,1.54,1.55
tim_one at users.sourceforge.net
tim_one at users.sourceforge.net
Mon Aug 9 17:43:49 CEST 2004
Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22785/Lib
Modified Files:
doctest.py
Log Message:
This started as a spelling and whitespace cleanup. The comment for
the set_trace fiddling didn't make sense to me, and I ended up reworking
that part of the code. We really do want to save and restore
pdb.set_trace, so that each dynamically nested level of doctest gets
sys.stdout fiddled to what's appropriate for *it*. The only "trick"
really needed is that these layers of set_trace wrappers each call the
original pdb.set_trace (instead of the current pdb.set_trace).
Index: doctest.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/doctest.py,v
retrieving revision 1.54
retrieving revision 1.55
diff -C2 -d -r1.54 -r1.55
*** doctest.py 9 Aug 2004 11:34:47 -0000 1.54
--- doctest.py 9 Aug 2004 15:43:46 -0000 1.55
***************
*** 1255,1279 ****
compileflags = _extract_future_flags(test.globs)
if out is None:
! out = sys.stdout.write
! saveout = sys.stdout
! # Note that don't save away the previous pdb.set_trace. Rather,
! # we safe pdb.set_trace on import (see import section above).
! # We then call and restore that original cersion. We do it this
! # way to make this feature testable. If we kept and called the
! # previous version, we'd end up restoring the original stdout,
! # which is not what we want.
def set_trace():
! sys.stdout = saveout
real_pdb_set_trace()
try:
- sys.stdout = self._fakeout
- pdb.set_trace = set_trace
return self.__run(test, compileflags, out)
finally:
! sys.stdout = saveout
! pdb.set_trace = real_pdb_set_trace
if clear_globs:
test.globs.clear()
--- 1255,1282 ----
compileflags = _extract_future_flags(test.globs)
+ save_stdout = sys.stdout
if out is None:
! out = save_stdout.write
! sys.stdout = self._fakeout
! # Patch pdb.set_trace to restore sys.stdout, so that interactive
! # debugging output is visible (not still redirected to self._fakeout).
! # Note that we run "the real" pdb.set_trace (captured at doctest
! # import time) in our replacement. Because the current run() may
! # run another doctest (and so on), the current pdb.set_trace may be
! # our set_trace function, which changes sys.stdout. If we called
! # a chain of those, we wouldn't be left with the save_stdout
! # *this* run() invocation wants.
def set_trace():
! sys.stdout = save_stdout
real_pdb_set_trace()
+ save_set_trace = pdb.set_trace
+ pdb.set_trace = set_trace
try:
return self.__run(test, compileflags, out)
finally:
! sys.stdout = save_stdout
! pdb.set_trace = save_set_trace
if clear_globs:
test.globs.clear()
More information about the Python-checkins
mailing list