[py-svn] r62994 - in py/trunk/py: execnet execnet/testing test/dsession test/dsession/testing test/plugin
hpk at codespeak.net
hpk at codespeak.net
Tue Mar 17 12:53:11 CET 2009
Author: hpk
Date: Tue Mar 17 12:53:09 2009
New Revision: 62994
Modified:
py/trunk/py/execnet/gwmanage.py
py/trunk/py/execnet/testing/test_gwmanage.py
py/trunk/py/test/dsession/hostmanage.py
py/trunk/py/test/dsession/testing/test_hostmanage.py
py/trunk/py/test/plugin/pytest_pytester.py
Log:
introducing internal MultiGateway class
Modified: py/trunk/py/execnet/gwmanage.py
==============================================================================
--- py/trunk/py/execnet/gwmanage.py (original)
+++ py/trunk/py/execnet/gwmanage.py Tue Mar 17 12:53:09 2009
@@ -94,31 +94,46 @@
for ch in self._channels:
ch.waitclose()
+class MultiGateway:
+ def __init__(self, gateways):
+ self.gateways = gateways
+ def remote_exec(self, source):
+ channels = []
+ for gw in self.gateways:
+ channels.append(gw.remote_exec(source))
+ return MultiChannel(channels)
+
class GatewayManager:
def __init__(self, specs):
- self.spec2gateway = {}
- for spec in specs:
- self.spec2gateway[GatewaySpec(spec)] = None
+ self.specs = [GatewaySpec(spec) for spec in specs]
+ self.gateways = []
def trace(self, msg):
py._com.pyplugins.notify("trace", "gatewaymanage", msg)
def makegateways(self):
- for spec, value in self.spec2gateway.items():
- assert value is None
+ assert not self.gateways
+ for spec in self.specs:
self.trace("makegateway %s" %(spec))
- self.spec2gateway[spec] = spec.makegateway()
+ self.gateways.append(spec.makegateway())
+
+ def getgateways(self, remote=True, inplacelocal=True):
+ l = []
+ for gw in self.gateways:
+ if gw.spec.inplacelocal():
+ if inplacelocal:
+ l.append(gw)
+ else:
+ if remote:
+ l.append(gw)
+ return MultiGateway(gateways=l)
def multi_exec(self, source, inplacelocal=True):
""" remote execute code on all gateways.
@param inplacelocal=False: don't send code to inplacelocal hosts.
"""
- source = py.code.Source(source)
- channels = []
- for spec, gw in self.spec2gateway.items():
- if inplacelocal or not spec.inplacelocal():
- channels.append(gw.remote_exec(source))
- return MultiChannel(channels)
+ multigw = self.getgateways(inplacelocal=inplacelocal)
+ return multigw.remote_exec(source)
def multi_chdir(self, basename, inplacelocal=True):
""" perform a remote chdir to the given path, may be relative.
@@ -132,7 +147,8 @@
"""
rsync = HostRSync(source, verbose=verbose, ignores=ignores)
added = False
- for spec, gateway in self.spec2gateway.items():
+ for gateway in self.gateways:
+ spec = gateway.spec
if not spec.inplacelocal():
self.trace("add_target_host %r" %(gateway,))
def finished():
@@ -148,8 +164,8 @@
self.trace("rsync: nothing to do.")
def exit(self):
- while self.spec2gateway:
- spec, gw = self.spec2gateway.popitem()
+ while self.gateways:
+ gw = self.gateways.pop()
self.trace("exiting gateway %s" % gw)
gw.exit()
Modified: py/trunk/py/execnet/testing/test_gwmanage.py
==============================================================================
--- py/trunk/py/execnet/testing/test_gwmanage.py (original)
+++ py/trunk/py/execnet/testing/test_gwmanage.py Tue Mar 17 12:53:09 2009
@@ -106,21 +106,21 @@
def test_hostmanager_popen_makegateway(self):
hm = GatewayManager(["popen"] * 2)
hm.makegateways()
- assert len(hm.spec2gateway) == 2
+ assert len(hm.gateways) == 2
hm.exit()
- assert not len(hm.spec2gateway)
+ assert not len(hm.gateways)
def test_hostmanager_popens_rsync(self, source):
hm = GatewayManager(["popen"] * 2)
hm.makegateways()
- assert len(hm.spec2gateway) == 2
- for gw in hm.spec2gateway.values():
+ assert len(hm.gateways) == 2
+ for gw in hm.gateways:
gw.remote_exec = None
l = []
hm.rsync(source, notify=lambda *args: l.append(args))
assert not l
hm.exit()
- assert not len(hm.spec2gateway)
+ assert not len(hm.gateways)
def test_hostmanager_rsync_popen_with_path(self, source, dest):
hm = GatewayManager(["popen:%s" %dest] * 1)
@@ -129,7 +129,7 @@
l = []
hm.rsync(source, notify=lambda *args: l.append(args))
assert len(l) == 1
- assert l[0] == ("rsyncrootready", hm.spec2gateway.keys()[0], source)
+ assert l[0] == ("rsyncrootready", hm.gateways[0].spec, source)
hm.exit()
dest = dest.join(source.basename)
assert dest.join("dir1").check()
Modified: py/trunk/py/test/dsession/hostmanage.py
==============================================================================
--- py/trunk/py/test/dsession/hostmanage.py (original)
+++ py/trunk/py/test/dsession/hostmanage.py Tue Mar 17 12:53:09 2009
@@ -99,7 +99,8 @@
self.trace_hoststatus()
- for host, gateway in self.gwmanager.spec2gateway.items():
+ for gateway in self.gwmanager.gateways:
+ host = gateway.spec
host.node = MasterNode(host,
gateway,
self.config,
Modified: py/trunk/py/test/dsession/testing/test_hostmanage.py
==============================================================================
--- py/trunk/py/test/dsession/testing/test_hostmanage.py (original)
+++ py/trunk/py/test/dsession/testing/test_hostmanage.py Tue Mar 17 12:53:09 2009
@@ -25,7 +25,7 @@
config = py.test.config._reparse(args)
assert config.topdir == source
hm = HostManager(config)
- assert hm.gwmanager.spec2gateway
+ assert hm.gwmanager.specs
return hm
def xxtest_hostmanager_custom_hosts(self, source, dest):
@@ -114,7 +114,7 @@
config = py.test.config._reparse([source])
hm = HostManager(config, hosts=hosts)
hm.rsync_roots()
- for gwspec in hm.gwmanager.spec2gateway:
+ for gwspec in hm.gwmanager.specs:
assert gwspec.inplacelocal()
assert not gwspec.joinpath
@@ -127,20 +127,12 @@
hm = HostManager(config, hosts=hosts)
evrec = EventRecorder(config.bus, debug=True)
hm.setup_hosts(putevent=[].append)
- for host in hm.gwmanager.spec2gateway:
+ for host in hm.gwmanager.specs:
l = evrec.getnamed("trace")
print evrec.events
assert l
hm.teardown_hosts()
- def test_hostmanage_simple_ssh_test(self, testdir):
- rp = testdir.mkdir('xyz123')
- rp.ensure("__init__.py")
- p = testdir.makepyfile("def test_123(): import xyz123")
- result = testdir.runpytest(p, '-d', "--hosts=popen", '--rsyncdirs=' + str(rp))
- assert result.ret == 0
- assert result.stdout.str().find("1 passed") != -1
-
@py.test.mark.xfail("implement double-rsync test")
def test_ssh_rsync_samehost_twice(self):
option = py.test.config.option
Modified: py/trunk/py/test/plugin/pytest_pytester.py
==============================================================================
--- py/trunk/py/test/plugin/pytest_pytester.py (original)
+++ py/trunk/py/test/plugin/pytest_pytester.py Tue Mar 17 12:53:09 2009
@@ -36,7 +36,7 @@
def __init__(self, pyfuncitem):
self.pyfuncitem = pyfuncitem
# XXX remove duplication with tmpdir plugin
- basetmp = py.test.ensuretemp("testdir")
+ basetmp = pyfuncitem._config.ensuretemp("testdir")
name = pyfuncitem.name
for i in range(100):
try:
More information about the pytest-commit
mailing list