2007-01-24 22:24:01 +08:00
|
|
|
""" Remote executor
|
|
|
|
"""
|
|
|
|
|
|
|
|
import py, os
|
|
|
|
|
|
|
|
from py.__.test.rsession.outcome import Outcome, ReprOutcome
|
|
|
|
from py.__.test.rsession.box import Box
|
|
|
|
from py.__.test.rsession import report
|
|
|
|
|
|
|
|
class RunExecutor(object):
|
|
|
|
""" Same as in executor, but just running run
|
|
|
|
"""
|
|
|
|
wraps = False
|
|
|
|
|
2007-01-25 00:46:46 +08:00
|
|
|
def __init__(self, item, usepdb=False, reporter=None, config=None):
|
2007-01-24 22:24:01 +08:00
|
|
|
self.item = item
|
|
|
|
self.usepdb = usepdb
|
|
|
|
self.reporter = reporter
|
2007-01-25 00:46:46 +08:00
|
|
|
self.config = config
|
|
|
|
assert self.config
|
2007-01-31 00:59:32 +08:00
|
|
|
|
|
|
|
def run(self):
|
|
|
|
self.item.run()
|
2007-01-24 22:24:01 +08:00
|
|
|
|
|
|
|
def execute(self):
|
|
|
|
try:
|
2007-01-31 00:59:32 +08:00
|
|
|
self.run()
|
2007-01-24 22:24:01 +08:00
|
|
|
outcome = Outcome()
|
|
|
|
except py.test.Item.Skipped, e:
|
|
|
|
outcome = Outcome(skipped=str(e))
|
|
|
|
except (KeyboardInterrupt, SystemExit):
|
|
|
|
raise
|
|
|
|
except:
|
|
|
|
excinfo = py.code.ExceptionInfo()
|
|
|
|
if isinstance(self.item, py.test.Function):
|
|
|
|
fun = self.item.obj # hope this is stable
|
|
|
|
code = py.code.Code(fun)
|
|
|
|
excinfo.traceback = excinfo.traceback.cut(
|
|
|
|
path=code.path, firstlineno=code.firstlineno)
|
|
|
|
outcome = Outcome(excinfo=excinfo, setupfailure=False)
|
|
|
|
if self.usepdb:
|
|
|
|
if self.reporter is not None:
|
|
|
|
self.reporter(report.ImmediateFailure(self.item,
|
2007-01-25 00:46:46 +08:00
|
|
|
ReprOutcome(outcome.make_repr
|
|
|
|
(self.config.option.tbstyle))))
|
2007-01-24 22:24:01 +08:00
|
|
|
import pdb
|
|
|
|
pdb.post_mortem(excinfo._excinfo[2])
|
|
|
|
# XXX hmm, we probably will not like to continue from that
|
|
|
|
# point
|
|
|
|
raise SystemExit()
|
|
|
|
outcome.stdout = ""
|
|
|
|
outcome.stderr = ""
|
|
|
|
return outcome
|
|
|
|
|
2007-01-31 00:59:32 +08:00
|
|
|
class ApigenExecutor(RunExecutor):
|
|
|
|
""" Same as RunExecutor, but takes tracer to trace calls as
|
|
|
|
an argument to execute
|
|
|
|
"""
|
|
|
|
def execute(self, tracer):
|
|
|
|
self.tracer = tracer
|
|
|
|
return super(ApigenExecutor, self).execute()
|
|
|
|
|
2007-02-01 19:50:29 +08:00
|
|
|
def wrap_underlaying(self, target, *args):
|
|
|
|
try:
|
|
|
|
self.tracer.start_tracing()
|
|
|
|
return target(*args)
|
|
|
|
finally:
|
|
|
|
self.tracer.end_tracing()
|
2007-01-31 00:59:32 +08:00
|
|
|
|
|
|
|
def run(self):
|
|
|
|
""" We want to trace *only* function objects here. Unsure
|
|
|
|
what to do with custom collectors at all
|
|
|
|
"""
|
2007-02-01 19:50:29 +08:00
|
|
|
if hasattr(self.item, 'obj') and type(self.item) is py.test.Function:
|
|
|
|
self.item.execute = self.wrap_underlaying
|
2007-01-31 00:59:32 +08:00
|
|
|
self.item.run()
|
|
|
|
|
2007-01-24 22:24:01 +08:00
|
|
|
class BoxExecutor(RunExecutor):
|
2007-01-31 00:59:32 +08:00
|
|
|
""" Same as RunExecutor, but boxes test instead
|
2007-01-24 22:24:01 +08:00
|
|
|
"""
|
|
|
|
wraps = True
|
|
|
|
|
|
|
|
def execute(self):
|
|
|
|
def fun():
|
|
|
|
outcome = RunExecutor.execute(self)
|
2007-01-25 00:46:46 +08:00
|
|
|
return outcome.make_repr(self.config.option.tbstyle)
|
|
|
|
b = Box(fun, config=self.config)
|
2007-01-24 22:24:01 +08:00
|
|
|
pid = b.run()
|
|
|
|
assert pid
|
|
|
|
if b.retval is not None:
|
|
|
|
passed, setupfailure, excinfo, skipped, critical, _, _, _\
|
|
|
|
= b.retval
|
|
|
|
return (passed, setupfailure, excinfo, skipped, critical, 0,
|
|
|
|
b.stdoutrepr, b.stderrrepr)
|
|
|
|
else:
|
|
|
|
return (False, False, None, False, False, b.signal,
|
|
|
|
b.stdoutrepr, b.stderrrepr)
|
|
|
|
|
|
|
|
class AsyncExecutor(RunExecutor):
|
|
|
|
""" same as box executor, but instead it returns function to continue
|
|
|
|
computations (more async mode)
|
|
|
|
"""
|
|
|
|
wraps = True
|
|
|
|
|
|
|
|
def execute(self):
|
|
|
|
def fun():
|
|
|
|
outcome = RunExecutor.execute(self)
|
2007-01-25 00:46:46 +08:00
|
|
|
return outcome.make_repr(self.config.option.tbstyle)
|
2007-01-24 22:24:01 +08:00
|
|
|
|
2007-01-25 00:46:46 +08:00
|
|
|
b = Box(fun, config=self.config)
|
2007-01-24 22:24:01 +08:00
|
|
|
parent, pid = b.run(continuation=True)
|
|
|
|
|
2007-01-25 00:46:46 +08:00
|
|
|
def cont(waiter=os.waitpid):
|
|
|
|
parent(pid, waiter=waiter)
|
2007-01-24 22:24:01 +08:00
|
|
|
if b.retval is not None:
|
|
|
|
passed, setupfailure, excinfo, skipped,\
|
|
|
|
critical, _, _, _ = b.retval
|
|
|
|
return (passed, setupfailure, excinfo, skipped, critical, 0,
|
|
|
|
b.stdoutrepr, b.stderrrepr)
|
|
|
|
else:
|
|
|
|
return (False, False, None, False, False,
|
|
|
|
b.signal, b.stdoutrepr, b.stderrrepr)
|
|
|
|
|
|
|
|
return cont, pid
|