summaryrefslogtreecommitdiff
path: root/Lib/doctest.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2011-06-30 17:39:17 +0200
committerVictor Stinner <victor.stinner@haypocalc.com>2011-06-30 17:39:17 +0200
commita0b12a1ca7777f8b417b9753b48a443214331243 (patch)
tree2a2346f4498b2d0d5d905ab0c483aa03fb2617e7 /Lib/doctest.py
parent319672e8a6ca3239573340dfb3d8fa46f7f53f0c (diff)
parent12b8d14991d54deedac7d7ca51c7f95006e6a7bc (diff)
downloadcpython-git-a0b12a1ca7777f8b417b9753b48a443214331243.tar.gz
(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).
Diffstat (limited to 'Lib/doctest.py')
-rw-r--r--Lib/doctest.py59
1 files changed, 23 insertions, 36 deletions
diff --git a/Lib/doctest.py b/Lib/doctest.py
index c508a7caf7..be8cc23eb5 100644
--- a/Lib/doctest.py
+++ b/Lib/doctest.py
@@ -92,10 +92,15 @@ __all__ = [
]
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 @@ def debug_script(src, pm=False, globs=None):
"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)
+ if globs:
+ globs = globs.copy()
+ else:
+ globs = {}
- finally:
- os.remove(srcfilename)
+ 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.