[Python-checkins] r72727 - in python/trunk/Lib/distutils: dir_util.py tests/test_dir_util.py

tarek.ziade python-checkins at python.org
Sun May 17 13:11:57 CEST 2009


Author: tarek.ziade
Date: Sun May 17 13:11:57 2009
New Revision: 72727

Log:
removed sys.platform == 'mac' usage in distutils.dir_util

Modified:
   python/trunk/Lib/distutils/dir_util.py
   python/trunk/Lib/distutils/tests/test_dir_util.py

Modified: python/trunk/Lib/distutils/dir_util.py
==============================================================================
--- python/trunk/Lib/distutils/dir_util.py	(original)
+++ python/trunk/Lib/distutils/dir_util.py	Sun May 17 13:11:57 2009
@@ -212,14 +212,11 @@
                     exc, "error removing %s: " % directory))
 
 
-def ensure_relative (path):
+def ensure_relative(path):
     """Take the full path 'path', and make it a relative path so
     it can be the second argument to os.path.join().
     """
     drive, path = os.path.splitdrive(path)
-    if sys.platform == 'mac':
-        return os.sep + path
-    else:
-        if path[0:1] == os.sep:
-            path = drive + path[1:]
-        return path
+    if path[0:1] == os.sep:
+        path = drive + path[1:]
+    return path

Modified: python/trunk/Lib/distutils/tests/test_dir_util.py
==============================================================================
--- python/trunk/Lib/distutils/tests/test_dir_util.py	(original)
+++ python/trunk/Lib/distutils/tests/test_dir_util.py	Sun May 17 13:11:57 2009
@@ -3,10 +3,8 @@
 import os
 import shutil
 
-from distutils.dir_util import mkpath
-from distutils.dir_util import remove_tree
-from distutils.dir_util import create_tree
-from distutils.dir_util import copy_tree
+from distutils.dir_util import (mkpath, remove_tree, create_tree, copy_tree,
+                                ensure_relative)
 
 from distutils import log
 from distutils.tests import support
@@ -85,6 +83,14 @@
         remove_tree(self.root_target, verbose=0)
         remove_tree(self.target2, verbose=0)
 
+    def test_ensure_relative(self):
+        if os.sep == '/':
+            self.assertEquals(ensure_relative('/home/foo'), 'home/foo')
+            self.assertEquals(ensure_relative('some/path'), 'some/path')
+        else:   # \\
+            self.assertEquals(ensure_relative('c:\\home\\foo'), 'home\\foo')
+            self.assertEquals(ensure_relative('home\\foo'), 'home\\foo')
+
 def test_suite():
     return unittest.makeSuite(DirUtilTestCase)
 


More information about the Python-checkins mailing list