[Python-checkins] cpython: fixed the move api in packaging.install, and closing the handle left by

tarek.ziade python-checkins at python.org
Sat May 21 15:12:16 CEST 2011


http://hg.python.org/cpython/rev/897372653bef
changeset:   70247:897372653bef
user:        Tarek Ziade <tarek at ziade.org>
date:        Sat May 21 15:12:10 2011 +0200
summary:
  fixed the move api in packaging.install, and closing the handle left by mkstemp() in its test module

files:
  Lib/packaging/install.py            |   6 ++----
  Lib/packaging/tests/test_install.py |  16 ++++++++++------
  2 files changed, 12 insertions(+), 10 deletions(-)


diff --git a/Lib/packaging/install.py b/Lib/packaging/install.py
--- a/Lib/packaging/install.py
+++ b/Lib/packaging/install.py
@@ -47,10 +47,8 @@
         destination = tempfile.mkdtemp()
 
     for old in files:
-        # not using os.path.join() because basename() might not be
-        # unique in destination
-        new = "%s%s" % (destination, old)
-
+        filename = os.path.split(old)[-1]
+        new = os.path.join(destination, filename)
         # try to make the paths.
         try:
             os.makedirs(os.path.dirname(new))
diff --git a/Lib/packaging/tests/test_install.py b/Lib/packaging/tests/test_install.py
--- a/Lib/packaging/tests/test_install.py
+++ b/Lib/packaging/tests/test_install.py
@@ -43,16 +43,18 @@
         self.version = "fake"
         if files:
             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):
         if self._files:
-            for f in self._real_files:
-                os.unlink(f[1])
+            for fn in self._real_files:
+                os.unlink(fn)
 
     def list_installed_files(self, **args):
         if self._files:
-            return [f[1] for f in self._real_files]
+            return self._real_files
 
     def get_install(self, **args):
         return self.list_installed_files()
@@ -231,8 +233,10 @@
         output = [o for o in install._move_files(files, newpath)]
 
         # check that output return the list of old/new places
-        for f in files:
-            self.assertIn((f, '%s%s' % (newpath, f)), output)
+        for file_ in files:
+            name = os.path.split(file_)[-1]
+            newloc = os.path.join(newpath, name)
+            self.assertIn((file_, newloc), output)
 
         # remove the files
         for f in [o[1] for o in output]:  # o[1] is the new place

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list