fixed the move api in packaging.install, and closing the handle left by mkstemp() in its test module

This commit is contained in:
Tarek Ziade 2011-05-21 15:12:10 +02:00
parent 2db5674a95
commit 4bdd9f36a0
2 changed files with 12 additions and 10 deletions

View File

@ -47,10 +47,8 @@ def _move_files(files, destination):
destination = tempfile.mkdtemp() destination = tempfile.mkdtemp()
for old in files: for old in files:
# not using os.path.join() because basename() might not be filename = os.path.split(old)[-1]
# unique in destination new = os.path.join(destination, filename)
new = "%s%s" % (destination, old)
# try to make the paths. # try to make the paths.
try: try:
os.makedirs(os.path.dirname(new)) os.makedirs(os.path.dirname(new))

View File

@ -43,16 +43,18 @@ class ToInstallDist:
self.version = "fake" self.version = "fake"
if files: if files:
for f in range(0, 3): for f in range(0, 3):
self._real_files.append(mkstemp()) fp, fn = mkstemp()
os.close(fp)
self._real_files.append(fn)
def _unlink_installed_files(self): def _unlink_installed_files(self):
if self._files: if self._files:
for f in self._real_files: for fn in self._real_files:
os.unlink(f[1]) os.unlink(fn)
def list_installed_files(self, **args): def list_installed_files(self, **args):
if self._files: if self._files:
return [f[1] for f in self._real_files] return self._real_files
def get_install(self, **args): def get_install(self, **args):
return self.list_installed_files() return self.list_installed_files()
@ -231,8 +233,10 @@ class TestInstall(LoggingCatcher, TempdirManager, unittest.TestCase):
output = [o for o in install._move_files(files, newpath)] output = [o for o in install._move_files(files, newpath)]
# check that output return the list of old/new places # check that output return the list of old/new places
for f in files: for file_ in files:
self.assertIn((f, '%s%s' % (newpath, f)), output) name = os.path.split(file_)[-1]
newloc = os.path.join(newpath, name)
self.assertIn((file_, newloc), output)
# remove the files # remove the files
for f in [o[1] for o in output]: # o[1] is the new place for f in [o[1] for o in output]: # o[1] is the new place