[py-svn] r36273 - in py/dist/py/test/rsession: . testing
fijal at codespeak.net
fijal at codespeak.net
Mon Jan 8 15:13:54 CET 2007
Author: fijal
Date: Mon Jan 8 15:13:52 2007
New Revision: 36273
Modified:
py/dist/py/test/rsession/reporter.py
py/dist/py/test/rsession/rsession.py
py/dist/py/test/rsession/testing/test_lsession.py
py/dist/py/test/rsession/testing/test_rsession.py
Log:
Refine the checkfun interface to something cleaner.
Modified: py/dist/py/test/rsession/reporter.py
==============================================================================
--- py/dist/py/test/rsession/reporter.py (original)
+++ py/dist/py/test/rsession/reporter.py Mon Jan 8 15:13:52 2007
@@ -239,9 +239,6 @@
itempath = " ".join(event.item.listnames()[1:])
print "%10s: %s %s" %(sshhost[:10], status, itempath)
- def is_failing(self):
- return len(self.failed_tests_outcome) != 0
-
def report_Nodes(self, event):
self.nodes = event.nodes
Modified: py/dist/py/test/rsession/rsession.py
==============================================================================
--- py/dist/py/test/rsession/rsession.py (original)
+++ py/dist/py/test/rsession/rsession.py Mon Jan 8 15:13:52 2007
@@ -117,7 +117,6 @@
startserverflag = self.config.option.startserver
restflag = self.config.option.restreport
- checkfun = lambda: None
if startserverflag and reporter is None:
from py.__.test.rsession.web import start_server, exported_methods
@@ -135,12 +134,10 @@
else:
reporter_instance = reporter_class(self.config, sshhosts)
reporter = reporter_instance.report
- checkfun = lambda : self.config.option.exitfirst and \
- reporter_instance.is_failing()
else:
startserverflag = False
- return reporter, checkfun, startserverflag
+ return reporter, startserverflag
def reporterror(reporter, data):
excinfo, item = data
@@ -157,6 +154,20 @@
from py.__.test.rsession.web import kill_server
kill_server()
+ def wrap_reporter(self, reporter):
+ """ We wrap reporter around, which makes it possible to us to track
+ number of failures
+ """
+ self.was_failure = False
+ def new_reporter(event):
+ if isinstance(event, report.ReceivedItemOutcome) and not event.outcome.passed:
+ 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 parse_directories(sshhosts):
# dictionary containing directories for hosts
@@ -174,17 +185,16 @@
class RSession(AbstractSession):
""" Remote version of session
"""
- def main(self, args, reporter=None, override_checkfun=None):
+ def main(self, args, reporter=None):
""" main loop for running tests. """
if not args:
args = [py.path.local()]
-
+
session_options.bind_config(self.config)
sshhosts, directories, remotepython, rsync_roots = self.read_distributed_config()
- reporter, checkfun, startserverflag = self.init_reporter(reporter,
+ reporter, startserverflag = self.init_reporter(reporter,
sshhosts, RemoteReporter)
- if override_checkfun:
- checkfun = override_checkfun
+ reporter, checkfun = self.wrap_reporter(reporter)
reporter(report.TestStarted(sshhosts))
@@ -235,7 +245,7 @@
class LSession(AbstractSession):
""" Local version of session
"""
- def main(self, args, reporter=None, runner=None, shouldstop=None):
+ def main(self, args, reporter=None, runner=None):
# check out if used options makes any sense
if not args:
@@ -247,10 +257,9 @@
py.magic.invoke(assertion=1)
session_options.bind_config(self.config)
- reporter, checkfun, startserverflag = self.init_reporter(reporter,
+ reporter, startserverflag = self.init_reporter(reporter,
sshhosts, LocalReporter, args[0])
- if shouldstop:
- checkfun = shouldstop
+ reporter, checkfun = self.wrap_reporter(reporter)
reporter(report.TestStarted(sshhosts))
pkgdir = self.getpkgdir(args[0])
Modified: py/dist/py/test/rsession/testing/test_lsession.py
==============================================================================
--- py/dist/py/test/rsession/testing/test_lsession.py (original)
+++ py/dist/py/test/rsession/testing/test_lsession.py Mon Jan 8 15:13:52 2007
@@ -121,14 +121,7 @@
lsession = LSession(config)
allevents = []
- def check_stop():
- testevents = [x for x in allevents
- if isinstance(x, report.ReceivedItemOutcome)]
- failevents = [i for i in testevents if i.outcome.excinfo]
- return len(failevents) > 0
-
- lsession.main(args, reporter=allevents.append, runner=box_runner,
- shouldstop=check_stop)
+ lsession.main(args, reporter=allevents.append, runner=box_runner)
testevents = [x for x in allevents
if isinstance(x, report.ReceivedItemOutcome)]
assert len(testevents)
@@ -187,6 +180,7 @@
allruns = []
def dummy_runner(item, config, reporter):
allruns.append(item)
+ item.passed = True
return item
lsession.main(args, reporter=allevents.append, runner=dummy_runner)
Modified: py/dist/py/test/rsession/testing/test_rsession.py
==============================================================================
--- py/dist/py/test/rsession/testing/test_rsession.py (original)
+++ py/dist/py/test/rsession/testing/test_rsession.py Mon Jan 8 15:13:52 2007
@@ -113,7 +113,7 @@
tmpdir = py.test.ensuretemp("example_distribution_minus_x")
tmpdir.ensure("sub", "conftest.py").write(py.code.Source("""
disthosts = [%r]
- """ % 'localhost'))
+ """ % ('localhost',)))
tmpdir.ensure("sub", "__init__.py")
tmpdir.ensure("sub", "test_one.py").write(py.code.Source("""
def test_1():
@@ -129,13 +129,10 @@
config, args = py.test.Config.parse(args)
rsession = RSession(config)
allevents = []
- def check():
- return [x for x in allevents if isinstance(x, report.ReceivedItemOutcome) and
- not x.outcome.passed]
-
- rsession.main(args, reporter=allevents.append, override_checkfun=check)
+ rsession.main(args, reporter=allevents.append)
testevents = [x for x in allevents
if isinstance(x, report.ReceivedItemOutcome)]
+ assert rsession.checkfun()
assert len(testevents) == 2
def test_example_distribution(self):
More information about the py-svn
mailing list