diff options
author | Tarek Ziade <tarek@ziade.org> | 2011-05-21 08:37:58 (GMT) |
---|---|---|
committer | Tarek Ziade <tarek@ziade.org> | 2011-05-21 08:37:58 (GMT) |
commit | 94449616daf968f7e031530c0c861079d31ff137 (patch) | |
tree | 7f89798c0d5c0750aa1322cb214563452e91c347 | |
parent | 9904b22b78624174f1e0d06b7e2aed019bfeb550 (diff) | |
download | cpython-94449616daf968f7e031530c0c861079d31ff137.zip cpython-94449616daf968f7e031530c0c861079d31ff137.tar.gz cpython-94449616daf968f7e031530c0c861079d31ff137.tar.bz2 |
fixed a few mocking/cleanup issues in packaging test_util for win32
-rw-r--r-- | Lib/packaging/tests/support.py | 22 | ||||
-rw-r--r-- | 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 index b410dba..0c85b5d 100644 --- a/Lib/packaging/tests/support.py +++ b/Lib/packaging/tests/support.py @@ -112,26 +112,28 @@ class TempdirManager: 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 index 53f6a56..29f5379 100644 --- a/Lib/packaging/tests/test_util.py +++ b/Lib/packaging/tests/test_util.py @@ -63,7 +63,9 @@ class FakePopen: 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 @@ class FakePopen: 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 @@ class UtilTestCase(support.EnvironRestorer, @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 |