[Python-checkins] cpython: fixed a few mocking/cleanup issues in packaging test_util for win32
tarek.ziade
python-checkins at python.org
Sat May 21 10:38:13 CEST 2011
http://hg.python.org/cpython/rev/fd6acce980fa
changeset: 70241:fd6acce980fa
user: Tarek Ziade <tarek at ziade.org>
date: Sat May 21 10:37:58 2011 +0200
summary:
fixed a few mocking/cleanup issues in packaging test_util for win32
files:
Lib/packaging/tests/support.py | 22 ++++++++++---------
Lib/packaging/tests/test_util.py | 13 +++++++----
2 files changed, 20 insertions(+), 15 deletions(-)
diff --git a/Lib/packaging/tests/support.py b/Lib/packaging/tests/support.py
--- a/Lib/packaging/tests/support.py
+++ b/Lib/packaging/tests/support.py
@@ -112,26 +112,28 @@
def setUp(self):
super(TempdirManager, self).setUp()
self._basetempdir = tempfile.mkdtemp()
+ self._files = []
def tearDown(self):
shutil.rmtree(self._basetempdir, os.name in ('nt', 'cygwin'))
+
+ for handle, name in self._files:
+ handle.close()
+ if os.path.exists(name):
+ try:
+ os.remove(name)
+ except OSError as exc:
+ if exc.errno != errno.ENOENT:
+ raise
+
super(TempdirManager, self).tearDown()
def mktempfile(self):
"""Create a read-write temporary file and return it."""
-
- def _delete_file(filename):
- try:
- os.remove(filename)
- except OSError as exc:
- if exc.errno != errno.ENOENT:
- raise
-
fd, fn = tempfile.mkstemp(dir=self._basetempdir)
os.close(fd)
fp = open(fn, 'w+')
- self.addCleanup(fp.close)
- self.addCleanup(_delete_file, fn)
+ self._files.append((fp, fn))
return fp
def mkdtemp(self):
diff --git a/Lib/packaging/tests/test_util.py b/Lib/packaging/tests/test_util.py
--- a/Lib/packaging/tests/test_util.py
+++ b/Lib/packaging/tests/test_util.py
@@ -63,7 +63,9 @@
startupinfo=None, creationflags=0,
restore_signals=True, start_new_session=False,
pass_fds=()):
- self.cmd = args.split()[0]
+ if isinstance(args, str):
+ args = args.split()
+ self.cmd = args[0]
exes = self.test_class._exes
if self.cmd not in exes:
# we don't want to call the system, returning an empty
@@ -77,6 +79,9 @@
def communicate(self, input=None, timeout=None):
return self.stdout.read(), self.stderr.read()
+ def wait(self, timeout=None):
+ return 0
+
class UtilTestCase(support.EnvironRestorer,
support.TempdirManager,
@@ -424,10 +429,8 @@
@unittest.skipUnless(os.name in ('nt', 'posix'),
'runs only under posix or nt')
def test_spawn(self):
- # Do not patch subprocess on unix because
- # packaging.util._spawn_posix uses it
- if os.name in 'posix':
- subprocess.Popen = self.old_popen
+ # no patching of Popen here
+ subprocess.Popen = self.old_popen
tmpdir = self.mkdtemp()
# creating something executable
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list