[Zope3-checkins] SVN: Zope3/trunk/src/zope/exceptions/ Cosmetic bugfix for the exception formatter: it used to double the newlines

Marius Gedminas marius at pov.lt
Wed May 31 13:36:17 EDT 2006


Log message for revision 68413:
  Cosmetic bugfix for the exception formatter: it used to double the newlines
  in exception messages (e.g. SyntaxError exceptions).
  
  Could this tiny little change be snuck into the upcoming 3.3 release?  Pretty
  pretty please with sugar on top?
  
  

Changed:
  U   Zope3/trunk/src/zope/exceptions/exceptionformatter.py
  U   Zope3/trunk/src/zope/exceptions/tests/test_exceptionformatter.py

-=-
Modified: Zope3/trunk/src/zope/exceptions/exceptionformatter.py
===================================================================
--- Zope3/trunk/src/zope/exceptions/exceptionformatter.py	2006-05-31 16:58:12 UTC (rev 68412)
+++ Zope3/trunk/src/zope/exceptions/exceptionformatter.py	2006-05-31 17:36:17 UTC (rev 68413)
@@ -158,8 +158,8 @@
         return self.line_sep.join(result)
 
     def formatExceptionOnly(self, etype, value):
-        return self.line_sep.join(
-            traceback.format_exception_only(etype, value))
+        result = ''.join(traceback.format_exception_only(etype, value))
+        return result.replace('\n', self.line_sep)
 
     def formatLastLine(self, exc_line):
         return self.escape(exc_line)

Modified: Zope3/trunk/src/zope/exceptions/tests/test_exceptionformatter.py
===================================================================
--- Zope3/trunk/src/zope/exceptions/tests/test_exceptionformatter.py	2006-05-31 16:58:12 UTC (rev 68412)
+++ Zope3/trunk/src/zope/exceptions/tests/test_exceptionformatter.py	2006-05-31 17:36:17 UTC (rev 68413)
@@ -143,6 +143,22 @@
         self.assert_(s.find('<') >= 0, s)
         self.assert_(s.find('>') >= 0, s)
 
+    def testMultilineException(self):
+        try:
+            exec 'syntax error'
+        except:
+            s = tb()
+        # Traceback (most recent call last):
+        #   Module zope.exceptions.tests.test_exceptionformatter, line ??, in testMultilineException
+        #     exec \'syntax error\'
+        #   File "<string>", line 1
+        #     syntax error
+        #            ^
+        # SyntaxError: unexpected EOF while parsing
+        self.assertEquals(s.splitlines()[-3:],
+                          ['    syntax error',
+                           '               ^',
+                           'SyntaxError: unexpected EOF while parsing'])
 
 
 def test_suite():



More information about the Zope3-Checkins mailing list