[py-svn] r57063 - in py/branch/event/py/test2/rep: . testing

hpk at codespeak.net hpk at codespeak.net
Thu Aug 7 17:09:22 CEST 2008


Author: hpk
Date: Thu Aug  7 17:09:15 2008
New Revision: 57063

Modified:
   py/branch/event/py/test2/rep/terminal.py
   py/branch/event/py/test2/rep/testing/test_terminal.py
Log:
report more events, small refactoring


Modified: py/branch/event/py/test2/rep/terminal.py
==============================================================================
--- py/branch/event/py/test2/rep/terminal.py	(original)
+++ py/branch/event/py/test2/rep/terminal.py	Thu Aug  7 17:09:15 2008
@@ -14,17 +14,42 @@
         self.curdir = py.path.local()
         if file is None:
             file = py.std.sys.stdout
-        self.out = py.io.TerminalWriter(file)
+        self._tw = py.io.TerminalWriter(file)
+
+    def write_fspath_result(self, fspath, res):
+        if fspath != self.currentfspath:
+            self._tw.line()
+            relpath = getrelpath(self.curdir, fspath)
+            self._tw.write(relpath + " ")
+            self.currentfspath = fspath
+        self._tw.write(res)
+
+    def write_line(self, line):
+        if self.currentfspath:
+            self._tw.line()
+            self.currentfspath = None
+        self._tw.line(line)
+
+    def rep_InternalException(self, ev):
+        for line in str(ev.excinfo.getrepr()).split("\n"):
+            self.write_line("InternalException: " + line)
+
+    def rep_HostGatewayReady(self, ev):
+        self.write_line("HostReady: %s" %(ev.host,))
+
+    def rep_HostCrashed(self, ev):
+        host = ev.host
+        error = ev.error
+        if not error:
+            error = "TERMINATED unexpectedly"
+        self.write_line("HostCrashed %s: pending=%r" %(host.hostid, ev.pending))
+        for line in str(error).split("\n"):
+            self.write_line("HostCrashed %s: %s" %(host.hostid, line))
     
     def rep_ItemTestReport(self, ev):
         super(TerminalReporter, self).rep_ItemTestReport(ev)
         fspath = ev.colitem.fspath 
-        if fspath != self.currentfspath:
-            relpath = getrelpath(self.curdir, fspath)
-            self.out.line()
-            self.out.write(relpath + " ")
-            self.currentfspath = fspath
-        self.out.write(ev.outcome.shortrepr)
+        self.write_fspath_result(fspath, ev.outcome.shortrepr)
 
     def rep_CollectionReport(self, ev):
         super(TerminalReporter, self).rep_CollectionReport(ev)
@@ -34,18 +59,15 @@
                 msg = ev.outcome.longrepr.message
             else:
                 msg = ev.outcome.longrepr.reprcrash.message
-            self.out.line()
-            relpath = getrelpath(self.curdir, fspath)
-            self.out.write(relpath + " - " + str(msg))
-            self.currentfspath = fspath
+            self.write_fspath_result(fspath, "- " + str(msg))
 
     def rep_SessionStart(self, ev):
-        self.out.sep("=", "test session starts", bold=True)
+        self._tw.sep("=", "test session starts", bold=True)
         self._sessionstarttime = py.std.time.time()
         self.out_hostinfo()
 
     def rep_SessionFinish(self, ev):
-        self.out.line("")
+        self._tw.line("")
         self.summary_failures()
         self.summary_skips()
         self.summary_stats()
@@ -57,10 +79,10 @@
 
     def summary_failures(self):
         if self._failed:
-            self.out.sep("=", "FAILURES")
+            self._tw.sep("=", "FAILURES")
             for ev in self._failed:
-                self.out.sep("_")
-                ev.toterminal(self.out)
+                self._tw.sep("_")
+                ev.toterminal(self._tw)
 
     def summary_stats(self):
         session_duration = py.std.time.time() - self._sessionstarttime
@@ -68,27 +90,27 @@
         numskipped = len(self._skipped)
         numpassed = len(self._passed)
         sum = numfailed + numpassed
-        self.out.line()
-        self.out.sep("=", "%d/%d passed + %d skips in %.2f seconds" %
+        self._tw.line()
+        self._tw.sep("=", "%d/%d passed + %d skips in %.2f seconds" %
                       (numpassed, sum, numskipped, session_duration), bold=True)
         if numfailed == 0:
-            self.out.sep("=", "failures: no failures :)", green=True)
+            self._tw.sep("=", "failures: no failures :)", green=True)
         else:
-            self.out.sep("=", "failures: %d" %(numfailed), red=True)
-        self.out.line()
+            self._tw.sep("=", "failures: %d" %(numfailed), red=True)
+        self._tw.line()
 
     def summary_skips(self):
         if not self._failed or self.config.option.showskipsummary:
             folded_skips = self._folded_skips()
             if folded_skips:
-                self.out.sep("_", "skipped test summary")
+                self._tw.sep("_", "skipped test summary")
                 for num, fspath, lineno, reason in folded_skips:
-                    self.out.line("%s:%d: [%d] %s" %(fspath, lineno, num, reason))
+                    self._tw.line("%s:%d: [%d] %s" %(fspath, lineno, num, reason))
 
     def out_hostinfo(self):
-        self.out.line("host 0: %s %s - Python %s" %
-                      (py.std.sys.platform, 
-                       py.std.sys.executable, 
-                       repr_pythonversion()))
+        self._tw.line("host 0: %s %s - Python %s" %
+                       (py.std.sys.platform, 
+                        py.std.sys.executable, 
+                        repr_pythonversion()))
 
 Reporter = TerminalReporter 

Modified: py/branch/event/py/test2/rep/testing/test_terminal.py
==============================================================================
--- py/branch/event/py/test2/rep/testing/test_terminal.py	(original)
+++ py/branch/event/py/test2/rep/testing/test_terminal.py	Thu Aug  7 17:09:15 2008
@@ -4,6 +4,7 @@
 #from py.__.test2.testing import suptest
 from py.__.test2.runner import basic_run_report
 from test_collectonly import InlineCollect, popvalue, assert_stringio_contains_lines
+from py.__.test2.rsession.hostmanage import Host
 
 class TestTerminal(InlineCollect):
     def test_session_reporter_subscription(self):
@@ -59,3 +60,39 @@
             ">   import xyz",
             "E   ImportError: No module named xyz"
         ])
+
+    def test_internal_exception(self):
+        modcol = self.getmodulecol([], "def test_one(): pass")
+        stringio = py.std.cStringIO.StringIO()
+        rep = TerminalReporter(modcol._config, file=stringio)
+        excinfo = py.test2.raises(ValueError, "raise ValueError('hello')")
+        rep.processevent(repevent.InternalException(excinfo))
+        s = popvalue(stringio)
+        assert s.find("InternalException:") != -1 
+
+    def test_hostready_crash(self):
+        modcol = self.getmodulecol([], """
+            def test_one():
+                pass
+        """)
+        stringio = py.std.cStringIO.StringIO()
+        host1 = Host("localhost")
+        rep = TerminalReporter(modcol._config, file=stringio)
+        rep.processevent(repevent.HostGatewayReady(host1, None))
+        s = popvalue(stringio)
+        assert s.find("HostReady") != -1
+        rep.processevent(repevent.HostCrashed(host1, [], "myerror"))
+        s = popvalue(stringio)
+        assert s.find("HostCrashed") != -1
+        assert s.find("myerror") != -1
+
+    def test_writeline(self):
+        modcol = self.getmodulecol([], "def test_one(): pass")
+        stringio = py.std.cStringIO.StringIO()
+        rep = TerminalReporter(modcol._config, file=stringio)
+        rep.write_fspath_result(py.path.local("xy.py"), '.')
+        rep.write_line("hello world")
+        lines = popvalue(stringio).split('\n')
+        assert not lines[0]
+        assert lines[1].endswith("xy.py .")
+        assert lines[2] == "hello world"



More information about the pytest-commit mailing list