[py-svn] r45869 - in py/branch/session-cleanups/py/test: . rsession rsession/testing testing
fijal at codespeak.net
fijal at codespeak.net
Sun Aug 19 17:27:00 CEST 2007
Author: fijal
Date: Sun Aug 19 17:26:59 2007
New Revision: 45869
Modified:
py/branch/session-cleanups/py/test/repevent.py
py/branch/session-cleanups/py/test/reporter.py
py/branch/session-cleanups/py/test/rsession/rsession.py
py/branch/session-cleanups/py/test/rsession/testing/test_rsession.py
py/branch/session-cleanups/py/test/rsession/web.py
py/branch/session-cleanups/py/test/testing/test_repevent.py
Log:
Kill another hack. This simplifies a bit what's going on in a reporter.
Modified: py/branch/session-cleanups/py/test/repevent.py
==============================================================================
--- py/branch/session-cleanups/py/test/repevent.py (original)
+++ py/branch/session-cleanups/py/test/repevent.py Sun Aug 19 17:26:59 2007
@@ -38,6 +38,9 @@
for key, value in self.__dict__.items()]
return "<%s %s>" %(self.__class__.__name__, " ".join(l),)
+ def is_failure(self):
+ return False
+
class SendItem(ReportEvent):
def __init__(self, channel, item):
self.item = item
@@ -53,6 +56,9 @@
self.item = item
self.outcome = outcome
+ def is_failure(self):
+ return not (self.outcome.passed or self.outcome.skipped)
+
class CallEvent(ReportEvent):
def __init__(self, func, args, kwargs):
self.func = func
@@ -115,6 +121,9 @@
self.excinfo = excinfo
self.item = item
+ def is_failure(self):
+ return True
+
class ItemStart(ReportEvent):
""" This class shows most of the start stuff, like directory, module, class
can be used for containers
Modified: py/branch/session-cleanups/py/test/reporter.py
==============================================================================
--- py/branch/session-cleanups/py/test/reporter.py (original)
+++ py/branch/session-cleanups/py/test/reporter.py Sun Aug 19 17:26:59 2007
@@ -29,6 +29,25 @@
else:
return LocalReporter
+class TestReporter(object):
+ """ Simple test reporter which tracks failures
+ and also calls arbitrary provided function,
+ useful for tests
+ """
+ def __init__(self, reportfun):
+ self.reportfun = reportfun
+ self.flag = False
+
+ def report(self, event):
+ if event.is_failure():
+ self.flag = True
+ self.reportfun(event)
+
+ __call__ = report
+
+ def was_failure(self):
+ return self.flag
+
class AbstractReporter(object):
def __init__(self, config, hosts):
self.config = config
@@ -61,6 +80,8 @@
# XXX reenable test before removing below line and
# run it with raise
#raise
+
+ __call__ = report
def report_unknown(self, what):
if self.config.option.verbose:
@@ -289,6 +310,9 @@
def report_Nodes(self, event):
self.nodes = event.nodes
+ def was_failure(self):
+ return len(self.failed) > 0
+
class RemoteReporter(AbstractReporter):
def get_item_name(self, event, colitem):
return event.host.hostname + ":" + \
Modified: py/branch/session-cleanups/py/test/rsession/rsession.py
==============================================================================
--- py/branch/session-cleanups/py/test/rsession/rsession.py (original)
+++ py/branch/session-cleanups/py/test/rsession/rsession.py Sun Aug 19 17:26:59 2007
@@ -13,7 +13,7 @@
from py.__.test.rsession.hostmanage import HostInfo, HostManager
from py.__.test.rsession.local import local_loop, plain_runner, apigen_runner,\
box_runner
-from py.__.test.reporter import LocalReporter, RemoteReporter
+from py.__.test.reporter import LocalReporter, RemoteReporter, TestReporter
from py.__.test.session import Session
from py.__.test.outcome import Skipped, Failed
@@ -30,25 +30,16 @@
if self.config.getvalue("dist_boxed"):
option.boxed = True
super(AbstractSession, self).fixoptions()
-
- def wrap_reporter(self, reporter):
- """ We wrap reporter around, which makes it possible to us to track
- existance of failures
- XXX kill this bastard
- """
- self.was_failure = False
- def new_reporter(event):
- if isinstance(event, repevent.ReceivedItemOutcome) and \
- not event.outcome.passed and \
- not event.outcome.skipped:
- self.was_failure = True
- return reporter(event)
- checkfun = lambda : self.config.option.exitfirst and \
- self.was_failure
- # for tests
- self.checkfun = checkfun
- return new_reporter, checkfun
+ def init_reporter(self, reporter, config, hosts):
+ if reporter is None:
+ reporter = choose_reporter(config)(config, hm.hosts)
+ else:
+ reporter = TestReporter(reporter)
+ checkfun = lambda : self.config.option.exitfirst and \
+ reporter.was_failure()
+ return reporter, checkfun
+
class RSession(AbstractSession):
""" Remote version of session
"""
@@ -77,9 +68,7 @@
""" main loop for running tests. """
config = self.config
hm = HostManager(config)
- if reporter is None:
- reporter = choose_reporter(config)(config, hm.hosts).report
- reporter, checkfun = self.wrap_reporter(reporter)
+ reporter, checkfun = self.init_reporter(reporter, config, hm.hosts)
reporter(repevent.TestStarted(hm.hosts, self.config.topdir,
hm.roots))
@@ -126,9 +115,8 @@
hosts = hm.hosts
if not self.config.option.nomagic:
py.magic.invoke(assertion=1)
- if reporter is None:
- reporter = choose_reporter(config)(config, hosts).report
- reporter, checkfun = self.wrap_reporter(reporter)
+
+ reporter, checkfun = self.init_reporter(reporter, config, hosts)
reporter(repevent.TestStarted(hosts, self.config.topdir, []))
colitems = self.config.getcolitems()
Modified: py/branch/session-cleanups/py/test/rsession/testing/test_rsession.py
==============================================================================
--- py/branch/session-cleanups/py/test/rsession/testing/test_rsession.py (original)
+++ py/branch/session-cleanups/py/test/rsession/testing/test_rsession.py Sun Aug 19 17:26:59 2007
@@ -40,7 +40,6 @@
testevents = [x for x in allevents
if isinstance(x, repevent.ReceivedItemOutcome)]
assert len(testevents) == 3
- assert rsession.checkfun()
def test_distribution_rsync_roots_example(self):
destdir = py.test.ensuretemp("example_dist_destdir")
Modified: py/branch/session-cleanups/py/test/rsession/web.py
==============================================================================
--- py/branch/session-cleanups/py/test/rsession/web.py (original)
+++ py/branch/session-cleanups/py/test/rsession/web.py Sun Aug 19 17:26:59 2007
@@ -427,6 +427,7 @@
# rebind
report = exported_methods.report
+ __call__ = report
def start_server_from_config(config):
if config.option.runbrowser:
Modified: py/branch/session-cleanups/py/test/testing/test_repevent.py
==============================================================================
--- py/branch/session-cleanups/py/test/testing/test_repevent.py (original)
+++ py/branch/session-cleanups/py/test/testing/test_repevent.py Sun Aug 19 17:26:59 2007
@@ -28,9 +28,26 @@
""" Checks if all the methods of reporter are sane
"""
from py.__.test.reporter import RemoteReporter
- from py.__.test import repevent
for method in dir(RemoteReporter):
if method.startswith("report_") and method != "report_unknown":
assert method[len('report_'):] in repevent.__dict__
+
+def test_repevent_failures():
+ from py.__.test.outcome import SerializableOutcome, ReprOutcome
+
+ assert not repevent.ReportEvent().is_failure()
+ assert not repevent.CallEvent(None, None, None).is_failure()
+ assert repevent.FailedTryiter(None, None).is_failure()
+ out = ReprOutcome(SerializableOutcome().make_repr())
+ assert not repevent.ReceivedItemOutcome(None, None, out).is_failure()
+ out = ReprOutcome(SerializableOutcome(skipped=True).make_repr())
+ assert not repevent.ReceivedItemOutcome(None, None, out).is_failure()
+ try:
+ 1/0
+ except:
+ exc = py.code.ExceptionInfo()
+ out = ReprOutcome(SerializableOutcome(excinfo=exc).make_repr())
+ assert repevent.ReceivedItemOutcome(None, None, out).is_failure()
+
More information about the py-svn
mailing list