Kaydet (Commit) ac6602bd authored tarafından Victor Stinner's avatar Victor Stinner

Issue #12333: restore the previous dir before removing the current directory

packaging.tests.support.TempdirManager: removing the current directory is not
allowed on Windows or Solaris. Store the current directory and restore it
before removing the temporary directory (which is used as the working directory
during the tests).
üst ac059453
...@@ -37,7 +37,7 @@ import tempfile ...@@ -37,7 +37,7 @@ import tempfile
from packaging import logger from packaging import logger
from packaging.dist import Distribution from packaging.dist import Distribution
from packaging.tests import unittest from packaging.tests import unittest
from test.support import requires_zlib from test.support import requires_zlib, unlink
__all__ = ['LoggingCatcher', 'TempdirManager', 'EnvironRestorer', __all__ = ['LoggingCatcher', 'TempdirManager', 'EnvironRestorer',
'DummyCommand', 'unittest', 'create_distribution', 'DummyCommand', 'unittest', 'create_distribution',
...@@ -121,20 +121,17 @@ class TempdirManager: ...@@ -121,20 +121,17 @@ class TempdirManager:
def setUp(self): def setUp(self):
super(TempdirManager, self).setUp() super(TempdirManager, self).setUp()
self._olddir = os.getcwd()
self._basetempdir = tempfile.mkdtemp() self._basetempdir = tempfile.mkdtemp()
self._files = [] self._files = []
def tearDown(self): def tearDown(self):
shutil.rmtree(self._basetempdir, os.name in ('nt', 'cygwin')) os.chdir(self._olddir)
shutil.rmtree(self._basetempdir)
for handle, name in self._files: for handle, name in self._files:
handle.close() handle.close()
if os.path.exists(name): unlink(name)
try:
os.remove(name)
except OSError as exc:
if exc.errno != errno.ENOENT:
raise
super(TempdirManager, self).tearDown() super(TempdirManager, self).tearDown()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment