[py-svn] r51150 - in py/branch/event/py/test2: . rsession rsession/testing testing
hpk at codespeak.net
hpk at codespeak.net
Thu Jan 31 10:48:39 CET 2008
Author: hpk
Date: Thu Jan 31 10:48:37 2008
New Revision: 51150
Modified:
py/branch/event/py/test2/config.py
py/branch/event/py/test2/executor.py
py/branch/event/py/test2/repevent.py
py/branch/event/py/test2/rsession/hostmanage.py
py/branch/event/py/test2/rsession/master.py
py/branch/event/py/test2/rsession/rsession.py
py/branch/event/py/test2/rsession/slave.py
py/branch/event/py/test2/rsession/testing/test_hostmanage.py
py/branch/event/py/test2/rsession/testing/test_master.py
py/branch/event/py/test2/rsession/testing/test_rest.py
py/branch/event/py/test2/rsession/testing/test_rsession.py
py/branch/event/py/test2/session.py
py/branch/event/py/test2/testing/test_collect.py
py/branch/event/py/test2/testing/test_repevent.py
py/branch/event/py/test2/testing/test_reporter.py
py/branch/event/py/test2/testing/test_session.py
py/branch/event/py/test2/testing/test_session2.py
Log:
* intermediate checkin
* refactoring towards using general events
* py/test2/testing passes apart from output-checking tests
* py/test2/rsession is still too messy ...
Modified: py/branch/event/py/test2/config.py
==============================================================================
--- py/branch/event/py/test2/config.py (original)
+++ py/branch/event/py/test2/config.py Thu Jan 31 10:48:37 2008
@@ -34,6 +34,7 @@
usage="usage: %prog [options] [query] [filenames of tests]")
self._conftest = Conftest()
self._initialized = False
+ self.hub = py.event.Hub()
def parse(self, args):
""" parse cmdline arguments into this config object.
Modified: py/branch/event/py/test2/executor.py
==============================================================================
--- py/branch/event/py/test2/executor.py (original)
+++ py/branch/event/py/test2/executor.py Thu Jan 31 10:48:37 2008
@@ -14,12 +14,9 @@
"""
wraps = False
- def __init__(self, item, usepdb=False, reporter=None, config=None):
+ def __init__(self, item, config):
self.item = item
- self.usepdb = usepdb
- self.reporter = reporter
self.config = config
- assert self.config
def run(self, capture=True):
if capture:
@@ -55,11 +52,10 @@
path=code.path, firstlineno=code.firstlineno)
outcome = SerializableOutcome(excinfo=excinfo, setupfailure=False)
outcome.stdout, outcome.stderr = self.item._getouterr()
- if self.usepdb:
- if self.reporter is not None:
- self.reporter(repevent.ImmediateFailure(self.item,
- ReprOutcome(outcome.make_repr
- (self.config.option.tbstyle))))
+ if self.config.option.usepdb:
+ self.config.hub.notify(
+ repevent.ImmediateFailure(self.item,
+ ReprOutcome(outcome.make_repr(self.config.option.tbstyle))))
py.__.test2.custompdb.post_mortem(excinfo._excinfo[2])
# XXX hmm, we probably will not like to continue from that
# point
Modified: py/branch/event/py/test2/repevent.py
==============================================================================
--- py/branch/event/py/test2/repevent.py (original)
+++ py/branch/event/py/test2/repevent.py Thu Jan 31 10:48:37 2008
@@ -7,27 +7,6 @@
def basic_report(msg_type, message):
print msg_type, message
-#def report(msg_type, message):
-# pass
-
-##def report_error(excinfo):
-## if isinstance(excinfo, py.test2.collect.Item.Skipped):
-## # we need to dispatch this info
-## report(Skipped(excinfo))
-## else:
-## report("itererror", excinfo)
-
-def wrapcall(reporter, func, *args, **kwargs):
- reporter(CallStart(func, args, kwargs))
- try:
- retval = func(*args, **kwargs)
- except:
- reporter(CallException(func, args, kwargs))
- raise
- else:
- reporter(CallFinish(func, args, kwargs))
- return retval
-
# ----------------------------------------------------------------------
# Reporting Events
# ----------------------------------------------------------------------
@@ -59,25 +38,25 @@
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
- self.args = args
- self.kwargs = kwargs
-
- def __repr__(self):
- call = "%s args=%s, kwargs=%s" %(self.func.__name__,
- self.args, self.kwargs)
- return '<%s %s>' %(self.__class__.__name__, call)
-
-class CallStart(CallEvent):
- pass
-
-class CallException(CallEvent):
- pass
-
-class CallFinish(CallEvent):
- pass
+#class CallEvent(ReportEvent):
+# def __init__(self, func, args, kwargs):
+# self.func = func
+# self.args = args
+# self.kwargs = kwargs
+#
+# def __repr__(self):
+# call = "%s args=%s, kwargs=%s" %(self.func.__name__,
+# self.args, self.kwargs)
+# return '<%s %s>' %(self.__class__.__name__, call)
+#
+#class CallStart(CallEvent):
+# pass
+#
+#class CallException(CallEvent):
+# pass
+#
+#class CallFinish(CallEvent):
+# pass
class HostRSyncing(ReportEvent):
def __init__(self, host, root, remotepath, synced):
Modified: py/branch/event/py/test2/rsession/hostmanage.py
==============================================================================
--- py/branch/event/py/test2/rsession/hostmanage.py (original)
+++ py/branch/event/py/test2/rsession/hostmanage.py Thu Jan 31 10:48:37 2008
@@ -93,7 +93,7 @@
else:
return True
- def add_target_host(self, host, destrelpath="", reporter=lambda x: None):
+ def add_target_host(self, host, destrelpath="", notify=None):
remotepath = host.gw_remotepath
key = host.hostname, host.relpath
if host.inplacelocal:
@@ -102,10 +102,14 @@
elif destrelpath:
remotepath = os.path.join(remotepath, destrelpath)
synced = key in self._synced
- reporter(repevent.HostRSyncing(host, py.path.local(self._sourcedir),
- remotepath, synced))
+ if notify:
+ notify(
+ repevent.HostRSyncing(host, py.path.local(self._sourcedir),
+ remotepath, synced))
def hostrsynced(host=host):
- reporter(repevent.HostRSyncRootReady(host, self._sourcedir))
+ if notify:
+ notify(
+ repevent.HostRSyncRootReady(host, self._sourcedir))
if key in self._synced:
hostrsynced()
return
@@ -131,16 +135,16 @@
hosts = [HostInfo(x, addrel) for x in hosts]
self.hosts = hosts
- def prepare_gateways(self, reporter):
+ def prepare_gateways(self):
python = self.config.getvalue("dist_remotepython")
for host in self.hosts:
host.initgateway(python=python)
- reporter(repevent.HostGatewayReady(host, self.roots))
+ self.config.hub.notify(repevent.HostGatewayReady(host, self.roots))
host.gw.host = host
- def init_rsync(self, reporter):
+ def init_rsync(self):
ignores = self.config.getvalue_pathlist("dist_rsync_ignore")
- self.prepare_gateways(reporter)
+ self.prepare_gateways()
# send each rsync root
for root in self.roots:
rsync = HostRSync(root, ignores=ignores,
@@ -150,22 +154,24 @@
else:
destrelpath = root.basename
for host in self.hosts:
- rsync.add_target_host(host, destrelpath, reporter)
+ rsync.add_target_host(host, destrelpath)
rsync.send(raises=False)
- def setup_hosts(self, reporter):
- self.init_rsync(reporter)
+ def setup_hosts(self):
+ self.init_rsync()
nodes = []
for host in self.hosts:
if hasattr(host.gw, 'remote_exec'): # otherwise dummy for tests :/
ch = setup_slave(host, self.config)
- nodes.append(MasterNode(ch, reporter))
+ nodes.append(MasterNode(ch, self.config.hub.notify))
return nodes
- def teardown_hosts(self, reporter, channels, nodes,
+ def teardown_hosts(self, channels, nodes,
waiter=lambda : time.sleep(.1), exitfirst=False):
for channel in channels:
channel.send(None)
+ # XXX
+ return
clean = exitfirst
while not clean:
@@ -174,17 +180,19 @@
if node.pending:
clean = False
waiter()
- self.teardown_gateways(reporter, channels)
+ self.teardown_gateways(channels)
def kill_channels(self, channels):
for channel in channels:
channel.send(42)
- def teardown_gateways(self, reporter, channels):
+ def teardown_gateways(self, channels):
+ return
+ self.config.hub.notify("tear down %r" %(channels,))
for channel in channels:
#try:
try:
- repevent.wrapcall(reporter, channel.waitclose, 1)
+ channel.waitclose(1.0)
except IOError: # timeout
# force closing
channel.close()
Modified: py/branch/event/py/test2/rsession/master.py
==============================================================================
--- py/branch/event/py/test2/rsession/master.py (original)
+++ py/branch/event/py/test2/rsession/master.py Thu Jan 31 10:48:37 2008
@@ -8,9 +8,9 @@
from py.builtin import GeneratorExit
class MasterNode(object):
- def __init__(self, channel, reporter):
+ def __init__(self, channel, notify):
+ self.notify = notify
self.channel = channel
- self.reporter = reporter
self.pending = []
channel.setcallback(self._callback)
@@ -21,8 +21,8 @@
def receive_result(self, outcomestring, item):
repr_outcome = ReprOutcome(outcomestring)
# send finish report
- self.reporter(repevent.ReceivedItemOutcome(
- self.channel, item, repr_outcome))
+ self.notify(repevent.ReceivedItemOutcome(
+ self.channel, item, repr_outcome))
def send(self, item):
try:
@@ -33,7 +33,7 @@
#itemspec = item.listnames()[1:]
self.channel.send(item._get_collector_trail())
# send start report
- self.reporter(repevent.SendItem(self.channel, item))
+ self.notify(repevent.SendItem(self.channel, item))
except IOError:
print "Sending error, channel IOError"
print self.channel._getremoteerror()
@@ -41,7 +41,7 @@
# of hanging nodes and such
raise
-def dispatch_loop(masternodes, itemgenerator, shouldstop,
+def dispatch_loop(masternodes, itemgenerator, #shouldstop,
waiter = lambda: py.std.time.sleep(0.1),
max_tasks_per_node=15):
all_tests = {}
@@ -51,10 +51,10 @@
if len(node.pending) < max_tasks_per_node:
item = itemgenerator.next()
all_tests[item] = True
- if shouldstop():
- for _node in masternodes:
- _node.send(StopIteration) # magic connector
- return None
+ #if shouldstop():
+ # for _node in masternodes:
+ # _node.send(StopIteration) # magic connector
+ # return None
node.send(item)
except StopIteration:
break
Modified: py/branch/event/py/test2/rsession/rsession.py
==============================================================================
--- py/branch/event/py/test2/rsession/rsession.py (original)
+++ py/branch/event/py/test2/rsession/rsession.py Thu Jan 31 10:48:37 2008
@@ -9,19 +9,16 @@
import time
from py.__.test2 import repevent
-from py.__.test2.rsession.master import MasterNode, dispatch_loop
+from py.__.test2.rsession.master import dispatch_loop
from py.__.test2.rsession.hostmanage import HostInfo, HostManager
from py.__.test2.rsession.local import local_loop, plain_runner, apigen_runner,\
box_runner
-from py.__.test2.reporter import LocalReporter, RemoteReporter, TestReporter
from py.__.test2.session import AbstractSession, itemgen
from py.__.test2.outcome import Skipped, Failed
class RSession(AbstractSession):
""" Remote version of session
"""
- reporterclass = RemoteReporter
-
def fixoptions(self):
super(RSession, self).fixoptions()
option = self.config.option
@@ -43,47 +40,42 @@
print "see also: http://codespeak.net/py/current/doc/test.html#automated-distributed-testing"
raise SystemExit
- def main(self, reporter=None):
+ def main(self):
""" main loop for running tests. """
- config = self.config
- hm = HostManager(config)
- reporter, checkfun = self.init_reporter(reporter, config, hm.hosts)
-
- reporter(repevent.TestStarted(hm.hosts, self.config,
- hm.roots))
- self.reporter = reporter
-
+ hm = HostManager(self.config)
+ hub = self.config.hub
+ hub.notify(repevent.TestStarted(hm.hosts, self.config, hm.roots))
try:
- nodes = hm.setup_hosts(reporter)
- reporter(repevent.RsyncFinished())
+ nodes = hm.setup_hosts()
+ hub.notify(repevent.RsyncFinished())
try:
- self.dispatch_tests(nodes, reporter, checkfun)
+ self.dispatch_tests(nodes)
except (KeyboardInterrupt, SystemExit):
print >>sys.stderr, "C-c pressed waiting for gateways to teardown..."
channels = [node.channel for node in nodes]
hm.kill_channels(channels)
- hm.teardown_gateways(reporter, channels)
+ hm.teardown_gateways(channels)
print >>sys.stderr, "... Done"
raise
+ print "tearing down nodes"
channels = [node.channel for node in nodes]
- hm.teardown_hosts(reporter, channels, nodes,
- exitfirst=self.config.option.exitfirst)
- reporter(repevent.Nodes(nodes))
- retval = reporter(repevent.TestFinished())
- return retval
+ hm.teardown_hosts(channels, nodes)
+ hub.notify(repevent.Nodes(nodes))
+ # XXX retval = reporter(repevent.TestFinished())
+ hub.notify(repevent.TestFinished())
except (KeyboardInterrupt, SystemExit):
- reporter(repevent.InterruptedExecution())
+ hub.notify(repevent.InterruptedExecution())
raise
except:
- reporter(repevent.CrashedExecution())
+ hub.notify(repevent.CrashedExecution())
raise
- def dispatch_tests(self, nodes, reporter, checkfun):
+ def dispatch_tests(self, nodes):
colitems = self.config.getcolitems()
keyword = self.config.option.keyword
- itemgenerator = itemgen(self, colitems, reporter, keyword)
+ itemgenerator = itemgen(self, colitems, keyword)
max_tasks_per_node = self.config.getvalue("dist_taskspernode")
- all_tests = dispatch_loop(nodes, itemgenerator, checkfun,
+ all_tests = dispatch_loop(nodes, itemgenerator,
max_tasks_per_node=max_tasks_per_node)
Modified: py/branch/event/py/test2/rsession/slave.py
==============================================================================
--- py/branch/event/py/test2/rsession/slave.py (original)
+++ py/branch/event/py/test2/rsession/slave.py Thu Jan 31 10:48:37 2008
@@ -11,7 +11,6 @@
class SlaveNode(object):
def __init__(self, config, executor):
- #self.rootcollector = rootcollector
self.config = config
self.executor = executor
@@ -21,8 +20,6 @@
return ex.execute()
def run(self, itemspec):
- #outcome = self.execute(itemspec)
- #return outcome.make_repr()
outcome = self.execute(itemspec)
if self.executor.wraps:
return outcome
Modified: py/branch/event/py/test2/rsession/testing/test_hostmanage.py
==============================================================================
--- py/branch/event/py/test2/rsession/testing/test_hostmanage.py (original)
+++ py/branch/event/py/test2/rsession/testing/test_hostmanage.py Thu Jan 31 10:48:37 2008
@@ -130,7 +130,7 @@
events = []
rsync = HostRSync(self.source)
h1.initgateway()
- rsync.add_target_host(h1, reporter=events.append)
+ rsync.add_target_host(h1, notify=events.append)
assert events
l = [x for x in events
if isinstance(x, repevent.HostRSyncing)]
@@ -192,7 +192,7 @@
dist_hosts = ["localhost:%s" % self.dest]
)
assert hm.config.topdir == self.source
- hm.init_rsync([].append)
+ hm.init_rsync()
dest = self.dest.join(self.source.basename)
assert dest.join("dir1").check()
assert dest.join("dir1", "dir2").check()
@@ -206,7 +206,7 @@
dist_rsync_roots = [str(self.source)]
)
assert hm.config.topdir == self.source
- hm.init_rsync([].append)
+ hm.init_rsync()
dest = self.dest.join(self.source.basename)
assert dest.join("dir1").check()
assert dest.join("dir1", "dir2").check()
@@ -223,8 +223,7 @@
config = py.test2.config._reparse([self.source])
hm = HostManager(config,
hosts=[HostInfo("localhost:" + str(self.dest))])
- events = []
- hm.init_rsync(reporter=events.append)
+ hm.init_rsync()
assert self.dest.join("dir2").check()
assert not self.dest.join("dir1").check()
assert not self.dest.join("bogus").check()
@@ -240,9 +239,7 @@
config = py.test2.config._reparse([self.source])
hm = HostManager(config,
hosts=[HostInfo("localhost:" + str(self.dest))])
- events = []
- print events
- hm.init_rsync(reporter=events.append)
+ hm.init_rsync()
assert self.dest.join("dir1").check()
assert not self.dest.join("dir1", "dir2").check()
assert self.dest.join("dir5","file").check()
@@ -252,13 +249,11 @@
hosts = [HostInfo("localhost") for i in range(3)]
config = py.test2.config._reparse([self.source])
hm = HostManager(config, hosts=hosts)
- events = []
- hm.init_rsync(events.append)
+ hm.init_rsync()
for host in hosts:
assert host.inplacelocal
assert host.gw_remotepath is None
assert not host.relpath
- assert events
def XXXtest_ssh_rsync_samehost_twice(self):
#XXX we have no easy way to have a temp directory remotely!
Modified: py/branch/event/py/test2/rsession/testing/test_master.py
==============================================================================
--- py/branch/event/py/test2/rsession/testing/test_master.py (original)
+++ py/branch/event/py/test2/rsession/testing/test_master.py Thu Jan 31 10:48:37 2008
@@ -114,7 +114,7 @@
def waiter():
for node in masternodes:
node.pending.pop()
- dispatch_loop(masternodes, itemgenerator, shouldstop, waiter=waiter)
+ dispatch_loop(masternodes, itemgenerator, waiter=waiter)
class TestSlave:
def setup_class(cls):
Modified: py/branch/event/py/test2/rsession/testing/test_rest.py
==============================================================================
--- py/branch/event/py/test2/rsession/testing/test_rest.py (original)
+++ py/branch/event/py/test2/rsession/testing/test_rest.py Thu Jan 31 10:48:37 2008
@@ -3,6 +3,9 @@
"""
import py
+
+py.test.skip("refactor ReST reporter tests")
+
from py.__.test2.testing.test_reporter import AbstractTestReporter,\
DummyChannel
from py.__.test2 import repevent
Modified: py/branch/event/py/test2/rsession/testing/test_rsession.py
==============================================================================
--- py/branch/event/py/test2/rsession/testing/test_rsession.py (original)
+++ py/branch/event/py/test2/rsession/testing/test_rsession.py Thu Jan 31 10:48:37 2008
@@ -9,6 +9,8 @@
from py.__.test2.rsession.testing.basetest import BasicRsessionTest
from py.__.test2.rsession.testing.test_hostmanage import DirSetup
+from py.__.test2.testing.test_session import getevents_runmain
+
def setup_module(mod):
mod.pkgdir = py.path.local(py.__file__).dirpath()
if py.std.sys.platform == "win32":
@@ -34,9 +36,11 @@
pass
"""))
config = py.test2.config._reparse([self.source.join("sub"), '-x'])
- allevents = []
rsession = RSession(config)
- rsession.main(allevents.append)
+ def f(ev):
+ print ev
+ config.hub.append(f)
+ allevents = getevents_runmain(rsession)
testevents = [x for x in allevents
if isinstance(x, repevent.ReceivedItemOutcome)]
assert len(testevents) == 3
@@ -69,9 +73,8 @@
config = py.test2.config._reparse([tmpdir.join(subdir)])
assert config.topdir == tmpdir
assert not tmpdir.join("__init__.py").check()
- allevents = []
rsession = RSession(config)
- rsession.main(allevents.append)
+ allevents = getevents_runmain(rsession)
testevents = [x for x in allevents
if isinstance(x, repevent.ReceivedItemOutcome)]
assert len(testevents)
@@ -103,9 +106,12 @@
tmpdir = self.source
config = py.test2.config._reparse([tmpdir])
hm = HostManager(config, hosts)
- nodes = hm.setup_hosts(setup_events.append)
- hm.teardown_hosts(teardown_events.append,
- [node.channel for node in nodes], nodes)
+
+ config.hub.append(setup_events.append)
+ nodes = hm.setup_hosts()
+
+ config.hub.append(teardown_events.append)
+ hm.teardown_hosts([node.channel for node in nodes], nodes)
count_rsyn_calls = [i for i in setup_events
if isinstance(i, repevent.HostRSyncing)]
@@ -125,12 +131,9 @@
def test_setup_teardown_run_ssh(self):
hosts = [HostInfo('localhost:%s' % self.dest)]
allevents = []
-
+ self.config.hub.append(allevents.append)
hm = HostManager(self.config, hosts=hosts)
- nodes = hm.setup_hosts(allevents.append)
-
- from py.__.test2.testing.test_executor \
- import ItemTestPassing, ItemTestFailing, ItemTestSkipping
+ nodes = hm.setup_hosts()
itempass = self.getexample("pass")
itemfail = self.getexample("fail")
@@ -144,7 +147,7 @@
node.send(itemskip)
node.send(itemprint)
- hm.teardown_hosts(allevents.append, [node.channel for node in nodes], nodes)
+ hm.teardown_hosts([node.channel for node in nodes], nodes)
events = [i for i in allevents
if isinstance(i, repevent.ReceivedItemOutcome)]
@@ -152,6 +155,7 @@
if i.outcome.passed]
skipped = [i for i in events
if i.outcome.skipped]
+ for x in allevents: print x
assert len(passed) == 2 * len(nodes)
assert len(skipped) == len(nodes)
assert len(events) == 4 * len(nodes)
@@ -162,7 +166,6 @@
def test_nice_level(self):
""" Tests if nice level behaviour is ok
"""
- allevents = []
hosts = [HostInfo('localhost:%s' % self.dest)]
tmpdir = self.source
tmpdir.ensure("__init__.py")
@@ -177,7 +180,7 @@
config = py.test2.config._reparse([tmpdir])
rsession = RSession(config)
- rsession.main(allevents.append)
+ allevents = getevents_runmain(rsession)
testevents = [x for x in allevents
if isinstance(x, repevent.ReceivedItemOutcome)]
passevents = [x for x in testevents if x.outcome.passed]
Modified: py/branch/event/py/test2/session.py
==============================================================================
--- py/branch/event/py/test2/session.py (original)
+++ py/branch/event/py/test2/session.py Thu Jan 31 10:48:37 2008
@@ -1,7 +1,6 @@
import py
import sys
from py.__.test2.outcome import Outcome, Failed, Passed, Skipped
-from py.__.test2.reporter import choose_reporter, TestReporter
from py.__.test2 import repevent
from py.__.test2.outcome import SerializableOutcome, ReprOutcome
from py.__.test2.reporter import LocalReporter
@@ -21,15 +20,14 @@
except NameError:
GeneratorExit = StopIteration # I think
-def itemgen(session, colitems, reporter, keyword=None):
+def itemgen(session, colitems, keyword=None):
+ hub = session.config.hub
stopitems = py.test2.collect.Item # XXX should be generator here as well
while 1:
if not colitems:
break
next = colitems.pop(0)
- if reporter:
- reporter(repevent.ItemStart(next))
-
+ hub.notify(repevent.ItemStart(next))
if isinstance(next, stopitems):
try:
next._skipbykeyword(keyword)
@@ -38,22 +36,21 @@
if session.config.option.keyword_oneshot:
keyword = None
excinfo = py.code.ExceptionInfo()
- reporter(repevent.SkippedTryiter(excinfo, next))
+ hub.notify(repevent.SkippedTryiter(excinfo, next))
else:
try:
cols = [next.join(x) for x in next.run()]
- for x in itemgen(session, cols, reporter, keyword):
+ for x in itemgen(session, cols, keyword):
yield x
except (KeyboardInterrupt, SystemExit, GeneratorExit):
raise
except:
excinfo = py.code.ExceptionInfo()
if excinfo.type is Skipped:
- reporter(repevent.SkippedTryiter(excinfo, next))
+ hub.notify(repevent.SkippedTryiter(excinfo, next))
else:
- reporter(repevent.FailedTryiter(excinfo, next))
- if reporter:
- reporter(repevent.ItemFinish(next))
+ hub.notify(repevent.FailedTryiter(excinfo, next))
+ hub.notify(repevent.ItemFinish(next))
class AbstractSession(object):
""" An abstract session executes collectors/items through a runner.
@@ -81,16 +78,6 @@
if option.keyword_oneshot and not option.keyword:
raise ValueError, "--keyword-oneshot makes sense only when --keyword is supplied"
- def init_reporter(self, reporter, config, hosts):
- if reporter is None:
- reporter = choose_reporter(self.reporterclass, config)\
- (config, hosts)
- else:
- reporter = TestReporter(reporter)
- checkfun = lambda : self.config.option.exitfirst and \
- reporter.was_failure()
- return reporter, checkfun
-
class Session(AbstractSession):
"""
A Session gets test Items from Collectors, executes the
@@ -103,8 +90,7 @@
def header(self, colitems):
""" setup any neccessary resources ahead of the test run. """
- self.reporter(repevent.TestStarted(None, self.config,
- None))
+ self.config.hub.notify(repevent.TestStarted(None, self.config, None))
if not self.config.option.nomagic:
py.magic.invoke(assertion=1)
@@ -113,30 +99,25 @@
py.test2.collect.Function._state.teardown_all()
if not self.config.option.nomagic:
py.magic.revoke(assertion=1)
- self.reporter(repevent.TestFinished())
+ self.config.hub.notify(repevent.TestFinished())
- def main(self, reporter=None):
+ def main(self):
""" main loop for running tests. """
config = self.config
- self.reporter, shouldstop = self.init_reporter(reporter, config, None)
-
colitems = self.config.getcolitems()
self.header(colitems)
keyword = self.config.option.keyword
- reporter = self.reporter
- itemgenerator = itemgen(self, colitems, reporter, keyword)
+ itemgenerator = itemgen(self, colitems, keyword)
failures = []
try:
while 1:
try:
item = itemgenerator.next()
- if shouldstop():
- return
outcome = self.run(item)
if outcome is not None:
if not outcome.passed and not outcome.skipped:
failures.append((item, outcome))
- reporter(repevent.ReceivedItemOutcome(None, item, outcome))
+ self.config.hub.notify(repevent.ReceivedItemOutcome(None, item, outcome))
except StopIteration:
break
finally:
@@ -146,12 +127,10 @@
def run(self, item):
if not self.config.option.boxed:
- executor = RunExecutor(item, self.config.option.usepdb,
- self.reporter, self.config)
+ executor = RunExecutor(item, config=self.config)
return ReprOutcome(executor.execute().make_repr())
else:
- executor = BoxExecutor(item, self.config.option.usepdb,
- self.reporter, self.config)
+ executor = BoxExecutor(item, config=self.config)
return ReprOutcome(executor.execute())
class Exit(Exception):
Modified: py/branch/event/py/test2/testing/test_collect.py
==============================================================================
--- py/branch/event/py/test2/testing/test_collect.py (original)
+++ py/branch/event/py/test2/testing/test_collect.py Thu Jan 31 10:48:37 2008
@@ -5,10 +5,18 @@
from py.__.test2.terminal.out import getout
from py.__.test2.repevent import ReceivedItemOutcome
-def getpassed(all):
- outcomes = [i.outcome for i in all if isinstance(i, ReceivedItemOutcome)]
- l = [i for i in outcomes if i.passed]
- return l
+def getpassed(session):
+ hub = session.config.hub
+ all = []
+ hub.append(all.append)
+ try:
+ session.main()
+ print all
+ outcomes = [i.outcome for i in all if isinstance(i, ReceivedItemOutcome)]
+ l = [i for i in outcomes if i.passed]
+ return l
+ finally:
+ hub.pop()
def setup_module(mod):
mod.datadir = setupdatadir()
@@ -210,20 +218,16 @@
old = o.chdir()
try:
config = py.test2.config._reparse([])
- all = []
session = config._getsessionclass()(config)
- session.main(all.append)
- l = getpassed(all)
+ l = getpassed(session)
assert len(l) == 2
finally:
old.chdir()
# test that running the file directly works
config = py.test2.config._reparse([str(checkfile)])
- all = []
session = config._getsessionclass()(config)
- session.main(all.append)
- l = getpassed(all)
+ l = getpassed(session)
assert len(l) == 2
def test_custom_NONpython_collection_from_conftest():
@@ -257,20 +261,16 @@
old = o.chdir()
try:
config = py.test2.config._reparse([])
- all = []
session = config._getsessionclass()(config)
- session.main(all.append)
- l = getpassed(all)
+ l = getpassed(session)
assert len(l) == 1
finally:
old.chdir()
# test that running the file directly works
config = py.test2.config._reparse([str(checkfile)])
- all = []
session = config._getsessionclass()(config)
- session.main(all.append)
- l = getpassed(all)
+ l = getpassed(session)
assert len(l) == 1
def test_order_of_execution_generator_same_codeline():
@@ -293,10 +293,8 @@
yield assert_order_of_execution
"""))
config = py.test2.config._reparse([o])
- all = []
session = config.initsession()
- session.main(all.append)
- l = getpassed(all)
+ l = getpassed(session)
assert len(l) == 7
def test_order_of_execution_generator_different_codeline():
@@ -326,10 +324,8 @@
yield assert_order_of_execution
"""))
config = py.test2.config._reparse([o])
- all = []
session = config.initsession()
- session.main(all.append)
- l = getpassed(all)
+ l = getpassed(session)
assert len(l) == 4
Modified: py/branch/event/py/test2/testing/test_repevent.py
==============================================================================
--- py/branch/event/py/test2/testing/test_repevent.py (original)
+++ py/branch/event/py/test2/testing/test_repevent.py Thu Jan 31 10:48:37 2008
@@ -3,26 +3,6 @@
import py
from py.__.test2 import repevent
-def test_wrapcall_ok():
- l = []
- def ok(x):
- return x+1
- i = repevent.wrapcall(l.append, ok, 1)
- assert i == 2
- assert len(l) == 2
- assert isinstance(l[0], repevent.CallStart)
- assert isinstance(l[1], repevent.CallFinish)
- assert repr(l[0])
- assert repr(l[1])
-
-def test_wrapcall_exception():
- l = []
- def fail(x):
- raise ValueError
- py.test2.raises(ValueError, "repevent.wrapcall(l.append, fail, 1)")
- assert len(l) == 2
- assert isinstance(l[0], repevent.CallStart)
- assert isinstance(l[1], repevent.CallException)
def test_reporter_methods_sanity():
""" Checks if all the methods of reporter are sane
Modified: py/branch/event/py/test2/testing/test_reporter.py
==============================================================================
--- py/branch/event/py/test2/testing/test_reporter.py (original)
+++ py/branch/event/py/test2/testing/test_reporter.py Thu Jan 31 10:48:37 2008
@@ -1,4 +1,3 @@
-
""" reporter tests.
XXX there are a few disabled reporting tests because
@@ -18,6 +17,9 @@
import py, os
+
+py.test.skip("rewrite reporter tests completely, take existing as hints")
+
from py.__.test2.session import AbstractSession, itemgen
from py.__.test2.reporter import RemoteReporter, LocalReporter, choose_reporter
from py.__.test2 import repevent
Modified: py/branch/event/py/test2/testing/test_session.py
==============================================================================
--- py/branch/event/py/test2/testing/test_session.py (original)
+++ py/branch/event/py/test2/testing/test_session.py Thu Jan 31 10:48:37 2008
@@ -5,6 +5,8 @@
from py.__.test2.repevent import ReceivedItemOutcome, SkippedTryiter,\
FailedTryiter
+from test_session2 import getevents_runmain
+
implied_options = {
'-v': 'verbose',
'-l': 'showlocals',
@@ -60,9 +62,8 @@
def runfiletest(opts):
config = py.test2.config._reparse(opts + [datadir/'filetest.py'])
- all = []
session = config.initsession()
- session.main(all.append)
+ all = getevents_runmain(session)
assert len(getfailed(all)) == 2
assert not getskipped(all)
@@ -75,9 +76,8 @@
def check(keyword, name):
config = py.test2.config._reparse([datadir/'filetest.py',
'-s', '-k', keyword])
- all = []
session = config._getsessionclass()(config)
- session.main(all.append)
+ all = getevents_runmain(session)
outcomes = [i for i in all if isinstance(i, ReceivedItemOutcome)]
assert len(getfailed(all)) == 1
assert outcomes[0].item.name == name
@@ -106,9 +106,8 @@
for keyword in ('xxx', 'xxx test_2', 'TestClass', 'xxx -test_1',
'TestClass test_2', 'xxx TestClass test_2',):
config = py.test2.config._reparse([o, '-s', '-k', keyword])
- all = []
session = config._getsessionclass()(config)
- session.main(all.append)
+ all = getevents_runmain(session)
print "keyword", repr(keyword)
l = getpassed(all)
outcomes = [i for i in all if isinstance(i, ReceivedItemOutcome)]
@@ -120,9 +119,8 @@
def test_select_starton(self):
config = py.test2.config._reparse([datadir/'testmore.py',
'-j', '-k', "test_two"])
- all = []
session = config._getsessionclass()(config)
- session.main(all.append)
+ all = getevents_runmain(session)
assert len(getpassed(all)) == 2
assert len(getskipped(all)) == 1
@@ -132,9 +130,8 @@
from py.__.test2.session import Session
from py.__.test2.terminal.out import getout
config = py.test2.config._reparse(list(args))
- all = []
session = Session(config)
- session.main(all.append)
+ all = getevents_runmain(session)
return session, all
def test_terminal(self):
Modified: py/branch/event/py/test2/testing/test_session2.py
==============================================================================
--- py/branch/event/py/test2/testing/test_session2.py (original)
+++ py/branch/event/py/test2/testing/test_session2.py Thu Jan 31 10:48:37 2008
@@ -8,6 +8,17 @@
import py.__.test2.custompdb
from py.__.test2.session import Session
+def getevents_runmain(session):
+ hub = session.config.hub
+ allevents = []
+ hub.append(allevents.append)
+ try:
+ session.main()
+ return allevents
+ finally:
+ hub.remove(allevents.append)
+
+
def setup_module(mod):
mod.tmp = py.test2.ensuretemp("lsession_module")
@@ -37,8 +48,7 @@
args.append('--boxed')
config = py.test2.config._reparse(args)
lsession = Session(config)
- allevents = []
- lsession.main(reporter=allevents.append)
+ allevents = getevents_runmain(lsession)
testevents = [x for x in allevents
if isinstance(x, repevent.ReceivedItemOutcome)]
assert len(testevents)
@@ -84,8 +94,7 @@
args.append('--boxed')
config = py.test2.config._reparse(args)
lsession = Session(config)
- allevents = []
- lsession.main(reporter=allevents.append)
+ allevents = getevents_runmain(lsession)
testevents = [x for x in allevents
if isinstance(x, repevent.ReceivedItemOutcome)]
assert len(testevents)
@@ -113,9 +122,8 @@
args = [str(tmpdir.join(subdir)), '--pdb']
config = py.test2.config._reparse(args)
lsession = Session(config)
- allevents = []
#try:
- lsession.main(reporter=allevents.append)
+ allevents = getevents_runmain(lsession)
#except SystemExit:
# pass
#else:
@@ -147,9 +155,7 @@
config = py.test2.config._reparse(args)
assert config.option.exitfirst
lsession = Session(config)
- allevents = []
-
- lsession.main(reporter=allevents.append)
+ allevents = getevents_runmain(lsession)
testevents = [x for x in allevents
if isinstance(x, repevent.ReceivedItemOutcome)]
assert len(testevents)
@@ -176,9 +182,8 @@
args = [str(tmpdir.join("sub3")), '-k', 'test_one']
config = py.test2.config._reparse(args)
lsession = Session(config)
- allevents = []
- lsession.main(reporter=allevents.append)
+ allevents = getevents_runmain(lsession)
testevents = [x for x in allevents
if isinstance(x, repevent.ReceivedItemOutcome)]
assert len(testevents)
@@ -204,10 +209,8 @@
args = [str(tmpdir.join("sub4"))]
config = py.test2.config._reparse(args)
lsession = Session(config)
- allevents = []
allruns = []
- lsession.main(reporter=allevents.append)
-
+ allevents = getevents_runmain(lsession)
testevents = [x for x in allevents
if isinstance(x, repevent.ReceivedItemOutcome)]
assert len(testevents) == 4
@@ -230,8 +233,7 @@
args = [str(tmpdir.join("sub5"))]
config = py.test2.config._reparse(args)
lsession = Session(config)
- allevents = []
- lsession.main(reporter=allevents.append)
+ allevents = getevents_runmain(lsession)
testevents = [x for x in allevents
if isinstance(x, repevent.ReceivedItemOutcome)]
assert len(testevents) == 0
@@ -256,8 +258,7 @@
args = [str(tmpdir.join("sub6"))]
config = py.test2.config._reparse(args)
lsession = Session(config)
- allevents = []
- lsession.main(reporter=allevents.append)
+ allevents = getevents(lsession)
testevents = [x for x in allevents
if isinstance(x, repevent.ReceivedItemOutcome)]
failevents = [i for i in testevents if i.outcome.excinfo]
@@ -277,8 +278,7 @@
args = [str(tmpdir.join("sub7"))]
config = py.test2.config._reparse(args)
lsession = Session(config)
- allevents = []
- lsession.main(reporter=allevents.append)
+ allevents = getevents_runmain(lsession.main)
testevents = [x for x in allevents
if isinstance(x, repevent.ReceivedItemOutcome)]
assert len(testevents) == 1
More information about the py-svn
mailing list