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

fijal at codespeak.net fijal at codespeak.net
Thu Nov 9 17:24:40 CET 2006


Author: fijal
Date: Thu Nov  9 17:24:38 2006
New Revision: 34424

Modified:
   py/dist/py/test/rsession/reporter.py
   py/dist/py/test/rsession/testing/test_reporter.py
Log:
Reporter tests refactoring. Now FailedTryiter works for both reporters (and is tested)


Modified: py/dist/py/test/rsession/reporter.py
==============================================================================
--- py/dist/py/test/rsession/reporter.py	(original)
+++ py/dist/py/test/rsession/reporter.py	Thu Nov  9 17:24:38 2006
@@ -11,6 +11,7 @@
 
 from py.__.test.terminal.out import getout
 from py.__.test.rsession import report
+from py.__.test.rsession import outcome
 
 class AbstractReporter(object):
     def __init__(self, config, hosts, pkgdir=py.path.local(py.__file__)):
@@ -75,7 +76,8 @@
         self.timeend = item.timeend
         self.skips()
         self.failures()
-        self.hangs()
+        if hasattr(self, 'nodes'): # XXX: Testing
+            self.hangs()
         self.summary()
     
     def hangs(self):
@@ -91,13 +93,18 @@
         if self.failed_tests_outcome:
             self.out.sep("=", " FAILURES ")
         for event in self.failed_tests_outcome:
-            host = self.get_host(event)
-            self.out.sep('_', "%s on %s" % 
-                (" ".join(event.item.listnames()), host))
-            if event.outcome.signal:
-                self.repr_signal(event.item, event.outcome)
+            if isinstance(event, report.ReceivedItemOutcome):
+                host = self.get_host(event)
+                self.out.sep('_', "%s on %s" % 
+                    (" ".join(event.item.listnames()), host))
+                if event.outcome.signal:
+                    self.repr_signal(event.item, event.outcome)
+                else:
+                    self.repr_failure(event.item, event.outcome)
             else:
-                self.repr_failure(event.item, event.outcome)
+                self.out.sep('_', " ".join(event.item.listnames()))
+                out = outcome.Outcome(excinfo=event.excinfo)
+                self.repr_failure(event.item, outcome.ReprOutcome(out.make_repr()))
     
     def repr_failure(self, item, outcome): 
         excinfo = outcome.excinfo
@@ -221,14 +228,18 @@
 
 class RemoteReporter(AbstractReporter):
     def get_host(self, item):
-        return item.channel.gateway.sshaddress
+        if item.channel:
+            return item.channel.gateway.sshaddress
+        # XXX: Testing purposes only
+        return 'localhost'
     
     def get_item_name(self, event, colitem):
-        return event.channel.gateway.sshaddress + ":" + \
+        return self.get_host(event) + ":" + \
             "/".join(colitem.listnames())
-                
+        
     def report_FailedTryiter(self, event):
         self.out.line("FAILED TO LOAD MODULE: %s\n" % "/".join(event.item.listnames()))
+        self.failed_tests_outcome.append(event)
     
     def report_SkippedTryiter(self, event):
         self.out.line("Skipped (%s) %s\n" % (str(event.excinfo.value), "/".
@@ -248,6 +259,7 @@
     def report_FailedTryiter(self, event):
         #self.show_item(event.item, False)
         self.out.write("- FAILED TO LOAD MODULE")
+        self.failed_tests_outcome.append(event)
     
     def report_ReceivedItemOutcome(self, event):
         if event.outcome.passed:

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	Thu Nov  9 17:24:38 2006
@@ -4,8 +4,9 @@
 """
 
 import py, os
-from py.__.test.rsession.rsession import LocalReporter, AbstractSession
-from py.__.test.rsession.report import ReceivedItemOutcome, ItemStart
+from py.__.test.rsession.rsession import LocalReporter, AbstractSession,\
+    RemoteReporter
+from py.__.test.rsession import report
 from py.__.test.rsession.outcome import ReprOutcome, Outcome
 from py.__.test.rsession.testing.test_slave import funcpass_spec, mod_spec
 from py.__.test.rsession.box import Box
@@ -16,7 +17,7 @@
 def setup_module(mod):
     mod.pkgdir = py.path.local(py.__file__).dirpath()
 
-class TestReporter(object):
+class AbstractTestReporter(object):
     def prepare_outcomes(self):
         # possible outcomes
         try:
@@ -35,7 +36,7 @@
         
         return outcomes
     
-    def test_report_received_item_outcome(self):
+    def report_received_item_outcome(self):
         config, args = py.test.Config.parse(["some_sub"])
         # we just go...
         rootcol = py.test.collect.Directory(pkgdir.dirpath())
@@ -43,19 +44,19 @@
         outcomes = self.prepare_outcomes()
         
         def boxfun(config, item, outcomes):
-            r = LocalReporter(config, ["localhost"])
+            r = self.reporter(config, ["localhost"])
             for outcome in outcomes:
-                r.report(ReceivedItemOutcome(None, item, outcome))
+                r.report(report.ReceivedItemOutcome(None, item, outcome))
         
         s = StringIO()
         stdoutcopy = sys.stdout
         sys.stdout = s
         boxfun(config, item, outcomes)
-        sys.stdoud = stdoutcopy
+        sys.stdout = stdoutcopy
         
-        assert s.getvalue() == 'FsF.'
+        return s.getvalue()
 
-    def test_module(self):
+    def _test_module(self):
         config, args = py.test.Config.parse(["some_sub"])
         # we just go...
         rootcol = py.test.collect.Directory(pkgdir.dirpath())
@@ -64,22 +65,22 @@
         outcomes = self.prepare_outcomes()
         
         def boxfun(pkgdir, config, item, funcitem, outcomes):
-            r = LocalReporter(config, ["localhost"])
+            r = self.reporter(config, ["localhost"])
             #r.pkgdir = pkdgir
-            r.report(ItemStart(item))
+            r.report(report.ItemStart(item))
             for outcome in outcomes:
-                r.report(ReceivedItemOutcome(None, funcitem, outcome))
+                r.report(report.ReceivedItemOutcome(None, funcitem, outcome))
         
         s = StringIO()
         stdoutcopy = sys.stdout
         sys.stdout = s
         boxfun(pkgdir, config, moditem, funcitem, outcomes)
-        sys.stdoud = stdoutcopy
+        sys.stdout = stdoutcopy
+        
+        return s.getvalue()
         
-        assert s.getvalue().endswith("test_slave.py[8] FsF."),\
-            s.getvalue()
 
-    def test_full_module(self):
+    def _test_full_module(self):
         tmpdir = py.test.ensuretemp("repmod")
         tmpdir.ensure("__init__.py")
         tmpdir.ensure("test_one.py").write(py.code.Source("""
@@ -97,7 +98,7 @@
         def boxfun():
             config, args = py.test.Config.parse([str(tmpdir)])
             rootcol = py.test.collect.Directory(tmpdir)
-            r = LocalReporter(config, ["localhost"])
+            r = self.reporter(config, ["localhost"])
             list(rootcol.tryiter(reporterror=lambda x : AbstractSession.reporterror(r.report, x)))
         
         #b = Box(boxfun)
@@ -106,9 +107,71 @@
         stdoutcopy = sys.stdout
         sys.stdout = s
         boxfun()
-        sys.stdoud = stdoutcopy
+        sys.stdout = stdoutcopy
         
-        assert s.getvalue() == """
+        return s.getvalue()
+
+    def test_failed_to_load(self):
+        tmpdir = py.test.ensuretemp("failedtoload")
+        tmpdir.ensure("__init__.py")
+        tmpdir.ensure("test_three.py").write(py.code.Source("""
+        sadsadsa
+        """))
+        def boxfun():
+            config, args = py.test.Config.parse([str(tmpdir)])
+            rootcol = py.test.collect.Directory(tmpdir)
+            r = self.reporter(config, ["localhost"])
+            r.report(report.TestStarted(['localhost']))
+            r.report(report.RsyncFinished())
+            list(rootcol.tryiter(reporterror=lambda x : AbstractSession.reporterror(r.report, x)))
+            r.report(report.TestFinished())
+        
+        s = StringIO()
+        stdoutcopy = sys.stdout
+        sys.stdout = s
+        boxfun()
+        sys.stdout = stdoutcopy
+        assert s.getvalue().find("NameError: name 'sadsadsa' is not defined") != -1
+
+class TestLocalReporter(AbstractTestReporter):
+    reporter = LocalReporter
+    
+    def test_report_received_item_outcome(self):
+        assert self.report_received_item_outcome() == 'FsF.'
+
+    def test_module(self):
+        assert self._test_module().endswith("test_slave.py[8] FsF."),\
+            self._test_module()
+    
+    def test_full_module(self):
+        assert self._test_full_module() == """
 repmod/test_one.py[1] 
 repmod/test_three.py[0] - FAILED TO LOAD MODULE
 repmod/test_two.py[0] - skipped (reason)"""
+
+class TestRemoteReporter(AbstractTestReporter):
+    reporter = RemoteReporter
+
+    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
+    
+    def test_module(self):
+        val = self._test_module()
+        print val
+        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
+    
+    def test_full_module(self):
+        val = self._test_full_module()
+        assert val == 'FAILED TO LOAD MODULE: repmod/test_three.py\n'\
+        '\nSkipped (reason) repmod/test_two.py\n\n'



More information about the pytest-commit mailing list