[Python-checkins] r71239 - in python/branches/py3k: Lib/test/test_traceback.py Lib/traceback.py Misc/NEWS

georg.brandl python-checkins at python.org
Sun Apr 5 16:28:43 CEST 2009


Author: georg.brandl
Date: Sun Apr  5 16:28:42 2009
New Revision: 71239

Log:
Merged revisions 71237-71238 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r71237 | georg.brandl | 2009-04-05 16:24:52 +0200 (So, 05 Apr 2009) | 1 line
  
  #1326077: fix traceback formatting of SyntaxErrors.  This fixes two differences with formatting coming from Python: a) the reproduction of location details in the error message if no line text is given, b) the prefixing of the last line by one space.
........
  r71238 | georg.brandl | 2009-04-05 16:25:41 +0200 (So, 05 Apr 2009) | 1 line
  
  Add NEWS entry for r71237.
........


Modified:
   python/branches/py3k/   (props changed)
   python/branches/py3k/Lib/test/test_traceback.py
   python/branches/py3k/Lib/traceback.py
   python/branches/py3k/Misc/NEWS

Modified: python/branches/py3k/Lib/test/test_traceback.py
==============================================================================
--- python/branches/py3k/Lib/test/test_traceback.py	(original)
+++ python/branches/py3k/Lib/test/test_traceback.py	Sun Apr  5 16:28:42 2009
@@ -10,16 +10,6 @@
 
 import traceback
 
-try:
-    raise KeyError
-except KeyError:
-    type_, value, tb = sys.exc_info()
-    file_ = StringIO()
-    traceback_print(tb, file_)
-    example_traceback = file_.getvalue()
-else:
-    raise Error("unable to create test traceback string")
-
 
 class SyntaxTracebackCases(unittest.TestCase):
     # For now, a very minimal set of tests.  I want to be sure that
@@ -158,9 +148,24 @@
 
 class TracebackFormatTests(unittest.TestCase):
 
-    def test_traceback_indentation(self):
+    def test_traceback_format(self):
+        try:
+            raise KeyError('blah')
+        except KeyError:
+            type_, value, tb = sys.exc_info()
+            traceback_fmt = 'Traceback (most recent call last):\n' + \
+                            ''.join(traceback.format_tb(tb))
+            file_ = StringIO()
+            traceback_print(tb, file_)
+            python_fmt  = file_.getvalue()
+        else:
+            raise Error("unable to create test traceback string")
+
+        # Make sure that Python and the traceback module format the same thing
+        self.assertEquals(traceback_fmt, python_fmt)
+
         # Make sure that the traceback is properly indented.
-        tb_lines = example_traceback.splitlines()
+        tb_lines = python_fmt.splitlines()
         self.assertEquals(len(tb_lines), 3)
         banner, location, source_line = tb_lines
         self.assert_(banner.startswith('Traceback'))

Modified: python/branches/py3k/Lib/traceback.py
==============================================================================
--- python/branches/py3k/Lib/traceback.py	(original)
+++ python/branches/py3k/Lib/traceback.py	Sun Apr  5 16:28:42 2009
@@ -63,7 +63,7 @@
         filename = co.co_filename
         name = co.co_name
         _print(file,
-               '  File "%s", line %d, in %s' % (filename,lineno,name))
+               '  File "%s", line %d, in %s' % (filename, lineno, name))
         linecache.checkcache(filename)
         line = linecache.getline(filename, lineno, f.f_globals)
         if line: _print(file, '    ' + line.strip())
@@ -159,9 +159,8 @@
             _print(file, 'Traceback (most recent call last):')
             print_tb(tb, limit, file)
         lines = format_exception_only(type(value), value)
-        for line in lines[:-1]:
-            _print(file, line, ' ')
-        _print(file, lines[-1], '')
+        for line in lines:
+            _print(file, line, '')
 
 def format_exception(etype, value, tb, limit=None, chain=True):
     """Format a stack trace and the exception information.

Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS	(original)
+++ python/branches/py3k/Misc/NEWS	Sun Apr  5 16:28:42 2009
@@ -327,6 +327,8 @@
 Library
 -------
 
+- Issue 1326077: fix the formatting of SyntaxErrors by the traceback module.
+
 - Issue #1665206 (partially): Move imports in cgitb to the top of the module
   instead of performing them in functions. Helps prevent import deadlocking in
   threads.


More information about the Python-checkins mailing list