[py-svn] r61951 - in py/branch/pytestplugin/py/test: . dsession dsession/testing looponfail looponfail/testing testing
hpk at codespeak.net
hpk at codespeak.net
Mon Feb 16 16:13:13 CET 2009
Author: hpk
Date: Mon Feb 16 16:13:11 2009
New Revision: 61951
Modified:
py/branch/pytestplugin/py/test/dsession/dsession.py
py/branch/pytestplugin/py/test/dsession/hostmanage.py
py/branch/pytestplugin/py/test/dsession/masterslave.py
py/branch/pytestplugin/py/test/dsession/testing/test_dsession.py
py/branch/pytestplugin/py/test/dsession/testing/test_hostmanage.py
py/branch/pytestplugin/py/test/dsession/testing/test_masterslave.py
py/branch/pytestplugin/py/test/event.py
py/branch/pytestplugin/py/test/looponfail/remote.py
py/branch/pytestplugin/py/test/looponfail/testing/test_util.py
py/branch/pytestplugin/py/test/testing/test_event.py
Log:
intermediate: only notify with named events, disallow sending unnamed events.
Modified: py/branch/pytestplugin/py/test/dsession/dsession.py
==============================================================================
--- py/branch/pytestplugin/py/test/dsession/dsession.py (original)
+++ py/branch/pytestplugin/py/test/dsession/dsession.py Mon Feb 16 16:13:11 2009
@@ -43,6 +43,10 @@
self._testsfailed = False
self.trace = config.maketrace("dsession.log")
+ def queueput(self, **kw):
+ assert len(kw) == 1
+ self.queue.put(kw)
+
def fixoptions(self):
""" check, fix and determine conflicting options. """
option = self.config.option
@@ -97,12 +101,14 @@
# we use a timeout here so that control-C gets through
while 1:
try:
- ev = self.queue.get(timeout=2.0)
+ kw = self.queue.get(timeout=2.0)
break
except Queue.Empty:
continue
loopstate.dowork = True
- self.bus.notify(ev)
+ self.bus.notify(**kw)
+ assert len(kw) == 1
+ name, ev = kw.items()[0]
if isinstance(ev, event.ItemTestReport):
self.removeitem(ev.colitem)
if ev.failed:
@@ -133,9 +139,10 @@
def loop_once_shutdown(self, loopstate):
# once we are in shutdown mode we dont send
# events other than HostDown upstream
- ev = self.queue.get()
- if isinstance(ev, event.HostDown):
- self.bus.notify(ev)
+ kw = self.queue.get()
+ name, ev = kw.items()[0]
+ if name == "hostdown":
+ self.bus.notify(hostdown=ev)
self.removehost(ev.host)
if not self.host2pending:
# finished
@@ -156,7 +163,7 @@
except KeyboardInterrupt:
exitstatus = outcome.EXIT_INTERRUPTED
except:
- self.bus.notify(event.InternalException())
+ self.bus.notify(internalerror=event.InternalException())
exitstatus = outcome.EXIT_INTERNALERROR
if exitstatus == 0 and self._testsfailed:
exitstatus = outcome.EXIT_TESTSFAILED
@@ -185,8 +192,8 @@
senditems.append(next)
else:
ev = basic_collect_report(next)
- self.bus.notify(event.CollectionStart(next))
- self.queue.put(ev)
+ self.bus.notify(collectionstart=event.CollectionStart(next))
+ self.queue.put({'collectionstart': ev})
self.senditems(senditems)
def senditems(self, tosend):
@@ -203,14 +210,14 @@
# "sending same item %r to multiple hosts "
# "not implemented" %(item,))
self.item2host[item] = host
- self.bus.notify(event.ItemStart(item, host))
+ self.bus.notify(itemstart=event.ItemStart(item, host))
pending.extend(sending)
tosend[:] = tosend[room:] # update inplace
if not tosend:
break
if tosend:
# we have some left, give it to the main loop
- self.queue.put(event.RescheduleItems(tosend))
+ self.queueput(rescheduleitems = event.RescheduleItems(tosend))
def removeitem(self, item):
if item not in self.item2host:
@@ -222,12 +229,15 @@
def handle_crashitem(self, item, host):
longrepr = "!!! Host %r crashed during running of test %r" %(host, item)
rep = event.ItemTestReport(item, when="???", excinfo=longrepr)
- self.bus.notify(rep)
+ self.bus.notify(itemtestreport=rep)
def setup_hosts(self):
""" setup any neccessary resources ahead of the test run. """
self.hm = HostManager(self)
- self.hm.setup_hosts(notify=self.queue.put)
+ def kwnotify(**kw):
+ assert len(kw) == 1
+ self.queue.put(kw)
+ self.hm.setup_hosts(notify=kwnotify)
def teardown_hosts(self):
""" teardown any resources after a test run. """
Modified: py/branch/pytestplugin/py/test/dsession/hostmanage.py
==============================================================================
--- py/branch/pytestplugin/py/test/dsession/hostmanage.py (original)
+++ py/branch/pytestplugin/py/test/dsession/hostmanage.py Mon Feb 16 16:13:11 2009
@@ -148,7 +148,7 @@
def prepare_gateways(self):
for host in self.hosts:
host.initgateway()
- self.session.bus.notify(event.HostGatewayReady(host, self.roots))
+ self.session.bus.notify(hostgatewayready=event.HostGatewayReady(host, self.roots))
def init_rsync(self):
self.prepare_gateways()
@@ -164,7 +164,7 @@
for host in self.hosts:
rsync.add_target_host(host, destrelpath)
rsync.send(raises=False)
- self.session.bus.notify(event.RsyncFinished())
+ self.session.bus.notify(rsyncfinished=event.RsyncFinished())
def setup_hosts(self, notify=None):
if notify is None:
Modified: py/branch/pytestplugin/py/test/dsession/masterslave.py
==============================================================================
--- py/branch/pytestplugin/py/test/dsession/masterslave.py (original)
+++ py/branch/pytestplugin/py/test/dsession/masterslave.py Mon Feb 16 16:13:11 2009
@@ -30,19 +30,20 @@
if not self._down:
if not err:
err = "TERMINATED"
- self.notify(event.HostDown(self.host, err))
+ self.notify(hostdown=event.HostDown(self.host, err))
return
if ev is None:
self._down = True
- self.notify(event.HostDown(self.host, None))
+ self.notify(hostdown=event.HostDown(self.host, None))
return
except KeyboardInterrupt:
raise
except:
excinfo = py.code.ExceptionInfo()
print "!" * 20, excinfo
- ev = event.InternalException(excinfo)
- self.notify(ev)
+ self.notify(internalerror=event.InternalException(excinfo))
+ else:
+ self.notify(itemtestreport=ev)
def send(self, item):
assert item is not None
Modified: py/branch/pytestplugin/py/test/dsession/testing/test_dsession.py
==============================================================================
--- py/branch/pytestplugin/py/test/dsession/testing/test_dsession.py (original)
+++ py/branch/pytestplugin/py/test/dsession/testing/test_dsession.py Mon Feb 16 16:13:11 2009
@@ -69,7 +69,8 @@
""")
session = DSession(modcol._config)
session.triggertesting([modcol])
- rep = session.queue.get(block=False)
+ kw = session.queue.get(block=False)
+ name, rep = kw.items()[0]
assert isinstance(rep, event.CollectionReport)
assert len(rep.result) == 1
@@ -89,7 +90,8 @@
assert host2_sent == [item] * session.MAXITEMSPERHOST
assert session.host2pending[host1] == host1_sent
assert session.host2pending[host2] == host2_sent
- ev = session.queue.get(block=False)
+ kw = session.queue.get(block=False)
+ name, ev = kw.items()[0]
assert isinstance(ev, event.RescheduleItems)
assert ev.items == [item]
@@ -117,17 +119,17 @@
session.addhost(host1)
ev = event.RescheduleItems([item])
loopstate = LoopState([])
- session.queue.put(ev)
+ session.queueput(rescheduleitems=ev)
session.loop_once(loopstate)
# check that RescheduleEvents are not immediately
# rescheduled if there are no hosts
assert loopstate.dowork == False
- session.queue.put(event.NOP())
+ session.queueput(anonymous=event.NOP())
session.loop_once(loopstate)
- session.queue.put(event.NOP())
+ session.queueput(anonymous=event.NOP())
session.loop_once(loopstate)
assert host1.node.sent == [[item]]
- session.queue.put(run(item))
+ session.queueput(itemtestreport=run(item))
session.loop_once(loopstate)
assert loopstate.shuttingdown
assert not loopstate.testsfailed
@@ -142,7 +144,7 @@
# setup a HostDown event
ev = event.HostDown(host1, None)
- session.queue.put(ev)
+ session.queueput(hostdown=ev)
loopstate = LoopState([item])
loopstate.dowork = False
@@ -172,7 +174,7 @@
session.senditems([item1, item2])
host = session.item2host[item1]
ev = event.HostDown(host, None)
- session.queue.put(ev)
+ session.queueput(hostdown=ev)
events = [] ; session.bus.subscribe(events.append)
loopstate = LoopState([])
@@ -191,7 +193,7 @@
session = DSession(item._config)
host1 = Host("localhost")
hostup = makehostup(host1)
- session.queue.put(hostup)
+ session.queueput(hostup=hostup)
loopstate = LoopState([item])
loopstate.dowork = False
assert len(session.host2pending) == 0
@@ -204,7 +206,7 @@
ev = event.NOP()
events = [] ; session.bus.subscribe(events.append)
- session.queue.put(ev)
+ session.queueput(anonymous=ev)
session.loop_once(LoopState([]))
assert events[0] == ev
@@ -215,15 +217,15 @@
session.addhost(host1)
loopstate = LoopState([item])
- session.queue.put(event.NOP())
+ session.queueput(anonymous=event.NOP())
session.loop_once(loopstate)
assert host1.node.sent == [[item]]
ev = run(item)
- session.queue.put(ev)
+ session.queueput(itemtestreport=ev)
session.loop_once(loopstate)
assert loopstate.shuttingdown
- session.queue.put(event.HostDown(host1, None))
+ session.queueput(hostdown=event.HostDown(host1, None))
session.loop_once(loopstate)
dumpqueue(session.queue)
return session, loopstate.exitstatus
@@ -258,8 +260,8 @@
# run tests ourselves and produce reports
ev1 = run(items[0])
ev2 = run(items[1])
- session.queue.put(ev1) # a failing one
- session.queue.put(ev2)
+ session.queueput(itemtestreport=ev1) # a failing one
+ session.queueput(itemtestreport=ev2)
# now call the loop
loopstate = LoopState(items)
session.loop_once(loopstate)
@@ -275,11 +277,11 @@
loopstate.shuttingdown = True
l = []
session.bus.subscribe(l.append)
- session.queue.put(run(item))
+ session.queueput(itemtestreport=run(item))
session.loop_once(loopstate)
assert not l
ev = event.HostDown(host)
- session.queue.put(ev)
+ session.queueput(hostdown=ev)
session.loop_once(loopstate)
assert l == [ev]
@@ -320,13 +322,13 @@
host.node = MockNode()
session.addhost(host)
session.senditems([item])
- session.queue.put(run(item))
+ session.queueput(itemtestreport=run(item))
loopstate = LoopState([])
session.loop_once(loopstate)
assert host.node._shutdown is True
assert loopstate.exitstatus is None, "loop did not wait for hostdown"
assert loopstate.shuttingdown
- session.queue.put(event.HostDown(host, None))
+ session.queueput(hostdown=event.HostDown(host, None))
session.loop_once(loopstate)
assert loopstate.exitstatus == 0
@@ -347,10 +349,10 @@
session.senditems([item1])
# host2pending will become empty when the loop sees
# the report
- session.queue.put(run(item1))
+ session.queueput(itemtestreport=run(item1))
# but we have a collection pending
- session.queue.put(colreport)
+ session.queueput(collectionreport=colreport)
loopstate = LoopState([])
session.loop_once(loopstate)
Modified: py/branch/pytestplugin/py/test/dsession/testing/test_hostmanage.py
==============================================================================
--- py/branch/pytestplugin/py/test/dsession/testing/test_hostmanage.py (original)
+++ py/branch/pytestplugin/py/test/dsession/testing/test_hostmanage.py Mon Feb 16 16:13:11 2009
@@ -280,14 +280,18 @@
session = py.test.config._reparse([self.source]).initsession()
hm = HostManager(session, hosts=hosts)
queue = py.std.Queue.Queue()
- hm.setup_hosts(notify=queue.put)
+ def queueput(**kw):
+ queue.put(kw)
+ hm.setup_hosts(notify=queueput)
for host in hm.hosts:
- ev = queue.get(timeout=2.0)
+ kw = queue.get(timeout=2.0)
+ name, ev = kw.items()[0]
assert isinstance(ev, event.HostUp)
for host in hm.hosts:
host.node.shutdown()
for host in hm.hosts:
- ev = queue.get(timeout=2.0)
+ kw = queue.get(timeout=2.0)
+ name, ev = kw.items()[0]
assert isinstance(ev, event.HostDown)
def XXXtest_ssh_rsync_samehost_twice(self):
Modified: py/branch/pytestplugin/py/test/dsession/testing/test_masterslave.py
==============================================================================
--- py/branch/pytestplugin/py/test/dsession/testing/test_masterslave.py (original)
+++ py/branch/pytestplugin/py/test/dsession/testing/test_masterslave.py Mon Feb 16 16:13:11 2009
@@ -10,13 +10,15 @@
events = []
while 1:
try:
- ev = self.queue.get(timeout=timeout)
+ kw = self.queue.get(timeout=timeout)
except py.std.Queue.Empty:
print "node channel", self.node.channel
print "remoteerror", self.node.channel._getremoteerror()
print "seen events", events
raise IOError("did not see %r events" % (eventtype))
else:
+ assert len(kw) == 1
+ name, ev = kw.items()[0]
if isinstance(ev, eventtype):
return ev
events.append(ev)
@@ -28,7 +30,9 @@
self.queue = py.std.Queue.Queue()
self.host = Host("localhost")
self.host.initgateway()
- self.node = MasterNode(self.host, self.config, self.queue.put)
+ def queueput(**kw):
+ self.queue.put(kw)
+ self.node = MasterNode(self.host, self.config, queueput)
assert not self.node.channel.isclosed()
def getitem(self, source):
Modified: py/branch/pytestplugin/py/test/event.py
==============================================================================
--- py/branch/pytestplugin/py/test/event.py (original)
+++ py/branch/pytestplugin/py/test/event.py Mon Feb 16 16:13:11 2009
@@ -41,10 +41,7 @@
else:
self._bus.unsubscribe(**kw)
- def notify(self, event=None, **kw):
- if event is not None:
- kw = kw.copy()
- kw['*'] = event
+ def notify(self, **kw):
self._bus.notify(**kw)
class BaseEvent(object):
Modified: py/branch/pytestplugin/py/test/looponfail/remote.py
==============================================================================
--- py/branch/pytestplugin/py/test/looponfail/remote.py (original)
+++ py/branch/pytestplugin/py/test/looponfail/remote.py Mon Feb 16 16:13:11 2009
@@ -164,5 +164,5 @@
session.main(colitems)
session.bus.unsubscribe(recordfailures)
ev = event.LooponfailingInfo(failreports, [config.topdir])
- session.bus.notify(ev)
+ session.bus.notify(looponfailinginfo=ev)
channel.send([x.colitem._totrail() for x in failreports if x.failed])
Modified: py/branch/pytestplugin/py/test/looponfail/testing/test_util.py
==============================================================================
--- py/branch/pytestplugin/py/test/looponfail/testing/test_util.py (original)
+++ py/branch/pytestplugin/py/test/looponfail/testing/test_util.py Mon Feb 16 16:13:11 2009
@@ -66,19 +66,19 @@
def test_eventrecorder():
bus = event.EventBus()
recorder = EventRecorder(bus)
- bus.notify(event.NOP())
+ bus.notify(anonymous=event.NOP())
assert recorder.events
assert not recorder.getfailures()
rep = event.ItemTestReport(None, None)
rep.failed = True
- bus.notify(rep)
+ bus.notify(itemtestreport=rep)
failures = recorder.getfailures()
assert failures == [rep]
recorder.clear()
assert not recorder.events
assert not recorder.getfailures()
recorder.unsubscribe()
- bus.notify(rep)
+ bus.notify(itemtestreport=rep)
assert not recorder.events
assert not recorder.getfailures()
Modified: py/branch/pytestplugin/py/test/testing/test_event.py
==============================================================================
--- py/branch/pytestplugin/py/test/testing/test_event.py (original)
+++ py/branch/pytestplugin/py/test/testing/test_event.py Mon Feb 16 16:13:11 2009
@@ -9,9 +9,9 @@
bus = EventBus()
l = []
bus.subscribe(l.append)
- bus.notify(1)
- bus.notify(2)
- bus.notify(3)
+ bus.notify(x=1)
+ bus.notify(x=2)
+ bus.notify(x=3)
assert l == [1,2,3]
def test_multi_sub(self):
@@ -20,9 +20,9 @@
l2 = []
bus.subscribe(l1.append)
bus.subscribe(l2.append)
- bus.notify(1)
- bus.notify(2)
- bus.notify(3)
+ bus.notify(x=1)
+ bus.notify(x=2)
+ bus.notify(x=3)
assert l1 == [1,2,3]
assert l2 == [1,2,3]
@@ -30,9 +30,9 @@
bus = EventBus()
l = []
bus.subscribe(l.append)
- bus.notify(1)
+ bus.notify(x=1)
bus.unsubscribe(l.append)
- bus.notify(2)
+ bus.notify(x=22)
assert l == [1]
def test_event_attributes():
More information about the pytest-commit
mailing list