[py-svn] r14834 - in py/dist/py/path/local: . testing

hpk at codespeak.net hpk at codespeak.net
Wed Jul 20 22:01:10 CEST 2005


Author: hpk
Date: Wed Jul 20 22:01:08 2005
New Revision: 14834

Modified:
   py/dist/py/path/local/local.py
   py/dist/py/path/local/testing/test_posix.py
Log:
fix a probably long standing bug of the py.path.local().join method 
which would produce non-normalized paths. 



Modified: py/dist/py/path/local/local.py
==============================================================================
--- py/dist/py/path/local/local.py	(original)
+++ py/dist/py/path/local/local.py	Wed Jul 20 22:01:08 2005
@@ -154,15 +154,22 @@
         """
         if not args:
             return self
-        strargs = [self.strpath]
-        strargs.extend(map(str, args))
+        strpath = self.strpath
+        sep = self.sep 
+        strargs = [str(x) for x in args] 
         if kwargs.get('abs', 0):
-            for i in range(len(strargs)-1, 0, -1):
+            for i in range(len(strargs)-1, -1, -1):
                 if os.path.isabs(strargs[i]):
-                    strargs = strargs[i:]
+                    strpath = strargs[i] 
+                    strargs = strargs[i+1:]
                     break
+        for arg in strargs: 
+            arg = arg.strip(sep) 
+            if not strpath.endswith(sep): 
+                strpath += sep 
+            strpath += arg 
         obj = self.new()
-        obj.strpath = os.path.normpath(self.sep.join(strargs))
+        obj.strpath = strpath 
         return obj
 
     def __eq__(self, other):

Modified: py/dist/py/path/local/testing/test_posix.py
==============================================================================
--- py/dist/py/path/local/testing/test_posix.py	(original)
+++ py/dist/py/path/local/testing/test_posix.py	Wed Jul 20 22:01:08 2005
@@ -115,6 +115,11 @@
         p2 = py.path.local(self.root.sep+'blabla')
         assert p1.common(p2) == '/' 
 
+    def test_join_to_root(self): 
+        root = self.root.parts()[0]
+        assert len(str(root)) == 1
+        assert str(root.join('a')) == '/a'
+
     def test_chmod_simple_int(self):
         print "self.root is", self.root
         mode = self.root.mode()



More information about the pytest-commit mailing list