[Zope3-checkins] SVN: zope.testing/trunk/ colorization of doctest output now correctly handles blank lines

Benji York benji at zope.com
Fri May 1 08:45:39 EDT 2009


Log message for revision 99639:
  colorization of doctest output now correctly handles blank lines
  

Changed:
  U   zope.testing/trunk/CHANGES.txt
  U   zope.testing/trunk/src/zope/testing/testrunner/formatter.py
  U   zope.testing/trunk/src/zope/testing/testrunner/testrunner-colors.txt

-=-
Modified: zope.testing/trunk/CHANGES.txt
===================================================================
--- zope.testing/trunk/CHANGES.txt	2009-05-01 12:00:41 UTC (rev 99638)
+++ zope.testing/trunk/CHANGES.txt	2009-05-01 12:45:39 UTC (rev 99639)
@@ -9,7 +9,9 @@
   line number of the current example. This fixes
   https://bugs.launchpad.net/bugs/339813
 
+- Colorization of doctest output correctly handles blank lines.
 
+
 3.7.3 (2009-04-22)
 ==================
 

Modified: zope.testing/trunk/src/zope/testing/testrunner/formatter.py
===================================================================
--- zope.testing/trunk/src/zope/testing/testrunner/formatter.py	2009-05-01 12:00:41 UTC (rev 99638)
+++ zope.testing/trunk/src/zope/testing/testrunner/formatter.py	2009-05-01 12:45:39 UTC (rev 99639)
@@ -584,12 +584,15 @@
                         self.color('normal'), '\n'])
                 else:
                     print line
-            elif line.startswith('    '):
+            elif line.startswith('    ') or line.strip() == '':
                 if colorize_diff and len(line) > 4:
                     color = self.diff_color.get(line[4], color_of_indented_text)
                     print self.colorize(color, line)
                 else:
-                    print self.colorize(color_of_indented_text, line)
+                    if line.strip() != '':
+                        print self.colorize(color_of_indented_text, line)
+                    else:
+                        print line
             else:
                 colorize_diff = False
                 if line.startswith('Failed example'):

Modified: zope.testing/trunk/src/zope/testing/testrunner/testrunner-colors.txt
===================================================================
--- zope.testing/trunk/src/zope/testing/testrunner/testrunner-colors.txt	2009-05-01 12:00:41 UTC (rev 99638)
+++ zope.testing/trunk/src/zope/testing/testrunner/testrunner-colors.txt	2009-05-01 12:45:39 UTC (rev 99639)
@@ -243,7 +243,37 @@
     {normal}Tearing down left over layers:{normal}
       Tear down zope.testing.testrunner.layer.UnitTests in {green}N.NNN{normal} seconds.
 
+Even test failures that have actual blank lines (as opposed to <BLANKLINE>) in
+them are highlighted correctly.
 
+    >>> import zope.testing.testrunner.formatter
+    >>> formatter = zope.testing.testrunner.formatter.ColorfulOutputFormatter(None)
+    >>> formatter.print_doctest_failure("""\
+    ...     File "sometest.txt", line 221, in sometest.txt
+    ... Failed example:
+    ...     foo()
+    ... Expected:
+    ...     Output that contains
+    ...
+    ...     blank lines.
+    ... Got:
+    ...     Output that still contains
+    ...
+    ...     blank lines.""")
+    {normal}    File "sometest.txt", line 221, in sometest.txt{normal}
+    Failed example:
+    {cyan}    foo(){normal}
+    Expected:
+    {green}    Output that contains{normal}
+    <BLANKLINE>
+    {green}    blank lines.{normal}
+    Got:
+    {red}    Output that still contains{normal}
+    <BLANKLINE>
+    {red}    blank lines.{normal}
+    <BLANKLINE>
+
+
 Timing individual tests
 -----------------------
 



More information about the Zope3-Checkins mailing list