mirror of
https://github.com/python/cpython.git
synced 2025-10-14 10:53:40 +00:00
runtest(): I don't know why we don't just use TESTFN, but if we have to
do bizarre things to get a temp file, I changed it to use mkstemp instead of NamedTemporaryFile. This tried to leave the file open while passing its name to execfile(). On Win2K (but not Win9X), though, a file created with O_TEMPORARY cannot be opened again, so the test failed with a permission error when execfile tried to open it. Closer to the truth: a file created with O_TEMPORARY can be opened again, but only if the file is also created with SHARE_DELETE access via the Win32 CreateFile() function. There's no way to get at that from MS's version of libc, though (we'd have to ditch the "std" C file functions in favor of Win32 API calls).
This commit is contained in:
parent
d41bf34825
commit
632a4fbd4d
1 changed files with 5 additions and 4 deletions
|
@ -56,18 +56,19 @@ def runtest(hier, code):
|
||||||
root = tempfile.mkdtemp()
|
root = tempfile.mkdtemp()
|
||||||
mkhier(root, hier)
|
mkhier(root, hier)
|
||||||
savepath = sys.path[:]
|
savepath = sys.path[:]
|
||||||
codefile = tempfile.NamedTemporaryFile()
|
fd, fname = tempfile.mkstemp(binary=False)
|
||||||
codefile.write(code)
|
os.write(fd, code)
|
||||||
codefile.flush()
|
os.close(fd)
|
||||||
try:
|
try:
|
||||||
sys.path.insert(0, root)
|
sys.path.insert(0, root)
|
||||||
if verbose: print "sys.path =", sys.path
|
if verbose: print "sys.path =", sys.path
|
||||||
try:
|
try:
|
||||||
execfile(codefile.name, globals(), {})
|
execfile(fname, globals(), {})
|
||||||
except:
|
except:
|
||||||
traceback.print_exc(file=sys.stdout)
|
traceback.print_exc(file=sys.stdout)
|
||||||
finally:
|
finally:
|
||||||
sys.path[:] = savepath
|
sys.path[:] = savepath
|
||||||
|
os.unlink(fname)
|
||||||
try:
|
try:
|
||||||
cleanout(root)
|
cleanout(root)
|
||||||
except (os.error, IOError):
|
except (os.error, IOError):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue