2008-08-16 23:26:59 +08:00
|
|
|
"""
|
|
|
|
test collection and execution events
|
|
|
|
"""
|
|
|
|
|
|
|
|
import py
|
|
|
|
import time
|
|
|
|
from py.__.test.outcome import Skipped
|
|
|
|
|
|
|
|
class BaseEvent(object):
|
|
|
|
def __repr__(self):
|
|
|
|
l = ["%s=%s" %(key, value)
|
|
|
|
for key, value in self.__dict__.items()]
|
|
|
|
return "<%s %s>" %(self.__class__.__name__, " ".join(l),)
|
|
|
|
|
|
|
|
def timestamp():
|
|
|
|
return time.time()
|
|
|
|
|
|
|
|
class NOP(BaseEvent):
|
|
|
|
pass
|
|
|
|
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
# Basic Live Reporting Events
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
class TestrunStart(BaseEvent):
|
|
|
|
def __init__(self):
|
|
|
|
self.timestart = time.time()
|
|
|
|
|
|
|
|
class TestrunFinish(BaseEvent):
|
2008-09-13 04:35:18 +08:00
|
|
|
def __init__(self, exitstatus=0, excinfo=None):
|
2008-08-16 23:26:59 +08:00
|
|
|
self.exitstatus = exitstatus
|
2008-09-13 04:35:18 +08:00
|
|
|
if excinfo is None:
|
|
|
|
self.excrepr = None
|
|
|
|
else:
|
|
|
|
self.excrepr = excinfo.getrepr()
|
2008-08-16 23:26:59 +08:00
|
|
|
self.timeend = time.time()
|
|
|
|
|
|
|
|
class InternalException(BaseEvent):
|
|
|
|
def __init__(self, excinfo=None):
|
|
|
|
if excinfo is None:
|
|
|
|
excinfo = py.code.ExceptionInfo()
|
|
|
|
self.repr = excinfo.getrepr(funcargs=True, showlocals=True)
|
|
|
|
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
# Events related to collecting and executing test Items
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
class ItemStart(BaseEvent):
|
|
|
|
def __init__(self, item, host=None):
|
|
|
|
self.item = item
|
|
|
|
self.host = host
|
|
|
|
self.time = timestamp()
|
|
|
|
|
|
|
|
class Deselected(BaseEvent):
|
|
|
|
def __init__(self, items):
|
|
|
|
self.items = items
|
|
|
|
|
|
|
|
|
|
|
|
class BaseReport(BaseEvent):
|
|
|
|
def toterminal(self, out):
|
2009-02-27 18:18:27 +08:00
|
|
|
longrepr = self.longrepr
|
2008-08-16 23:26:59 +08:00
|
|
|
if hasattr(longrepr, 'toterminal'):
|
|
|
|
longrepr.toterminal(out)
|
|
|
|
else:
|
|
|
|
out.line(str(longrepr))
|
2009-02-27 18:18:27 +08:00
|
|
|
|
2008-08-16 23:26:59 +08:00
|
|
|
class ItemTestReport(BaseReport):
|
|
|
|
""" Test Execution Report. """
|
2009-02-27 18:18:27 +08:00
|
|
|
failed = passed = skipped = False
|
2008-08-16 23:26:59 +08:00
|
|
|
|
2009-02-27 18:18:27 +08:00
|
|
|
def __init__(self, colitem, excinfo=None, when=None, outerr=None):
|
|
|
|
self.colitem = colitem
|
|
|
|
self.keywords = colitem and colitem.readkeywords()
|
|
|
|
if not excinfo:
|
|
|
|
self.passed = True
|
|
|
|
self.shortrepr = "."
|
|
|
|
else:
|
|
|
|
self.when = when
|
|
|
|
if not isinstance(excinfo, py.code.ExceptionInfo):
|
|
|
|
self.failed = True
|
|
|
|
shortrepr = "?"
|
|
|
|
longrepr = excinfo
|
|
|
|
elif excinfo.errisinstance(Skipped):
|
|
|
|
self.skipped = True
|
|
|
|
shortrepr = "s"
|
|
|
|
longrepr = self.colitem._repr_failure_py(excinfo, outerr)
|
|
|
|
else:
|
|
|
|
self.failed = True
|
|
|
|
shortrepr = self.colitem.shortfailurerepr
|
|
|
|
if self.when == "execute":
|
|
|
|
longrepr = self.colitem.repr_failure(excinfo, outerr)
|
|
|
|
else: # exception in setup or teardown
|
|
|
|
longrepr = self.colitem._repr_failure_py(excinfo, outerr)
|
|
|
|
shortrepr = shortrepr.lower()
|
|
|
|
self.shortrepr = shortrepr
|
|
|
|
self.longrepr = longrepr
|
|
|
|
|
2008-08-16 23:26:59 +08:00
|
|
|
class CollectionStart(BaseEvent):
|
|
|
|
def __init__(self, collector):
|
|
|
|
self.collector = collector
|
|
|
|
|
|
|
|
class CollectionReport(BaseReport):
|
|
|
|
""" Collection Report. """
|
2009-02-27 18:18:27 +08:00
|
|
|
skipped = failed = passed = False
|
|
|
|
|
|
|
|
def __init__(self, colitem, result, excinfo=None, when=None, outerr=None):
|
|
|
|
self.colitem = colitem
|
|
|
|
if not excinfo:
|
|
|
|
self.passed = True
|
|
|
|
self.result = result
|
|
|
|
else:
|
|
|
|
self.when = when
|
|
|
|
self.outerr = outerr
|
|
|
|
self.longrepr = self.colitem._repr_failure_py(excinfo, outerr)
|
|
|
|
if excinfo.errisinstance(Skipped):
|
|
|
|
self.skipped = True
|
|
|
|
self.reason = str(excinfo.value)
|
|
|
|
else:
|
|
|
|
self.failed = True
|
|
|
|
|
|
|
|
def toterminal(self, out):
|
|
|
|
longrepr = self.longrepr
|
|
|
|
if hasattr(longrepr, 'toterminal'):
|
|
|
|
longrepr.toterminal(out)
|
|
|
|
else:
|
|
|
|
out.line(str(longrepr))
|
2008-08-16 23:26:59 +08:00
|
|
|
|
|
|
|
class LooponfailingInfo(BaseEvent):
|
|
|
|
def __init__(self, failreports, rootdirs):
|
|
|
|
self.failreports = failreports
|
|
|
|
self.rootdirs = rootdirs
|
|
|
|
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
# Distributed Testing Events
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
class RescheduleItems(BaseEvent):
|
|
|
|
def __init__(self, items):
|
|
|
|
self.items = items
|
|
|
|
|
|
|
|
class HostGatewayReady(BaseEvent):
|
|
|
|
def __init__(self, host, roots):
|
|
|
|
self.host = host
|
|
|
|
self.roots = roots
|
|
|
|
|
|
|
|
class HostUp(BaseEvent):
|
|
|
|
def __init__(self, host, platinfo):
|
|
|
|
self.host = host
|
|
|
|
self.platinfo = platinfo
|
|
|
|
|
|
|
|
class HostDown(BaseEvent):
|
|
|
|
def __init__(self, host, error=None):
|
|
|
|
self.host = host
|
|
|
|
self.error = error
|
|
|
|
|
2008-08-24 18:58:42 +08:00
|
|
|
# ---------------------------------------------------------------------
|
|
|
|
# Events related to rsyncing
|
|
|
|
# ---------------------------------------------------------------------
|
2008-08-16 23:26:59 +08:00
|
|
|
|
|
|
|
class HostRSyncing(BaseEvent):
|
|
|
|
def __init__(self, host, root, remotepath, synced):
|
|
|
|
self.host = host
|
|
|
|
self.root = root
|
|
|
|
self.remotepath = remotepath
|
|
|
|
self.synced = synced
|
|
|
|
|
|
|
|
class RsyncFinished(BaseEvent):
|
|
|
|
def __init__(self):
|
|
|
|
self.time = timestamp()
|
|
|
|
|
|
|
|
class HostRSyncRootReady(BaseEvent):
|
|
|
|
def __init__(self, host, root):
|
|
|
|
self.host = host
|
|
|
|
self.root = root
|
|
|
|
|
2009-02-27 18:18:27 +08:00
|
|
|
|
|
|
|
# make all eventclasses available on BaseEvent so that
|
|
|
|
# consumers of events can easily filter by
|
|
|
|
# 'isinstance(event, event.Name)' checks
|
|
|
|
|
|
|
|
for name, cls in vars().items():
|
|
|
|
if hasattr(cls, '__bases__') and issubclass(cls, BaseEvent):
|
|
|
|
setattr(BaseEvent, name, cls)
|
|
|
|
#
|