Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(6)

Unified Diff: Lib/doctest.py

Issue 10639: reindent.py converts newlines to platform default
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Lib/distutils/tests/test_build_py.py ('k') | Lib/email/errors.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Lib/doctest.py Tue Jul 26 09:37:46 2011 +0300
+++ b/Lib/doctest.py Mon Jul 25 09:47:18 2011 -0400
@@ -92,15 +92,10 @@
]
import __future__
-import difflib
-import inspect
-import linecache
-import os
-import pdb
-import re
-import sys
-import traceback
-import unittest
+
+import sys, traceback, inspect, linecache, os, re
+import unittest, difflib, pdb, tempfile
+import warnings
from io import StringIO
from collections import namedtuple
@@ -2516,21 +2511,39 @@
"Debug a test script. `src` is the script, as a string."
import pdb
- if globs:
- globs = globs.copy()
- else:
- globs = {}
-
- if pm:
- try:
- exec(src, globs, globs)
- except:
- print(sys.exc_info()[1])
- p = pdb.Pdb(nosigint=True)
- p.reset()
- p.interaction(None, sys.exc_info()[2])
- else:
- pdb.Pdb(nosigint=True).run("exec(%r)" % src, globs, globs)
+ # 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 exec() needs to open and read it.
+ srcfilename = tempfile.mktemp(".py", "doctestdebug")
+ f = open(srcfilename, 'w')
+ f.write(src)
+ f.close()
+
+ try:
+ if globs:
+ globs = globs.copy()
+ else:
+ globs = {}
+
+ if pm:
+ try:
+ with open(srcfilename) as f:
+ exec(f.read(), globs, globs)
+ except:
+ print(sys.exc_info()[1])
+ p = pdb.Pdb(nosigint=True)
+ p.reset()
+ p.interaction(None, sys.exc_info()[2])
+ else:
+ fp = open(srcfilename)
+ try:
+ script = fp.read()
+ finally:
+ fp.close()
+ pdb.Pdb(nosigint=True).run("exec(%r)" % script, globs, globs)
+
+ finally:
+ os.remove(srcfilename)
def debug(module, name, pm=False):
"""Debug a single doctest docstring.
« no previous file with comments | « Lib/distutils/tests/test_build_py.py ('k') | Lib/email/errors.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+