[py-svn] r8464 - in py/dist/py/path: . local local/testing svn svn/testing testing
hpk at codespeak.net
hpk at codespeak.net
Sat Jan 22 00:11:55 CET 2005
Author: hpk
Date: Sat Jan 22 00:11:55 2005
New Revision: 8464
Removed:
py/dist/py/path/local/api.py
Modified:
py/dist/py/path/common.py
py/dist/py/path/local/local.py
py/dist/py/path/local/posix.py
py/dist/py/path/local/testing/test_posix.py
py/dist/py/path/svn/svncommon.py
py/dist/py/path/svn/testing/svntestbase.py
py/dist/py/path/svn/urlcommand.py
py/dist/py/path/testing/fscommon.py
Log:
fixed long-standing svn-test-skips (therefore implemented
svnurl.ensure() ...)
some refactoring of the testing code
remove some unused code
Modified: py/dist/py/path/common.py
==============================================================================
--- py/dist/py/path/common.py (original)
+++ py/dist/py/path/common.py Sat Jan 22 00:11:55 2005
@@ -79,6 +79,9 @@
return False
return True
+class _dummyclass:
+ pass
+
class PathBase(object):
""" shared implementation for filesystem path objects."""
Checkers = Checkers
@@ -163,33 +166,30 @@
def __repr__(self):
return repr(str(self))
- def visit(self, fil=None, rec=None, ignore=None):
+ def visit(self, fil=None, rec=None, ignore=_dummyclass):
if isinstance(fil, str):
fil = fnmatch(fil)
- if isinstance(rec, str):
- rec = fnmatch(fil)
- if ignore:
+ if rec:
+ if isinstance(rec, str):
+ rec = fnmatch(fil)
+ elif not callable(rec):
+ rec = lambda x: True
+ reclist = [self]
+ while reclist:
+ current = reclist.pop(0)
try:
- dirlist = self.listdir()
+ dirlist = current.listdir()
except ignore:
return
- else:
- dirlist = self.listdir()
- checkdir = py.path.checker(dir=1)
- reclist = []
- for p in dirlist:
- if fil is None or fil(p):
- yield p
- if checkdir(p) and (rec is None or rec(p)):
- reclist.append(p)
-
- for p in reclist:
- for i in p.visit(fil, rec, ignore=ignore):
- yield i
+ for p in dirlist:
+ if fil is None or fil(p):
+ yield p
+ if p.check(dir=1) and (rec is None or rec(p)):
+ reclist.append(p)
def _callex(self, func, *args):
""" call a function and raise errno-exception if applicable. """
- #__tracebackhide__ = True
+ __tracebackhide__ = True
try:
return func(*args)
except py.error.Error:
@@ -197,7 +197,7 @@
except EnvironmentError, e:
if not hasattr(e, 'errno'):
raise
- #__tracebackhide__ = False
+ __tracebackhide__ = False
cls, value, tb = sys.exc_info()
errno = e.errno
try:
@@ -212,7 +212,7 @@
except KeyError:
raise cls, value, tb
value = cls("%s%r" % (func.__name__, args))
- #__tracebackhide__ = True
+ __tracebackhide__ = True
raise cls, value
class fnmatch:
@@ -408,3 +408,4 @@
# fall-back
__tracebackhide__ = True
return old_import_hook(name, glob, loc, fromlist)
+
Deleted: /py/dist/py/path/local/api.py
==============================================================================
--- /py/dist/py/path/local/api.py Sat Jan 22 00:11:55 2005
+++ (empty file)
@@ -1,77 +0,0 @@
-"""
-Tool functions regarding local filesystem paths
-"""
-from py import path
-
-def get_temproot():
- """ return the system's temporary directory (where tempfiles are usually created in)"""
- p = mkdtemp()
- try:
- return p.dirpath()
- finally:
- p.remove()
-
-def mkdtemp():
- """ return a Path object pointing to a fresh new temporary directory
- (which we created ourself).
- """
- import tempfile
- tries = 10
- for i in range(tries):
- dname = tempfile.mktemp()
- dpath = path.local(tempfile.mktemp())
- try:
- dpath.mkdir()
- except path.FileExists:
- continue
- return dpath
- raise py.error.EAGAIN("could not create tempdir, %d tries" % tries)
-
-def make_numbered_dir(rootdir=None, base = 'session-', keep=3):
- """ return unique directory with a number greater than the current
- maximum one. The number is assumed to start directly after base.
- if keep is true directories with a number less than (maxnum-keep)
- will be removed.
- """
- if rootdir is None:
- rootdir = get_temproot()
-
- def parse_num(path):
- """ parse the number out of a path (if it matches the base) """
- bn = path.basename
- if bn.startswith(base):
- try:
- return int(bn[len(base):])
- except TypeError:
- pass
-
- # compute the maximum number currently in use with the base
- maxnum = -1
- for path in rootdir.listdir():
- num = parse_num(path)
- if num is not None:
- maxnum = max(maxnum, num)
-
- # make the new directory
- udir = rootdir.mkdir(base + str(maxnum+1))
-
- # prune old directories
- if keep:
- for path in rootdir.listdir():
- num = parse_num(path)
- if num is not None and num <= (maxnum - keep):
- path.remove(rec=1)
- return udir
-
-def parentdirmatch(dirname, startmodule=None):
- if startmodule is None:
- fn = path.local()
- else:
- mod = path.py(startmodule)
- fn = mod.getfile()
- current = fn.dirpath()
- while current != fn:
- fn = current
- if current.basename == dirname:
- return current
- current = current.dirpath()
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 22 00:11:55 2005
@@ -411,11 +411,7 @@
""" return the system's temporary directory
(where tempfiles are usually created in)
"""
- p = cls.mkdtemp()
- try:
- return p.dirpath()
- finally:
- p.remove()
+ return py.path.local(py.std.tempfile.gettempdir())
get_temproot = classmethod(get_temproot)
def mkdtemp(cls):
@@ -475,21 +471,6 @@
return udir
make_numbered_dir = classmethod(make_numbered_dir)
- #def parentdirmatch(cls, dirname, startmodule=None):
- # """ ??? """
- # if startmodule is None:
- # fn = path.local()
- # else:
- # mod = path.py(startmodule)
- # fn = mod.getfile()
- # current = fn.dirpath()
- # while current != fn:
- # fn = current
- # if current.basename() == dirname:
- # return current
- # current = current.dirpath()
- #parentdirmatch = classmethod(parentdirmatch)
-
def copychunked(src, dest):
chunksize = 524288 # half a meg of bytes
fsrc = src.open('rb')
Modified: py/dist/py/path/local/posix.py
==============================================================================
--- py/dist/py/path/local/posix.py (original)
+++ py/dist/py/path/local/posix.py Sat Jan 22 00:11:55 2005
@@ -38,7 +38,7 @@
if not isinstance(mode, int):
raise TypeError("mode %r must be an integer" % (mode,))
if rec:
- for x in self.visit():
+ for x in self.visit(rec=rec):
self._callex(os.chmod, str(x), mode)
self._callex(os.chmod, str(self), mode)
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 Sat Jan 22 00:11:55 2005
@@ -1,111 +1,85 @@
import py
-import sys
-from py.__impl__.path.testing.fscommon import setuptestfs
-checker = py.path.checker
-local = py.path.local
class TestPOSIXLocalPath:
#root = local(TestLocalPath.root)
- disabled = sys.platform == 'win32'
+ disabled = py.std.sys.platform == 'win32'
def setup_class(cls):
cls.root = py.test.config.tmpdir / 'TestPosixLocalPath'
- cls.root.ensure(dir=1)
- setuptestfs(cls.root)
+
+ def setup_method(self, method):
+ name = method.im_func.func_name
+ self.tmpdir = self.root.ensure(name, dir=1)
def test_hardlink(self):
- tmpdir = local(local.mkdtemp())
- try:
- linkpath = tmpdir.join('test')
- filepath = tmpdir.join('file')
- filepath.write("Hello")
- linkpath.mklinkto(filepath)
- assert filepath.read() == linkpath.read()
- finally:
- tmpdir.remove(rec=1)
+ tmpdir = self.tmpdir
+ linkpath = tmpdir.join('test')
+ filepath = tmpdir.join('file')
+ filepath.write("Hello")
+ nlink = filepath.stat().st_nlink
+ linkpath.mklinkto(filepath)
+ assert filepath.stat().st_nlink == nlink + 1
def test_symlink_are_identical(self):
- tmpdir = local(local.mkdtemp())
- try:
- filepath = tmpdir.join('file')
- filepath.write("Hello")
- linkpath = tmpdir.join('test')
- linkpath.mksymlinkto(filepath)
- assert filepath.read() == linkpath.read()
- finally:
- tmpdir.remove(rec=1)
+ tmpdir = self.tmpdir
+ filepath = tmpdir.join('file')
+ filepath.write("Hello")
+ linkpath = tmpdir.join('test')
+ linkpath.mksymlinkto(filepath)
+ assert linkpath.readlink() == str(filepath)
def test_symlink_isfile(self):
- tmpdir = local(local.mkdtemp())
- try:
- linkpath = tmpdir.join('test')
- filepath = tmpdir.join('file')
- filepath.write("")
- linkpath.mksymlinkto(filepath)
- assert linkpath.check(file=1)
- assert not linkpath.check(link=0, file=1)
- finally:
- tmpdir.remove(rec=1)
+ tmpdir = self.tmpdir
+ linkpath = tmpdir.join('test')
+ filepath = tmpdir.join('file')
+ filepath.write("")
+ linkpath.mksymlinkto(filepath)
+ assert linkpath.check(file=1)
+ assert not linkpath.check(link=0, file=1)
def test_symlink_relative(self):
- tmpdir = local(local.mkdtemp())
- try:
- linkpath = tmpdir.join('test')
- filepath = tmpdir.join('file')
- filepath.write("Hello")
- linkpath.mksymlinkto(filepath, absolute=False)
- assert linkpath.readlink() == "file"
- assert filepath.read() == linkpath.read()
- finally:
- tmpdir.remove(rec=1)
+ tmpdir = self.tmpdir
+ linkpath = tmpdir.join('test')
+ filepath = tmpdir.join('file')
+ filepath.write("Hello")
+ linkpath.mksymlinkto(filepath, absolute=False)
+ assert linkpath.readlink() == "file"
+ assert filepath.read() == linkpath.read()
def test_relto_with_root(self):
y = self.root.join('x').relto(py.path.local('/'))
assert y[0] == str(self.root)[1]
def test_visit_recursive_symlink(self):
- tmpdir = local.mkdtemp()
- try:
- linkpath = tmpdir.join('test')
- linkpath.mksymlinkto(tmpdir)
- visitor = tmpdir.visit(None, checker(link=0))
- assert list(visitor) == [linkpath]
- #check.equal(list(tmpdir.visit()), [linkpath])
- finally:
- tmpdir.remove(rec=1)
+ tmpdir = self.tmpdir
+ linkpath = tmpdir.join('test')
+ linkpath.mksymlinkto(tmpdir)
+ visitor = tmpdir.visit(None, py.path.checker(link=0))
+ assert list(visitor) == [linkpath]
def test_symlink_isdir(self):
- tmpdir = local.mkdtemp()
- try:
- linkpath = tmpdir.join('test')
- linkpath.mksymlinkto(tmpdir)
- assert linkpath.check(dir=1)
- assert not linkpath.check(link=0, dir=1)
- finally:
- tmpdir.remove(rec=1)
+ tmpdir = self.tmpdir
+ linkpath = tmpdir.join('test')
+ linkpath.mksymlinkto(tmpdir)
+ assert linkpath.check(dir=1)
+ assert not linkpath.check(link=0, dir=1)
def test_symlink_remove(self):
- tmpdir = local.mkdtemp().realpath()
- try:
- linkpath = tmpdir.join('test')
- linkpath.mksymlinkto(linkpath) # point to itself
- assert linkpath.check(link=1)
- linkpath.remove()
- assert not linkpath.check()
- finally:
- tmpdir.remove(rec=1)
+ tmpdir = self.tmpdir.realpath()
+ linkpath = tmpdir.join('test')
+ linkpath.mksymlinkto(linkpath) # point to itself
+ assert linkpath.check(link=1)
+ linkpath.remove()
+ assert not linkpath.check()
def test_realpath_file(self):
- tmpdir = local.mkdtemp()
- try:
- linkpath = tmpdir.join('test')
- filepath = tmpdir.join('file')
- filepath.write("")
- linkpath.mksymlinkto(filepath)
- realpath = linkpath.realpath()
- assert realpath.basename == 'file'
- finally:
- tmpdir.remove(rec=1)
+ tmpdir = self.tmpdir
+ linkpath = tmpdir.join('test')
+ filepath = tmpdir.join('file')
+ filepath.write("")
+ linkpath.mksymlinkto(filepath)
+ realpath = linkpath.realpath()
+ assert realpath.basename == 'file'
def test_owner(self):
from pwd import getpwuid
@@ -126,21 +100,20 @@
path.read(1)
assert path.atime() != atime
- def testcommondir(self):
+ def test_commondir(self):
# XXX This is here in local until we find a way to implement this
# using the subversion command line api.
p1 = self.root.join('something')
p2 = self.root.join('otherthing')
- assert p1.commondir(p2) == self.root
- assert p2.commondir(p1) == self.root
+ assert p1.common(p2) == self.root
+ assert p2.common(p1) == self.root
- def testcommondir_nocommon(self):
+ def test_commondir_nocommon(self):
# XXX This is here in local until we find a way to implement this
# using the subversion command line api.
p1 = self.root.join('something')
- p2 = local(os.sep+'blabla')
- assert p1.commondir(p2) is None
-
+ p2 = py.path.local(self.root.sep+'blabla')
+ assert p1.common(p2) == '/'
def test_chmod_simple_int(self):
print "self.root is", self.root
@@ -155,11 +128,11 @@
def test_chmod_rec_int(self):
# XXX fragile test
print "self.root is", self.root
- recfilter = checker(dotfile=0)
+ recfilter = py.path.checker(dotfile=0, link=0)
oldmodes = {}
for x in self.root.visit(rec=recfilter):
oldmodes[x] = x.mode()
- self.root.chmod(0772, rec=1)
+ self.root.chmod(0772, rec=recfilter)
try:
for x in self.root.visit(rec=recfilter):
assert x.mode() & 0777 == 0772
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 22 00:11:55 2005
@@ -135,8 +135,8 @@
if len(nameinfo_seq) == 1:
name, info = nameinfo_seq[0]
if name == self.basename and info.kind == 'file':
- if not self.check(dir=1):
- raise py.error.ENOTDIR(self)
+ #if not self.check(dir=1):
+ raise py.error.ENOTDIR(self)
paths = self._make_path_tuple(nameinfo_seq)
if fil or sort:
Modified: py/dist/py/path/svn/testing/svntestbase.py
==============================================================================
--- py/dist/py/path/svn/testing/svntestbase.py (original)
+++ py/dist/py/path/svn/testing/svntestbase.py Sat Jan 22 00:11:55 2005
@@ -31,14 +31,38 @@
wc = py.path.svnwc(wcdir)
return ("file://%s" % repo, wc)
+def save_repowc():
+ repo, wc = getrepowc()
+ repo = py.path.local(repo[len("file://"):])
+ assert repo.check()
+ savedrepo = repo.dirpath('repo_save')
+ savedwc = wc.dirpath('wc_save')
+ repo.copy(savedrepo)
+ wc.localpath.copy(savedwc.localpath)
+ return savedrepo, savedwc
+
+def restore_repowc((savedrepo, savedwc)):
+ repo, wc = getrepowc()
+ repo = py.path.local(repo[len("file://"):])
+ assert repo.check()
+ repo.remove()
+ wc.localpath.remove()
+ savedrepo.move(repo)
+ savedwc.localpath.move(wc.localpath)
+
class CommonSvnTests(CommonFSTests):
def setup_method(self, meth):
bn = meth.func_name
for x in 'test_remove', 'test_move':
if bn.startswith(x):
- py.test.skip(
- "tests for modifying svn needs better test state management")
+ self._savedrepowc = save_repowc()
+
+ def teardown_method(self, meth):
+ x = getattr(self, '_savedrepowc', None)
+ if x is not None:
+ restore_repowc(x)
+ del self._savedrepowc
def test_propget(self):
url = self.root.join("samplefile")
Modified: py/dist/py/path/svn/urlcommand.py
==============================================================================
--- py/dist/py/path/svn/urlcommand.py (original)
+++ py/dist/py/path/svn/urlcommand.py Sat Jan 22 00:11:55 2005
@@ -79,6 +79,17 @@
return popen(svncommon.fixlocale() +
'svn cat -r %s "%s"' % (self.rev, self.strpath))
+ def dirpath(self, *args, **kwargs):
+ """ return the directory Path of the current Path joined
+ with any given path arguments.
+ """
+ l = self.strpath.split(self.sep)
+ if len(l) < 4:
+ raise py.error.EINVAL(self, "base is not valid")
+ elif len(l) == 4:
+ return self.join(*args, **kwargs)
+ else:
+ return self.new(basename='').join(*args, **kwargs)
# modifying methods (cache must be invalidated)
def mkdir(self, *args, **kwargs):
@@ -90,16 +101,57 @@
def copy(self, target, msg='copied by py lib invocation'):
if getattr(target, 'rev', None) is not None:
- raise py.error.EINVAL(target, "can't copy to revisioned resource")
+ raise py.error.EINVAL(target, "revisions are immutable")
process.cmdexec("svn copy -m %r %s %s" %(msg, str(self), str(target)))
self._lsnorevcache.delentry(target.dirpath().strpath)
+ def rename(self, target, msg="renamed by py lib invocation"):
+ if getattr(self, 'rev', None) is not None:
+ raise py.error.EINVAL(self, "revisions are immutable")
+ py.process.cmdexec("svn move -m %r --force %s %s" %(
+ msg, str(self), str(target)))
+ self._lsnorevcache.delentry(self.dirpath().strpath)
+ self._lsnorevcache.delentry(self.strpath)
+
def remove(self, rec=1, msg='removed by py lib invocation'):
if self.rev is not None:
- raise py.error.EINVAL(self, "can't remove revisioned resource")
+ raise py.error.EINVAL(self, "revisions are immutable")
process.cmdexec("svn rm -m %r %s" %(msg, str(self)))
self._lsnorevcache.delentry(self.dirpath().strpath)
+ def ensure(self, *args, **kwargs):
+ """ ensure that an args-joined path exists (by default as
+ a file). If you specify a keyword argument 'dir=True'
+ then the path is forced to be a directory path.
+ """
+ if getattr(self, 'rev', None) is not None:
+ raise py.error.EINVAL(self, "revisions are immutable")
+ target = self.join(*args)
+ dir = kwargs.get('dir', 0)
+ for x in target.parts(reverse=True):
+ if x.check():
+ break
+ else:
+ raise py.error.ENOENT(target, "has not any valid base!")
+ if x == target:
+ if not x.check(dir=dir):
+ raise dir and py.error.ENOTDIR(x) or py.error.EISDIR(x)
+ return x
+ tocreate = target.relto(x)
+ basename = tocreate.split(self.sep, 1)[0]
+ tempdir = py.path.local.mkdtemp()
+ try:
+ tempdir.ensure(tocreate, dir=dir)
+ cmd = 'svn import -m %r %r %r' % (
+ "ensure %s" % tocreate,
+ str(tempdir.join(basename)),
+ x.join(basename)._encodedurl())
+ process.cmdexec(cmd)
+ self._lsnorevcache.delentry(x.strpath) # !!!
+ finally:
+ tempdir.remove()
+ return target
+
# end of modifying methods
def _propget(self, name):
res = self._svn('propget', name)
Modified: py/dist/py/path/testing/fscommon.py
==============================================================================
--- py/dist/py/path/testing/fscommon.py (original)
+++ py/dist/py/path/testing/fscommon.py Sat Jan 22 00:11:55 2005
@@ -197,20 +197,19 @@
assert tmpdir.join('mktest2') == new
def test_move_file(self):
- p = self.root.ensure('tomove')
- newp = p.new(basename='moved')
+ p = self.root.join('samplefile')
+ newp = p.dirpath('samplefile_moved')
p.move(newp)
assert newp.check(file=1)
assert not p.check()
def test_move_directory(self):
- source = self.root.join('to')
- source.ensure('moved', 'somefile').write("42")
- dest = source.new(basename='moveddir')
+ source = self.root.join('sampledir')
+ dest = self.root.join('moveddir')
source.move(dest)
assert dest.check(dir=1)
- assert dest.join('moved', 'somefile').read() == '42'
- assert not source.check()
+ assert dest.join('otherfile').check(file=1)
+ assert not source.join('sampledir').check()
def test_getpymodule(self):
obj = self.root.join('execfile').getpymodule()
More information about the pytest-commit
mailing list