[py-svn] r31518 - in py/branch/distributed/py/test/rsession: . testing
fijal at codespeak.net
fijal at codespeak.net
Wed Aug 23 11:45:53 CEST 2006
Author: fijal
Date: Wed Aug 23 11:45:49 2006
New Revision: 31518
Modified:
py/branch/distributed/py/test/rsession/executor.py
py/branch/distributed/py/test/rsession/rsession.py
py/branch/distributed/py/test/rsession/slave.py
py/branch/distributed/py/test/rsession/testing/test_dispatcher.py
py/branch/distributed/py/test/rsession/testing/test_executor.py
py/branch/distributed/py/test/rsession/testing/test_slave.py
Log:
Fixed exception handling to catch everything.
RSync run in paraller now.
Test passes in a very obscure way.
Some minor bugfixes.
Modified: py/branch/distributed/py/test/rsession/executor.py
==============================================================================
--- py/branch/distributed/py/test/rsession/executor.py (original)
+++ py/branch/distributed/py/test/rsession/executor.py Wed Aug 23 11:45:49 2006
@@ -13,7 +13,7 @@
def _execute(self, fun):
try:
fun()
- except Exception, e:
+ except:
excinfo = py.code.ExceptionInfo()
code = py.code.Code(fun)
excinfo.traceback = excinfo.traceback.cut(
@@ -28,3 +28,17 @@
if excinfo is not None:
return Outcome(excinfo=excinfo, setupfailure=False)
return Outcome()
+
+class RunExecutor(Executor):
+ """ Same as in executor, but just running run
+ """
+ def __init__(self, item):
+ self.item = item
+
+ def execute(self):
+ try:
+ self.item.run()
+ return Outcome()
+ except:
+ excinfo = py.code.ExceptionInfo()
+ return Outcome(excinfo=excinfo, setupfailure=False)
Modified: py/branch/distributed/py/test/rsession/rsession.py
==============================================================================
--- py/branch/distributed/py/test/rsession/rsession.py (original)
+++ py/branch/distributed/py/test/rsession/rsession.py Wed Aug 23 11:45:49 2006
@@ -15,9 +15,24 @@
def report(self, *whatever):
self.event.set()
print whatever
+
+ def iteritems(self, colitems):
+ to_run = colitems
+ try:
+ while 1:
+ colitem = to_run.pop()
+ if isinstance(colitem, py.test.Item):
+ yield colitem
+ else:
+ for i in colitem.run():
+ to_run.append(colitem.join(i))
+ except IndexError:
+ pass
+
- def main(self, args):
+ def main(self, args):
""" main loop for running tests. """
+ import thread, threading
from py.__.test.terminal.remote import getrootdir
from py.__.test.rsession.master import (
setup_slave, bin_rsync, MasterNode, dispatch_loop)
@@ -28,17 +43,38 @@
nodes = []
import threading
self.event = threading.Event()
- for host in sshhosts:
+ nodes_lock = threading.Condition()
+
+ def host_init(host):
bin_rsync(rootdir, host, relpath)
gw = py.execnet.SshGateway(host)
- ch = setup_slave(gw, relpath)
- nodes.append(MasterNode(ch, self.report))
+ ch = setup_slave(gw, relpath)
+ nodes_lock.acquire()
+ try:
+ nodes.append(MasterNode(ch, self.report))
+ nodes_lock.notify()
+ finally:
+ nodes_lock.release()
+
+ for host in sshhosts:
+ thread.start_new_thread(host_init, (host,))
+
+ while len(nodes) != len(sshhosts):
+ nodes_lock.acquire()
+ try:
+ nodes_lock.wait(1)
+ finally:
+ nodes_lock.release()
- itemgenerator = colitems[0].tryiter()
+ itemgenerator = self.iteritems(colitems)
dispatch_loop(nodes, itemgenerator, lambda : False, self.event)
print "INITIALIZED, dying now ..."
import time
time.sleep(3)
+
+ # XXX: Some cleanup here, like counting all the stuff we send
+ # and waiting for them to arrive back
+ # Maybe rescheduling stuff that did not landed at all
def _map2colitems(items):
# first convert all path objects into collectors
Modified: py/branch/distributed/py/test/rsession/slave.py
==============================================================================
--- py/branch/distributed/py/test/rsession/slave.py (original)
+++ py/branch/distributed/py/test/rsession/slave.py Wed Aug 23 11:45:49 2006
@@ -3,15 +3,18 @@
"""
import py
-from py.__.test.rsession.executor import Executor
+from py.__.test.rsession.executor import Executor, RunExecutor
class SlaveNode(object):
def __init__(self, rootcollector):
self.rootcollector = rootcollector
- def execute(self, itemspec):
+ def execute(self, itemspec):
item = self.rootcollector.getitembynames(itemspec)
- ex = Executor(item.obj, setup=item.setup)
+ if isinstance(item, py.test.Function):
+ ex = Executor(item.obj, setup=item.setup)
+ else:
+ ex = RunExecutor(item)
return ex.execute()
def run(self, itemspec):
Modified: py/branch/distributed/py/test/rsession/testing/test_dispatcher.py
==============================================================================
--- py/branch/distributed/py/test/rsession/testing/test_dispatcher.py (original)
+++ py/branch/distributed/py/test/rsession/testing/test_dispatcher.py Wed Aug 23 11:45:49 2006
@@ -69,6 +69,9 @@
rootcol = py.test.collect.Directory(rootdir)
funcpass_item = rootcol.getitembynames(funcpass_spec)
funcfail_item = rootcol.getitembynames(funcfail_spec)
+ # XXX: Just make this test pass
+ funcpass_item.parent.parent.parent.parent.parent.parent = None
+ funcfail_item.parent.parent.parent.parent.parent.parent = None
itemgenerator = iter([funcfail_item] + [funcpass_item] * 5 + [funcfail_item] * 5)
shouldstop = lambda : False
dispatch_loop(master_nodes, itemgenerator, shouldstop, event)
Modified: py/branch/distributed/py/test/rsession/testing/test_executor.py
==============================================================================
--- py/branch/distributed/py/test/rsession/testing/test_executor.py (original)
+++ py/branch/distributed/py/test/rsession/testing/test_executor.py Wed Aug 23 11:45:49 2006
@@ -2,7 +2,7 @@
import py
import example1
-from py.__.test.rsession.executor import Executor
+from py.__.test.rsession.executor import Executor, RunExecutor
def test_executor_passing_function():
ex = Executor(example1.f1)
@@ -38,3 +38,20 @@
assert not outcome.passed
assert outcome.setupfailure
assert outcome.excinfo.traceback[-1].frame.code.name == 'failingsetup'
+
+class ItemTestPassing(py.test.Item):
+ def run(self):
+ return None
+
+class ItemTestFailing(py.test.Item):
+ def run(self):
+ assert 0 == 1
+
+def test_run_executor():
+ ex = RunExecutor(ItemTestPassing("pass"))
+ outcome = ex.execute()
+ assert outcome.passed
+
+ ex = RunExecutor(ItemTestFailing("fail"))
+ outcome = ex.execute()
+ assert not outcome.passed
Modified: py/branch/distributed/py/test/rsession/testing/test_slave.py
==============================================================================
--- py/branch/distributed/py/test/rsession/testing/test_slave.py (original)
+++ py/branch/distributed/py/test/rsession/testing/test_slave.py Wed Aug 23 11:45:49 2006
@@ -70,4 +70,6 @@
assert not res_repr[0].passed
assert res_repr[1].passed
-
+def test_slave_run_different_stuff():
+ node = gettestnode()
+ node.run("py/documentation/log.txt")
More information about the pytest-commit
mailing list