[py-svn] r8296 - in py/dist/py/path: . extpy local svn test
hpk at codespeak.net
hpk at codespeak.net
Sat Jan 15 14:11:04 CET 2005
Author: hpk
Date: Sat Jan 15 14:11:04 2005
New Revision: 8296
Modified:
py/dist/py/path/common.py
py/dist/py/path/extpy/extpy.py
py/dist/py/path/local/local.py
py/dist/py/path/svn/svncommon.py
py/dist/py/path/svn/wccommand.py
py/dist/py/path/test/common.py
Log:
- unified relto() handling
(triggered by Armin's complaint on py-dev :-)
- came up with a new format for py.path.extpy paths:
/path/to/file.py/.some.module.path.inside
- fixed some tests to not check for exact
str(path) formatting.
Modified: py/dist/py/path/common.py
==============================================================================
--- py/dist/py/path/common.py (original)
+++ py/dist/py/path/common.py Sat Jan 15 14:11:04 2005
@@ -109,6 +109,19 @@
return self.get('basename')[0]
basename = property(basename, None, None, 'basename part of path')
+ def relto(self, relpath):
+ """ return a string which is the relative part of the path
+ to the given 'relpath'.
+ """
+ strrelpath = str(relpath)
+ if strrelpath and strrelpath[-1] != self.sep:
+ strrelpath += self.sep
+ strself = str(self)
+ print "%r relto %r" %(strself, strrelpath)
+ if strself.startswith(strrelpath):
+ return strself[len(strrelpath):]
+ return ""
+
def parts(self, reverse=False):
""" return a root-first list of all ancestor directories
plus the path itself.
Modified: py/dist/py/path/extpy/extpy.py
==============================================================================
--- py/dist/py/path/extpy/extpy.py (original)
+++ py/dist/py/path/extpy/extpy.py Sat Jan 15 14:11:04 2005
@@ -15,14 +15,16 @@
""" path object for addressing python objects. """
sep = '.'
def __new__(cls, root, modpath=''):
- if isinstance(root, str):
- root = py.path.local(root)
- #root = py.path.local(root)
- #raise TypeError("first root argument is not resolvable")
if not isinstance(modpath, str):
raise TypeError("second 'modpath' argument must be a dotted name.")
- #assert not isinstance(root, Extpy)
+ if isinstance(root, str):
+ root = py.path.local(root)
+
self = object.__new__(cls)
+ if isinstance(root, Extpy):
+ # we don't want it nested, do we?
+ assert not modpath
+ root = root.root
self.modpath = modpath
self.root = root
return self
@@ -34,7 +36,7 @@
return 'extpy(%r, %r)' % (self.root, self.modpath)
def __str__(self):
- return str(self.root.new(ext=self.modpath))
+ return "%s%s.%s" %(self.root, self.root.sep, self.modpath)
def join(self, *args):
for arg in args:
@@ -44,6 +46,11 @@
modpath = self.sep.join(modpath)
return self.__class__(self.root, modpath)
+ def relto(self, other):
+ if self.root != other.root:
+ return ''
+ return super(Extpy, self).relto(other)
+
def dirpath(self, *args):
modpath = self.modpath.split(self.sep) [:-1]
modpath = self.sep.join(modpath+list(args))
@@ -92,13 +99,6 @@
else:
return self.root.getpymodule()
- def relto(self, otherpath):
- if self.root == otherpath.root:
- if self.modpath.startswith(otherpath.modpath):
- s = self.modpath[len(otherpath.modpath):]
- return s.lstrip(self.sep)
- return ''
-
def listobj(self, fil=None, **kw):
l = []
for x in self.listdir(fil, **kw):
Modified: py/dist/py/path/local/local.py
==============================================================================
--- py/dist/py/path/local/local.py (original)
+++ py/dist/py/path/local/local.py Sat Jan 15 14:11:04 2005
@@ -197,15 +197,6 @@
""" return last modification time of the path. """
return self.stat().st_mtime
- def relto(self, relpath):
- """ return a string which is the relative part of the path
- to the given 'relpath' (which might be a string or a path object).
- """
- relpath = str(relpath)
- if self.strpath.startswith(relpath):
- return self.strpath[len(relpath)+(relpath[-1:] != self.sep):]
- return ""
-
def remove(self, rec=1):
""" remove a file or directory (or a directory tree if rec=1). """
if self.check(dir=1, link=0):
Modified: py/dist/py/path/svn/svncommon.py
==============================================================================
--- py/dist/py/path/svn/svncommon.py (original)
+++ py/dist/py/path/svn/svncommon.py Sat Jan 15 14:11:04 2005
@@ -166,17 +166,6 @@
""" Return the last modification time of the file. """
return self.info().mtime
- def relto(self, rel):
- """ Return a string which is the relative part of the Path to 'rel'.
-
- If the Path is not relative to the given base, return an empty string.
- """
- relpath = rel.strpath
- if self.strpath.startswith(relpath):
- return self.strpath[len(relpath)+1:]
- return ""
-
-
# shared help methods
def _make_path_tuple(self, nameinfo_seq):
Modified: py/dist/py/path/svn/wccommand.py
==============================================================================
--- py/dist/py/path/svn/wccommand.py (original)
+++ py/dist/py/path/svn/wccommand.py Sat Jan 15 14:11:04 2005
@@ -393,17 +393,6 @@
""" Return the last modification time of the file. """
return self.info().mtime
- def relto(self, rel):
- """ Return a string which is the relative part of the Path to 'rel'.
-
- If the Path is not relative to the given base, return an empty string.
- """
-
- relpath = rel.strpath
- if self.strpath.startswith(relpath):
- return self.strpath[len(relpath)+1:]
- return ""
-
def __hash__(self):
return hash((self.strpath, self.__class__))
Modified: py/dist/py/path/test/common.py
==============================================================================
--- py/dist/py/path/test/common.py (original)
+++ py/dist/py/path/test/common.py Sat Jan 15 14:11:04 2005
@@ -18,13 +18,19 @@
def test_join(self):
p = self.root.join('sampledir')
- assert str(p) == self.root.sep.join([str(self.root), 'sampledir'])
+ strp = str(p)
+ assert strp.endswith('sampledir')
+ assert strp.startswith(str(self.root))
def test_join_normalized(self):
newpath = self.root.join(self.root.sep+'sampledir')
- assert str(newpath) == self.root.sep.join([str(self.root), 'sampledir'])
+ strp = str(newpath)
+ assert strp.endswith('sampledir')
+ assert strp.startswith(str(self.root))
newpath = self.root.join((self.root.sep*2) + 'sampledir')
- assert str(newpath) == self.root.sep.join([str(self.root), 'sampledir'])
+ strp = str(newpath)
+ assert strp.endswith('sampledir')
+ assert strp.startswith(str(self.root))
def test_join_noargs(self):
newpath = self.root.join()
@@ -119,9 +125,10 @@
assert not self.root.check(relto=l)
def test_relto_not_relative(self):
- l1=self.root.join("sampledir")
- l2=self.root.join("samplefile")
+ l1=self.root.join("bcde")
+ l2=self.root.join("b")
assert not l1.relto(l2)
+ assert not l2.relto(l1)
def test_listdir(self):
l = self.root.listdir()
More information about the pytest-commit
mailing list