[Python-checkins] cpython (merge 3.2 -> default): (merge 3.2) Issue #12451: doctest.debug_script() doesn't create a temporary
victor.stinner
python-checkins at python.org
Thu Jun 30 17:39:42 CEST 2011
http://hg.python.org/cpython/rev/77c589b27e90
changeset: 71094:77c589b27e90
parent: 71092:3e627877b5a9
parent: 71093:bafc5c7d24b2
user: Victor Stinner <victor.stinner at haypocalc.com>
date: Thu Jun 30 17:39:17 2011 +0200
summary:
(merge 3.2) Issue #12451: doctest.debug_script() doesn't create a temporary
file anymore to avoid encoding issues (it used the locale encoding, whereas
UTF-8 should be).
Remove also an unused import (warnings).
files:
Lib/doctest.py | 61 ++++++++++++++-----------------------
Misc/NEWS | 3 +
2 files changed, 27 insertions(+), 37 deletions(-)
diff --git a/Lib/doctest.py b/Lib/doctest.py
--- a/Lib/doctest.py
+++ b/Lib/doctest.py
@@ -92,10 +92,15 @@
]
import __future__
-
-import sys, traceback, inspect, linecache, os, re
-import unittest, difflib, pdb, tempfile
-import warnings
+import difflib
+import inspect
+import linecache
+import os
+import pdb
+import re
+import sys
+import traceback
+import unittest
from io import StringIO
from collections import namedtuple
@@ -2511,39 +2516,21 @@
"Debug a test script. `src` is the script, as a string."
import pdb
- # 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)
+ 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)
def debug(module, name, pm=False):
"""Debug a single doctest docstring.
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -200,6 +200,9 @@
Library
-------
+- Issue #12451: doctest.debug_script() doesn't create a temporary file
+ anymore to avoid encoding issues.
+
- Issue #12451: pydoc.synopsis() now reads the encoding cookie if available,
to read the Python script from the right encoding.
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list