[py-svn] py-trunk commit 7b44b348f3f3: adapt to new execnet.Group code (since execnet-1.0.0b4), strike superflous code
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Fri Nov 20 00:20:11 CET 2009
# HG changeset patch -- Bitbucket.org
# Project py-trunk
# URL http://bitbucket.org/hpk42/py-trunk/overview/
# User holger krekel <holger at merlinux.eu>
# Date 1258668809 -3600
# Node ID 7b44b348f3f3e31f8f8c5de17e6607523efaf9f6
# Parent b5d1a500603adb9df1e981027be5ebf419f5aa6d
adapt to new execnet.Group code (since execnet-1.0.0b4), strike superflous code
--- a/testing/plugin/test_pytest_terminal.py
+++ b/testing/plugin/test_pytest_terminal.py
@@ -130,16 +130,16 @@ class TestTerminal:
rep.pytest_gwmanage_newgateway(gw1, rinfo)
linecomp.assert_contains_lines([
- "X1*popen*xyz*2.5*"
+ "*X1*popen*xyz*2.5*"
])
rep.pytest_gwmanage_rsyncstart(source="hello", gateways=[gw1, gw2])
linecomp.assert_contains_lines([
- "rsyncstart: hello -> X1, X2"
+ "rsyncstart: hello -> [X1], [X2]"
])
rep.pytest_gwmanage_rsyncfinish(source="hello", gateways=[gw1, gw2])
linecomp.assert_contains_lines([
- "rsyncfinish: hello -> X1, X2"
+ "rsyncfinish: hello -> [X1], [X2]"
])
def test_writeline(self, testdir, linecomp):
--- a/py/impl/test/dist/gwmanage.py
+++ b/py/impl/test/dist/gwmanage.py
@@ -10,9 +10,9 @@ from execnet.gateway_base import RemoteE
class GatewayManager:
RemoteError = RemoteError
def __init__(self, specs, hook, defaultchdir="pyexecnetcache"):
- self.gateways = []
self.specs = []
self.hook = hook
+ self.group = execnet.Group()
for spec in specs:
if not isinstance(spec, execnet.XSpec):
spec = execnet.XSpec(spec)
@@ -21,48 +21,19 @@ class GatewayManager:
self.specs.append(spec)
def makegateways(self):
- assert not self.gateways
+ assert not list(self.group)
for spec in self.specs:
- gw = execnet.makegateway(spec)
- self.gateways.append(gw)
- gw.id = "[%s]" % len(self.gateways)
+ gw = self.group.makegateway(spec)
self.hook.pytest_gwmanage_newgateway(
gateway=gw, platinfo=gw._rinfo())
- def getgateways(self, remote=True, inplacelocal=True):
- if not self.gateways and self.specs:
- self.makegateways()
- l = []
- for gw in self.gateways:
- if gw.spec._samefilesystem():
- if inplacelocal:
- l.append(gw)
- else:
- if remote:
- l.append(gw)
- return execnet.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.
- """
- 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.
- @param inplacelocal=False: don't send code to inplacelocal hosts.
- """
- self.multi_exec("import os ; os.chdir(%r)" % basename,
- inplacelocal=inplacelocal).waitclose()
-
def rsync(self, source, notify=None, verbose=False, ignores=None):
""" perform rsync to all remote hosts.
"""
rsync = HostRSync(source, verbose=verbose, ignores=ignores)
seen = py.builtin.set()
gateways = []
- for gateway in self.gateways:
+ for gateway in self.group:
spec = gateway.spec
if not spec._samefilesystem():
if spec not in seen:
@@ -84,9 +55,7 @@ class GatewayManager:
)
def exit(self):
- while self.gateways:
- gw = self.gateways.pop()
- gw.exit()
+ self.group.terminate()
class HostRSync(execnet.RSync):
""" RSyncer that filters out common files
--- a/py/plugin/pytest_terminal.py
+++ b/py/plugin/pytest_terminal.py
@@ -150,7 +150,7 @@ class TerminalReporter:
else:
d['extra'] = ""
d['cwd'] = platinfo.cwd
- infoline = ("%(id)s %(spec)s -- platform %(platform)s, "
+ infoline = ("[%(id)s] %(spec)s -- platform %(platform)s, "
"Python %(version)s "
"cwd: %(cwd)s"
"%(extra)s" % d)
@@ -158,14 +158,14 @@ class TerminalReporter:
self.gateway2info[gateway] = infoline
def pytest_gwmanage_rsyncstart(self, source, gateways):
- targets = ", ".join([gw.id for gw in gateways])
+ targets = ", ".join(["[%s]" % gw.id for gw in gateways])
msg = "rsyncstart: %s -> %s" %(source, targets)
if not self.config.option.verbose:
msg += " # use --verbose to see rsync progress"
self.write_line(msg)
def pytest_gwmanage_rsyncfinish(self, source, gateways):
- targets = ", ".join([gw.id for gw in gateways])
+ targets = ", ".join(["[%s]" % gw.id for gw in gateways])
self.write_line("rsyncfinish: %s -> %s" %(source, targets))
def pytest_plugin_registered(self, plugin):
@@ -177,11 +177,11 @@ class TerminalReporter:
self.write_line(msg)
def pytest_testnodeready(self, node):
- self.write_line("%s txnode ready to receive tests" %(node.gateway.id,))
+ self.write_line("[%s] txnode ready to receive tests" %(node.gateway.id,))
def pytest_testnodedown(self, node, error):
if error:
- self.write_line("%s node down, error: %s" %(node.gateway.id, error))
+ self.write_line("[%s] node down, error: %s" %(node.gateway.id, error))
def pytest_trace(self, category, msg):
if self.config.option.debug or \
@@ -203,7 +203,7 @@ class TerminalReporter:
line = self._reportinfoline(item)
extra = ""
if node:
- extra = "-> " + str(node.gateway.id)
+ extra = "-> [%s]" % node.gateway.id
self.write_ensure_prefix(line, extra)
else:
if self.config.option.verbose:
@@ -238,7 +238,7 @@ class TerminalReporter:
else:
self.ensure_newline()
if hasattr(rep, 'node'):
- self._tw.write("%s " % rep.node.gateway.id)
+ self._tw.write("[%s] " % rep.node.gateway.id)
self._tw.write(word, **markup)
self._tw.write(" " + line)
self.currentfspath = -2
--- a/py/impl/test/dist/nodemanage.py
+++ b/py/impl/test/dist/nodemanage.py
@@ -57,7 +57,7 @@ class NodeManager(object):
def setup_nodes(self, putevent):
self.rsync_roots()
self.trace("setting up nodes")
- for gateway in self.gwmanager.gateways:
+ for gateway in self.gwmanager.group:
node = TXNode(gateway, self.config, putevent, slaveready=self._slaveready)
gateway.node = node # to keep node alive
self.trace("started node %r" % node)
@@ -67,7 +67,7 @@ class NodeManager(object):
#assert node.gateway.node == node
self.nodes.append(node)
self.trace("%s slave node ready %r" % (node.gateway.id, node))
- if len(self.nodes) == len(self.gwmanager.gateways):
+ if len(self.nodes) == len(list(self.gwmanager.group)):
self._nodesready.set()
def wait_nodesready(self, timeout=None):
--- a/testing/pytest/dist/test_gwmanage.py
+++ b/testing/pytest/dist/test_gwmanage.py
@@ -37,26 +37,26 @@ class TestGatewayManagerPopen:
hm.makegateways()
call = hookrecorder.popcall("pytest_gwmanage_newgateway")
assert call.gateway.spec == execnet.XSpec("popen")
- assert call.gateway.id == "[1]"
+ assert call.gateway.id == "1"
assert call.platinfo.executable == call.gateway._rinfo().executable
call = hookrecorder.popcall("pytest_gwmanage_newgateway")
- assert call.gateway.id == "[2]"
- assert len(hm.gateways) == 2
+ assert call.gateway.id == "2"
+ assert len(hm.group) == 2
hm.exit()
- assert not len(hm.gateways)
+ assert not len(hm.group)
def test_popens_rsync(self, hook, mysetup):
source = mysetup.source
hm = GatewayManager(["popen"] * 2, hook)
hm.makegateways()
- assert len(hm.gateways) == 2
- for gw in hm.gateways:
+ assert len(hm.group) == 2
+ for gw in hm.group:
gw.remote_exec = None
l = []
hm.rsync(source, notify=lambda *args: l.append(args))
assert not l
hm.exit()
- assert not len(hm.gateways)
+ assert not len(hm.group)
def test_rsync_popen_with_path(self, hook, mysetup):
source, dest = mysetup.source, mysetup.dest
@@ -66,7 +66,7 @@ class TestGatewayManagerPopen:
l = []
hm.rsync(source, notify=lambda *args: l.append(args))
assert len(l) == 1
- assert l[0] == ("rsyncrootready", hm.gateways[0].spec, source)
+ assert l[0] == ("rsyncrootready", hm.group['1'].spec, source)
hm.exit()
dest = dest.join(source.basename)
assert dest.join("dir1").check()
@@ -82,49 +82,9 @@ class TestGatewayManagerPopen:
call = hookrecorder.popcall("pytest_gwmanage_rsyncstart")
assert call.source == source
assert len(call.gateways) == 1
- assert hm.gateways[0] == call.gateways[0]
+ assert hm.group["1"] == call.gateways[0]
call = hookrecorder.popcall("pytest_gwmanage_rsyncfinish")
- def test_multi_chdir_popen_with_path(self, hook, testdir):
- hm = GatewayManager(["popen//chdir=hello"] * 2, hook)
- testdir.tmpdir.chdir()
- hellopath = testdir.tmpdir.mkdir("hello").realpath()
- hm.makegateways()
- l = hm.multi_exec(
- "import os ; channel.send(os.getcwd())").receive_each()
- paths = [x[1] for x in l]
- assert l == [str(hellopath)] * 2
- py.test.raises(hm.RemoteError,
- 'hm.multi_chdir("world", inplacelocal=False)')
- worldpath = hellopath.mkdir("world")
- hm.multi_chdir("world", inplacelocal=False)
- l = hm.multi_exec(
- "import os ; channel.send(os.getcwd())").receive_each()
- assert len(l) == 2
- assert l[0] == l[1]
- curwd = os.getcwd()
- assert l[0].startswith(curwd)
- assert l[0].endswith("world")
-
- def test_multi_chdir_popen(self, testdir, hook):
- import os
- hm = GatewayManager(["popen"] * 2, hook)
- testdir.tmpdir.chdir()
- hellopath = testdir.tmpdir.mkdir("hello")
- hm.makegateways()
- hm.multi_chdir("hello", inplacelocal=False)
- l = hm.multi_exec("import os ; channel.send(os.getcwd())").receive_each()
- assert len(l) == 2
- curwd = os.path.realpath(os.getcwd())
- assert l == [curwd] * 2
-
- hm.multi_chdir("hello")
- l = hm.multi_exec("import os ; channel.send(os.getcwd())").receive_each()
- assert len(l) == 2
- assert l[0] == l[1]
- assert l[0].startswith(curwd)
- assert l[0].endswith("hello")
-
class pytest_funcarg__mysetup:
def __init__(self, request):
tmp = request.getfuncargvalue('tmpdir')
More information about the pytest-commit
mailing list