mirror of
https://github.com/python/cpython.git
synced 2025-11-08 21:52:45 +00:00
Fix #15496. Add directory removal helpers to make Windows tests more reliable. Patch by Jeremy Kloth
This commit is contained in:
parent
33f87a59b8
commit
bc77d3690b
2 changed files with 69 additions and 2 deletions
|
|
@ -181,15 +181,79 @@ def unload(name):
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
if sys.platform.startswith("win"):
|
||||||
|
def _waitfor(func, pathname, waitall=False):
|
||||||
|
# Peform the operation
|
||||||
|
func(pathname)
|
||||||
|
# Now setup the wait loop
|
||||||
|
if waitall:
|
||||||
|
dirname = pathname
|
||||||
|
else:
|
||||||
|
dirname, name = os.path.split(pathname)
|
||||||
|
dirname = dirname or '.'
|
||||||
|
# Check for `pathname` to be removed from the filesystem.
|
||||||
|
# The exponential backoff of the timeout amounts to a total
|
||||||
|
# of ~1 second after which the deletion is probably an error
|
||||||
|
# anyway.
|
||||||
|
# Testing on a i7@4.3GHz shows that usually only 1 iteration is
|
||||||
|
# required when contention occurs.
|
||||||
|
timeout = 0.001
|
||||||
|
while timeout < 1.0:
|
||||||
|
# Note we are only testing for the existance of the file(s) in
|
||||||
|
# the contents of the directory regardless of any security or
|
||||||
|
# access rights. If we have made it this far, we have sufficient
|
||||||
|
# permissions to do that much using Python's equivalent of the
|
||||||
|
# Windows API FindFirstFile.
|
||||||
|
# Other Windows APIs can fail or give incorrect results when
|
||||||
|
# dealing with files that are pending deletion.
|
||||||
|
L = os.listdir(dirname)
|
||||||
|
if not (L if waitall else name in L):
|
||||||
|
return
|
||||||
|
# Increase the timeout and try again
|
||||||
|
time.sleep(timeout)
|
||||||
|
timeout *= 2
|
||||||
|
warnings.warn('tests may fail, delete still pending for ' + pathname,
|
||||||
|
RuntimeWarning, stacklevel=4)
|
||||||
|
|
||||||
|
def _unlink(filename):
|
||||||
|
_waitfor(os.unlink, filename)
|
||||||
|
|
||||||
|
def _rmdir(dirname):
|
||||||
|
_waitfor(os.rmdir, dirname)
|
||||||
|
|
||||||
|
def _rmtree(path):
|
||||||
|
def _rmtree_inner(path):
|
||||||
|
for name in os.listdir(path):
|
||||||
|
fullname = os.path.join(path, name)
|
||||||
|
if os.path.isdir(fullname):
|
||||||
|
_waitfor(_rmtree_inner, fullname, waitall=True)
|
||||||
|
os.rmdir(fullname)
|
||||||
|
else:
|
||||||
|
os.unlink(fullname)
|
||||||
|
_waitfor(_rmtree_inner, path, waitall=True)
|
||||||
|
_waitfor(os.rmdir, path)
|
||||||
|
else:
|
||||||
|
_unlink = os.unlink
|
||||||
|
_rmdir = os.rmdir
|
||||||
|
_rmtree = shutil.rmtree
|
||||||
|
|
||||||
def unlink(filename):
|
def unlink(filename):
|
||||||
try:
|
try:
|
||||||
os.unlink(filename)
|
_unlink(filename)
|
||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def rmdir(dirname):
|
||||||
|
try:
|
||||||
|
_rmdir(dirname)
|
||||||
|
except OSError as error:
|
||||||
|
# The directory need not exist.
|
||||||
|
if error.errno != errno.ENOENT:
|
||||||
|
raise
|
||||||
|
|
||||||
def rmtree(path):
|
def rmtree(path):
|
||||||
try:
|
try:
|
||||||
shutil.rmtree(path)
|
_rmtree(path)
|
||||||
except OSError, e:
|
except OSError, e:
|
||||||
# Unix returns ENOENT, Windows returns ESRCH.
|
# Unix returns ENOENT, Windows returns ESRCH.
|
||||||
if e.errno not in (errno.ENOENT, errno.ESRCH):
|
if e.errno not in (errno.ENOENT, errno.ESRCH):
|
||||||
|
|
|
||||||
|
|
@ -323,6 +323,9 @@ Library
|
||||||
Tests
|
Tests
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
- Issue #15496: Add directory removal helpers for tests on Windows.
|
||||||
|
Patch by Jeremy Kloth.
|
||||||
|
|
||||||
- Issue #15043: test_gdb is now skipped entirely if gdb security settings
|
- Issue #15043: test_gdb is now skipped entirely if gdb security settings
|
||||||
block loading of the gdb hooks
|
block loading of the gdb hooks
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue