[Zope3-checkins] SVN: zope.testing/branches/colorized-output/src/zope/testing/testrunner.py Start colorizing error output: currently doctests failures without diffs only.

Marius Gedminas marius at pov.lt
Fri Jul 13 11:49:07 EDT 2007


Log message for revision 77871:
  Start colorizing error output: currently doctests failures without diffs only.
  
  

Changed:
  U   zope.testing/branches/colorized-output/src/zope/testing/testrunner.py

-=-
Modified: zope.testing/branches/colorized-output/src/zope/testing/testrunner.py
===================================================================
--- zope.testing/branches/colorized-output/src/zope/testing/testrunner.py	2007-07-13 15:30:23 UTC (rev 77870)
+++ zope.testing/branches/colorized-output/src/zope/testing/testrunner.py	2007-07-13 15:49:07 UTC (rev 77871)
@@ -527,7 +527,10 @@
         """Report an error with a traceback."""
         print
         print msg
+        print self.format_traceback(exc_info)
 
+    def format_traceback(self, exc_info):
+        """Format the traceback."""
         v = exc_info[1]
         if isinstance(v, doctest.DocTestFailureException):
             tb = v.args[0]
@@ -542,9 +545,8 @@
                 )
         else:
             tb = "".join(traceback.format_exception(*exc_info))
+        return tb
 
-        print tb
-
     def stop_test(self, test):
         """Clean up the output state after a test."""
         if self.progress:
@@ -573,10 +575,14 @@
     colorscheme = {'normal': 'normal',
                    'default': 'default',
                    'info': 'normal',
-                   'error': 'red',
+                   'error': 'brightred',
                    'number': 'green',
                    'ok-number': 'green',
-                   'error-number': 'brightred',}
+                   'error-number': 'brightred',
+                   'filename': 'lightblue',
+                   'failed-example': 'cyan',
+                   'expected-output': 'green',
+                   'actual-output': 'red',}
 
     prefixes = [('dark', '0;'),
                 ('light', '1;'),
@@ -661,7 +667,42 @@
             self.color('info'), ' errors',
             self.color('normal'), '\n'])
 
+    def print_traceback(self, msg, exc_info):
+        """Report an error with a traceback."""
+        print
+        print self.colorize('error', msg)
+        v = exc_info[1]
+        if isinstance(v, doctest.DocTestFailureException):
+            self.print_doctest_failure(v.args[0])
+        else:
+            tb = self.format_traceback(exc_info)
+            print self.colorize_traceback(tb)
 
+    def colorize_traceback(self, tb):
+        return tb # XXX
+
+    def print_doctest_failure(self, formatted_failure):
+        """Report a doctest failure.
+
+        ``formatted_failure`` is a string -- that's what
+        DocTestSuite/DocFileSute
+        """
+        color_of_indented_text = 'normal'
+        for line in formatted_failure.splitlines():
+            if line.startswith('File '):
+                print self.colorize('filename', line)
+            elif line.startswith('  '):
+                print self.colorize(color_of_indented_text, line)
+            else:
+                if line.startswith('Failed example'):
+                    color_of_indented_text = 'failed-example'
+                elif line.startswith('Expected:'):
+                    color_of_indented_text = 'expected-output'
+                elif line.startswith('Got:'):
+                    color_of_indented_text = 'actual-output'
+                print line
+
+
 def run(defaults=None, args=None):
     if args is None:
         args = sys.argv



More information about the Zope3-Checkins mailing list