[py-svn] r31542 - in py/branch/distributed/py/test: . rsession rsession/testing

fijal at codespeak.net fijal at codespeak.net
Wed Aug 23 15:00:42 CEST 2006


Author: fijal
Date: Wed Aug 23 15:00:38 2006
New Revision: 31542

Added:
   py/branch/distributed/py/test/rsession/reporter.py   (contents, props changed)
Modified:
   py/branch/distributed/py/test/collect.py
   py/branch/distributed/py/test/rsession/master.py
   py/branch/distributed/py/test/rsession/rsession.py
   py/branch/distributed/py/test/rsession/testing/test_master.py
Log:
(hpk, fijal) - Added simple reporter.


Modified: py/branch/distributed/py/test/collect.py
==============================================================================
--- py/branch/distributed/py/test/collect.py	(original)
+++ py/branch/distributed/py/test/collect.py	Wed Aug 23 15:00:38 2006
@@ -153,7 +153,7 @@
         cur = self
         for name in namelist:
             next = cur.join(name)
-            assert next is not None, (cur, name)
+            assert next is not None, (cur, name, namelist)
             cur = next
         return cur
 

Modified: py/branch/distributed/py/test/rsession/master.py
==============================================================================
--- py/branch/distributed/py/test/rsession/master.py	(original)
+++ py/branch/distributed/py/test/rsession/master.py	Wed Aug 23 15:00:38 2006
@@ -2,7 +2,8 @@
 Node code for Master. 
 """
 import py
-from py.__.test.rsession.outcome import ReprOutcome 
+from py.__.test.rsession.outcome import ReprOutcome
+from py.__.test.rsession import reporter
 
 MAX_TASKS_PER_NODE = 5
 
@@ -16,12 +17,15 @@
     def receive_result(self, outcomestring):
         repr_outcome = ReprOutcome(outcomestring)
         item = self.pending.pop()
-        self.report((item, repr_outcome))
+        # send finish report
+        self.report(reporter.ReceivedItemOutcome(self.channel, item, repr_outcome))
 
     def send(self, item):
         self.pending.insert(0, item)
-        itemspec = item.listnames() 
+        itemspec = item.listnames()
         self.channel.send(itemspec)
+        # send start report
+        self.report(reporter.SendItem(self.channel, item))
 
 def dispatch_loop(masternodes, itemgenerator, shouldstop, 
                   waiter = lambda: py.std.time.sleep(0.1), 

Added: py/branch/distributed/py/test/rsession/reporter.py
==============================================================================
--- (empty file)
+++ py/branch/distributed/py/test/rsession/reporter.py	Wed Aug 23 15:00:38 2006
@@ -0,0 +1,38 @@
+
+""" Reporter classes for showing asynchronous and synchronous status events
+"""
+
+import py
+
+def basic_report(msg_type, message):
+    print msg_type, message
+
+#def report(msg_type, message):
+#    pass
+
+def report_error(excinfo):
+    if isinstance(excinfo, py.test.Item.Skipped):
+        # we need to dispatch this info
+        report("skipped", excinfo)
+    else:
+        report("itererror", excinfo)
+
+class ReportEvent(object):
+    def __repr__(self):
+        l = ["%s=%s" %(key, value)
+           for key, value in self.__dict__.items()]
+        return "<%s %s>" %(self.__class__.__name__, " ".join(l),)
+
+class SendItem(ReportEvent):
+    def __init__(self, channel, item):
+        self.item = item
+        self.channel = channel
+
+class ReceivedItemOutcome(ReportEvent):
+    def __init__(self, channel, item, outcome):
+        self.channel = channel
+        self.item = item
+        self.outcome = outcome
+
+# tryiter, main dispatch loop, something else (setup-teardown stuff)
+# 

Modified: py/branch/distributed/py/test/rsession/rsession.py
==============================================================================
--- py/branch/distributed/py/test/rsession/rsession.py	(original)
+++ py/branch/distributed/py/test/rsession/rsession.py	Wed Aug 23 15:00:38 2006
@@ -1,4 +1,5 @@
 import py
+import threading
 
 class Reporter(object):
     def __init__(self, config):
@@ -15,18 +16,8 @@
     def report(self, *whatever):
         print whatever
     
-    def main(self, args):
-        """ main loop for running tests. """
-        import thread, threading
-        from py.__.test.terminal.remote import getrootdir
-        from py.__.test.rsession.master import (
-            setup_slave, bin_rsync, MasterNode, dispatch_loop)
-        colitems = self._map2colitems(args) 
-        sshhosts = self.config.getinitialvalue("disthosts")
-        relpath = "pytestcache"
-        rootdir = getrootdir(args)
+    def init_hosts(self, sshhosts, relpath):
         nodes = []
-        import threading
         nodes_lock = threading.Condition()
 
         def host_init(host):
@@ -49,6 +40,21 @@
                 nodes_lock.wait(1)
             finally:
                 nodes_lock.release()
+            
+        return nodes
+
+    
+    def main(self, args):
+        """ main loop for running tests. """
+        import thread, threading
+        from py.__.test.terminal.remote import getrootdir
+        from py.__.test.rsession.master import (
+            setup_slave, bin_rsync, MasterNode, dispatch_loop)
+        colitems = self._map2colitems(args) 
+        sshhosts = self.config.getinitialvalue("disthosts")
+        relpath = "pytestcache"
+        rootdir = getrootdir(args)
+        nodes = self.init_hosts(sshhosts, relpath)
 
         itemgenerator = colitems[0].tryiter()
         dispatch_loop(nodes, itemgenerator, lambda : False)

Modified: py/branch/distributed/py/test/rsession/testing/test_master.py
==============================================================================
--- py/branch/distributed/py/test/rsession/testing/test_master.py	(original)
+++ py/branch/distributed/py/test/rsession/testing/test_master.py	Wed Aug 23 15:00:38 2006
@@ -8,6 +8,7 @@
 from py.__.test.rsession.master import dispatch_loop, setup_slave, MasterNode
 from py.__.test.rsession.outcome import ReprOutcome, Outcome 
 from py.__.test.rsession.testing.test_slave import funcpass_spec, funcfail_spec
+from py.__.test.rsession import reporter
 
 def setup_module(mod):
     mod.rootdir = py.path.local(py.__file__).dirpath().dirpath()
@@ -31,9 +32,11 @@
     mnode.send(py.test.Item("notok"))
     ch.callback(Outcome().make_repr())
     ch.callback(Outcome(excinfo=42).make_repr())
-    assert len(reportlist) == 2
-    assert reportlist[0][1].passed 
-    assert not reportlist[1][1].passed 
+    assert len(reportlist) == 4
+    received = [i for i in reportlist 
+        if isinstance(i, reporter.ReceivedItemOutcome)]
+    assert received[0].outcome.passed 
+    assert not received[1].outcome.passed 
 
 def test_outcome_repr():
     out = ReprOutcome(Outcome(skipped=True).make_repr())
@@ -67,12 +70,14 @@
     gw.exit()
 
 def test_slave_running():
-    def simple_reporter(result):
-        item, res = result
+    def simple_reporter(event):
+        if not isinstance(event, reporter.ReceivedItemOutcome):
+            return
+        item = event.item
         if item.code.name == 'funcpass':
-            assert res.passed
+            assert event.outcome.passed
         else:
-            assert not res.passed
+            assert not event.outcome.passed
     
     def open_gw():
         gw = py.execnet.PopenGateway()



More information about the pytest-commit mailing list