[py-svn] r38389 - in py/trunk/py/test/rsession: . testing
hpk at codespeak.net
hpk at codespeak.net
Sat Feb 10 15:45:42 CET 2007
Author: hpk
Date: Sat Feb 10 15:45:41 2007
New Revision: 38389
Modified:
py/trunk/py/test/rsession/hostmanage.py
py/trunk/py/test/rsession/testing/test_hostmanage.py
Log:
completing the picture: now if you don't have rsync_roots
specified, the config.topdir is transfered but it is
transferred to the "remotepath.join(topdir.basename)"
(not actual code) to avoid random such rsyncs to
destroy/affect remote filesystem state.
Modified: py/trunk/py/test/rsession/hostmanage.py
==============================================================================
--- py/trunk/py/test/rsession/hostmanage.py (original)
+++ py/trunk/py/test/rsession/hostmanage.py Sat Feb 10 15:45:41 2007
@@ -13,17 +13,23 @@
"""
_hostname2list = {}
- def __init__(self, spec):
+ def __init__(self, spec, addrel=""):
parts = spec.split(':', 1)
self.hostname = parts.pop(0)
self.relpath = parts and parts.pop(0) or ""
if self.hostname == "localhost" and not self.relpath:
self.inplacelocal = True
+ if addrel:
+ raise ValueError("inplace localhosts cannot have "
+ "additional path %r" % addrel)
else:
self.inplacelocal = False
if not self.relpath:
self.relpath = "pytestcache-%s" % self.hostname
+ if addrel:
+ self.relpath += "/" + addrel # XXX too os-dependent
assert not parts
+ assert self.inplacelocal or self.relpath
self.hostid = self._getuniqueid(self.hostname)
def _getuniqueid(self, hostname):
@@ -32,7 +38,7 @@
l.append(hostid)
return hostid
- def initgateway(self, python="python", topdir=None):
+ def initgateway(self, python="python"):
if self.hostname == "localhost":
self.gw = py.execnet.PopenGateway(python=python)
else:
@@ -44,14 +50,13 @@
)).waitclose()
self.gw_remotepath = None
else:
- relpath = self.relpath or topdir or ""
- assert relpath
+ assert self.relpath
channel = self.gw.remote_exec(py.code.Source(
gethomedir,
sethomedir, "sethomedir()",
getpath_relto_home, """
channel.send(getpath_relto_home(%r))
- """ % relpath,
+ """ % self.relpath,
))
self.gw_remotepath = channel.receive()
@@ -116,19 +121,21 @@
class HostManager(object):
def __init__(self, config, hosts=None):
self.config = config
- if hosts is None:
- hosts = self.config.getvalue("dist_hosts")
- hosts = [HostInfo(x) for x in hosts]
- self.hosts = hosts
roots = self.config.getvalue_pathlist("dist_rsync_roots")
+ addrel = ""
if roots is None:
roots = [self.config.topdir]
+ addrel = self.config.topdir.basename
self.roots = roots
+ if hosts is None:
+ hosts = self.config.getvalue("dist_hosts")
+ hosts = [HostInfo(x, addrel) for x in hosts]
+ self.hosts = hosts
def prepare_gateways(self, reporter):
python = self.config.getvalue("dist_remotepython")
for host in self.hosts:
- host.initgateway(python=python, topdir=self.config.topdir)
+ host.initgateway(python=python)
reporter(repevent.HostGatewayReady(host, self.roots))
host.gw.host = host
@@ -140,7 +147,7 @@
rsync = HostRSync(root, ignores=ignores,
verbose=self.config.option.verbose)
if root == self.config.topdir:
- destrelpath =""
+ destrelpath = ""
else:
destrelpath = root.basename
for host in self.hosts:
Modified: py/trunk/py/test/rsession/testing/test_hostmanage.py
==============================================================================
--- py/trunk/py/test/rsession/testing/test_hostmanage.py (original)
+++ py/trunk/py/test/rsession/testing/test_hostmanage.py Sat Feb 10 15:45:41 2007
@@ -27,7 +27,15 @@
x = HostInfo("localhost:")
assert x.hostname == "localhost"
assert not x.relpath
- assert x.inplacelocal
+
+ def test_addrel(self):
+ py.test.raises(ValueError, """
+ HostInfo("localhost:", addrel="whatever")
+ """)
+ host = HostInfo("localhost:/tmp", addrel="base")
+ assert host.relpath == "/tmp/base"
+ host = HostInfo("localhost:tmp", addrel="base2")
+ assert host.relpath == "tmp/base2"
def test_path(self):
x = HostInfo("localhost:/tmp")
@@ -161,6 +169,16 @@
assert not res2
class TestHostManager(DirSetup):
+ def gethostmanager(self, dist_hosts):
+ self.source.join("conftest.py").write(py.code.Source("""
+ dist_hosts = %r
+ """ % (dist_hosts,)))
+ config = py.test.config._reparse([self.source])
+ assert config.topdir == self.source
+ hm = HostManager(config)
+ assert hm.hosts
+ return hm
+
def test_hostmanager_custom_hosts(self):
config = py.test.config._reparse([self.source])
hm = HostManager(config, hosts=[1,2,3])
@@ -169,15 +187,15 @@
def test_hostmanager_init_rsync_topdir(self):
dir2 = self.source.ensure("dir1", "dir2", dir=1)
dir2.ensure("hello")
- config = py.test.config._reparse([self.source])
- assert config.topdir == self.source
- hm = HostManager(config,
- hosts=[HostInfo("localhost:" + str(self.dest))])
- events = []
- hm.init_rsync(reporter=events.append)
- assert self.dest.join("dir1").check()
- assert self.dest.join("dir1", "dir2").check()
- assert self.dest.join("dir1", "dir2", 'hello').check()
+ hm = self.gethostmanager(
+ dist_hosts = ["localhost:%s" % self.dest]
+ )
+ assert hm.config.topdir == self.source
+ hm.init_rsync([].append)
+ dest = self.dest.join(self.source.basename)
+ assert dest.join("dir1").check()
+ assert dest.join("dir1", "dir2").check()
+ assert dest.join("dir1", "dir2", 'hello').check()
def test_hostmanager_init_rsync_rsync_roots(self):
dir2 = self.source.ensure("dir1", "dir2", dir=1)
More information about the pytest-commit
mailing list