[py-svn] r6971 - in py/dist/py/path: . test
hpk at codespeak.net
hpk at codespeak.net
Sun Oct 17 06:32:59 CEST 2004
Author: hpk
Date: Sun Oct 17 06:32:59 2004
New Revision: 6971
Modified:
py/dist/py/path/common.py
py/dist/py/path/test/common.py
Log:
improved 'parts()' method of path objects.
Modified: py/dist/py/path/common.py
==============================================================================
--- py/dist/py/path/common.py (original)
+++ py/dist/py/path/common.py Sun Oct 17 06:32:59 2004
@@ -21,10 +21,6 @@
self.kwargs = kwargs
def __call__(self, p):
return p.check(**self.kwargs)
-
-class invchecker(checker):
- def __call__(self, p):
- return not p.check(**self.kwargs)
class Checkers:
_depend_on_existence = 'exists',
@@ -115,7 +111,7 @@
return self.get('basename')
basename = property(basename, None, None, 'basename part of path')
- def parts(self):
+ def parts(self, reverse=False):
""" return a root-first list of all ancestor directories
plus the path itself.
"""
@@ -126,8 +122,9 @@
current = current.dirpath()
if last == current:
break
- l.append(current)
- l.reverse()
+ l.insert(0, current)
+ if reverse:
+ l.reverse()
return l
def common(self, other):
Modified: py/dist/py/path/test/common.py
==============================================================================
--- py/dist/py/path/test/common.py (original)
+++ py/dist/py/path/test/common.py Sun Oct 17 06:32:59 2004
@@ -35,6 +35,9 @@
par = newpath.parts()[-3:]
assert par == [self.root, self.root.join('sampledir'), newpath]
+ revpar = newpath.parts(reverse=True)[:3]
+ assert revpar == [newpath, self.root.join('sampledir'), self.root]
+
def test_common(self):
other = self.root.join('sampledir')
x = other.common(self.root)
More information about the pytest-commit
mailing list