Commit b6a04d68 authored by Tim Peters's avatar Tim Peters

debug_script(): I changed this in haste before to take out the use of

NamedTemporaryFile (which can't work for this function's purposes on
Windows).  Leaving temp files behind wasn't a great idea either, though,
so try to clean up.  At least the test suite no longer leaves any of
these guys behind now.
parent 31bd529f
...@@ -2342,26 +2342,33 @@ def debug_script(src, pm=False, globs=None): ...@@ -2342,26 +2342,33 @@ def debug_script(src, pm=False, globs=None):
"Debug a test script. `src` is the script, as a string." "Debug a test script. `src` is the script, as a string."
import pdb import pdb
srcfilename = tempfile.mktemp("doctestdebug.py") # Note that tempfile.NameTemporaryFile() cannot be used. As the
# docs say, a file so created cannot be opened by name a second time
# on modern Windows boxes, and execfile() needs to open it.
srcfilename = tempfile.mktemp(".py", "doctestdebug")
f = open(srcfilename, 'w') f = open(srcfilename, 'w')
f.write(src) f.write(src)
f.close() f.close()
if globs: try:
globs = globs.copy() if globs:
else: globs = globs.copy()
globs = {} else:
globs = {}
if pm: if pm:
try: try:
execfile(srcfilename, globs, globs) execfile(srcfilename, globs, globs)
except: except:
print sys.exc_info()[1] print sys.exc_info()[1]
pdb.post_mortem(sys.exc_info()[2]) pdb.post_mortem(sys.exc_info()[2])
else: else:
# Note that %r is vital here. '%s' instead can, e.g., cause # Note that %r is vital here. '%s' instead can, e.g., cause
# backslashes to get treated as metacharacters on Windows. # backslashes to get treated as metacharacters on Windows.
pdb.run("execfile(%r)" % srcfilename, globs, globs) pdb.run("execfile(%r)" % srcfilename, globs, globs)
finally:
os.remove(srcfilename)
def debug(module, name, pm=False): def debug(module, name, pm=False):
"""Debug a single doctest docstring. """Debug a single doctest docstring.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment