[py-svn] r34713 - in py/dist/py/test/rsession: . testing

fijal at codespeak.net fijal at codespeak.net
Fri Nov 17 16:49:22 CET 2006


Author: fijal
Date: Fri Nov 17 16:49:19 2006
New Revision: 34713

Added:
   py/dist/py/test/rsession/rest.py   (contents, props changed)
   py/dist/py/test/rsession/testing/test_rest.py   (contents, props changed)
Modified:
   py/dist/py/test/rsession/reporter.py
   py/dist/py/test/rsession/rsession.py
   py/dist/py/test/rsession/testing/test_reporter.py
Log:
Added basics od rest backend.


Modified: py/dist/py/test/rsession/reporter.py
==============================================================================
--- py/dist/py/test/rsession/reporter.py	(original)
+++ py/dist/py/test/rsession/reporter.py	Fri Nov 17 16:49:19 2006
@@ -28,6 +28,12 @@
         #self.count = 0
         #self.lgt = 1000
 
+    def get_host(self, item):
+        if item.channel:
+            return item.channel.gateway.sshaddress
+        # XXX: Testing purposes only
+        return 'localhost'
+
     def report(self, what):
         repfun = getattr(self, "report_" + what.__class__.__name__, 
                          self.report_unknown)
@@ -194,6 +200,9 @@
         total = total_passed + total_failed + total_skipped
         skipped_str = create_str("skipped", total_skipped)
         failed_str = create_str("failed", total_failed)
+        self.print_summary(total, skipped_str, failed_str)
+    
+    def print_summary(self, total, skipped_str, failed_str):
         self.out.sep("=", " %d test run%s%s in %.2fs (rsync: %.2f)" % 
             (total, skipped_str, failed_str, self.timeend - self.timestart,
              self.timersync - self.timestart))
@@ -230,13 +239,7 @@
     def report_Nodes(self, event):
         self.nodes = event.nodes
 
-class RemoteReporter(AbstractReporter):
-    def get_host(self, item):
-        if item.channel:
-            return item.channel.gateway.sshaddress
-        # XXX: Testing purposes only
-        return 'localhost'
-    
+class RemoteReporter(AbstractReporter):    
     def get_item_name(self, event, colitem):
         return self.get_host(event) + ":" + \
             "/".join(colitem.listnames())
@@ -250,9 +253,6 @@
             join(event.item.listnames())))
 
 class LocalReporter(AbstractReporter):
-    def get_host(self, item):
-        return 'localhost'
-    
     def get_item_name(self, event, colitem):
         return "/".join(colitem.listnames())
     

Added: py/dist/py/test/rsession/rest.py
==============================================================================
--- (empty file)
+++ py/dist/py/test/rsession/rest.py	Fri Nov 17 16:49:19 2006
@@ -0,0 +1,52 @@
+
+""" Rest reporting stuff
+"""
+
+import py
+import sys
+from py.__.test.rsession.reporter import AbstractReporter
+from py.__.rest.rst import *
+
+class RestReporter(AbstractReporter):
+    def report_unknown(self, what):
+        print "Unknown report: %s" % what
+
+    def report_TestStarted(self, event):
+        txt = "Test started, hosts: %s" % ", ".join(event.hosts)
+        print Title(txt, abovechar='=', belowchar='=').text() + "\n"
+        self.timestart = event.timestart
+
+    def report_ItemStart(self, event):
+        item = event.item
+        print
+        if isinstance(item, py.test.collect.Module):
+            lgt = len(list(item.tryiter()))
+            name = "/".join(item.listnames())
+            txt = 'Testing module %s (%d items)' % (name, lgt)
+            print Title(txt, belowchar='-').text()
+
+    def print_summary(self, total, skipped_str, failed_str):
+        print "\n"
+        txt = "%d test run%s%s in %.2fs (rsync: %.2f)" % \
+            (total, skipped_str, failed_str, self.timeend - self.timestart,
+             self.timersync - self.timestart)
+        print Title(txt, belowchar="=").text()
+    
+    def report_ReceivedItemOutcome(self, event):
+        host = self.get_host(event)
+        if event.outcome.passed:
+            status = "PASSED"
+            self.passed[host] += 1
+        elif event.outcome.skipped:
+            status = "SKIPPED"
+            self.skipped_tests_outcome.append(event)
+            self.skipped[host] += 1
+        else:
+            status = "FAILED"
+            self.failed[host] += 1
+            self.failed_tests_outcome.append(event)
+            # we'll take care of them later
+        sshhost = self.get_host(event)
+        itempath = " ".join(event.item.listnames()[1:])
+        print ListItem(Text("%10s: %s %s" %(sshhost[:10], status, itempath))).text()
+    

Modified: py/dist/py/test/rsession/rsession.py
==============================================================================
--- py/dist/py/test/rsession/rsession.py	(original)
+++ py/dist/py/test/rsession/rsession.py	Fri Nov 17 16:49:19 2006
@@ -112,12 +112,8 @@
     getpkgdir = staticmethod(getpkgdir)
 
     def init_reporter(self, reporter, sshhosts, reporter_class, arg=""):
-        #try:
-        #    # XXX: use it like a command line option, but how?
-        #    startserverflag = self.config.getinitialvalue("startserver")
-        #except:
-        #    startserverflag = False
         startserverflag = self.config.option.startserver
+        restflag = self.config.option.restreport
         
         checkfun = lambda: None
         if startserverflag and reporter is None:
@@ -129,6 +125,9 @@
                 import webbrowser
                 webbrowser.open("localhost:8000")
         elif reporter is None: 
+            if restflag:
+                from py.__.test.rsession.rest import RestReporter
+                reporter_class = RestReporter
             if arg:
                 reporter_instance = reporter_class(self.config, sshhosts, self.getpkgdir(arg))
             else:

Modified: py/dist/py/test/rsession/testing/test_reporter.py
==============================================================================
--- py/dist/py/test/rsession/testing/test_reporter.py	(original)
+++ py/dist/py/test/rsession/testing/test_reporter.py	Fri Nov 17 16:49:19 2006
@@ -14,10 +14,10 @@
 import sys
 from StringIO import StringIO
 
-def setup_module(mod):
-    mod.pkgdir = py.path.local(py.__file__).dirpath()
-
 class AbstractTestReporter(object):
+    def setup_class(cls):
+        cls.pkgdir = py.path.local(py.__file__).dirpath()
+    
     def prepare_outcomes(self):
         # possible outcomes
         try:
@@ -39,7 +39,7 @@
     def report_received_item_outcome(self):
         config, args = py.test.Config.parse(["some_sub"])
         # we just go...
-        rootcol = py.test.collect.Directory(pkgdir.dirpath())
+        rootcol = py.test.collect.Directory(self.pkgdir.dirpath())
         item = rootcol.getitembynames(funcpass_spec)
         outcomes = self.prepare_outcomes()
         
@@ -59,7 +59,7 @@
     def _test_module(self):
         config, args = py.test.Config.parse(["some_sub"])
         # we just go...
-        rootcol = py.test.collect.Directory(pkgdir.dirpath())
+        rootcol = py.test.collect.Directory(self.pkgdir.dirpath())
         funcitem = rootcol.getitembynames(funcpass_spec)
         moditem = rootcol.getitembynames(mod_spec)
         outcomes = self.prepare_outcomes()
@@ -74,7 +74,7 @@
         s = StringIO()
         stdoutcopy = sys.stdout
         sys.stdout = s
-        boxfun(pkgdir, config, moditem, funcitem, outcomes)
+        boxfun(self.pkgdir, config, moditem, funcitem, outcomes)
         sys.stdout = stdoutcopy
         
         return s.getvalue()

Added: py/dist/py/test/rsession/testing/test_rest.py
==============================================================================
--- (empty file)
+++ py/dist/py/test/rsession/testing/test_rest.py	Fri Nov 17 16:49:19 2006
@@ -0,0 +1,22 @@
+
+""" tests of rest reporter backend
+"""
+
+import py
+from py.__.test.rsession.testing.test_reporter import AbstractTestReporter
+from py.__.test.rsession.rest import RestReporter
+
+class TestRestReporter(AbstractTestReporter):
+    reporter = RestReporter
+
+    def test_failed_to_load(self):
+        py.test.skip("Not implemented")
+    
+    def test_report_received_item_outcome(self):
+        val = self.report_received_item_outcome()
+        expected = """- localhost\\: FAILED py test rsession testing test\\_slave.py funcpass
+- localhost\\: SKIPPED py test rsession testing test\\_slave.py funcpass
+- localhost\\: FAILED py test rsession testing test\\_slave.py funcpass
+- localhost\\: PASSED py test rsession testing test\\_slave.py funcpass
+"""
+        assert val == expected



More information about the pytest-commit mailing list