diff options
author | Georg Brandl <georg@python.org> | 2009-04-05 14:28:42 +0000 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2009-04-05 14:28:42 +0000 |
commit | 96d2b0f850100e1b6dfef9f1051a11b60dabdd38 (patch) | |
tree | 13d2c1cc8e861eca3594bd8a62373fa5444b7315 /Lib/test/test_traceback.py | |
parent | 5f8b4932e13907794ef706dc00d8bf4ae140323f (diff) | |
download | cpython-96d2b0f850100e1b6dfef9f1051a11b60dabdd38.tar.gz |
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.
........
Diffstat (limited to 'Lib/test/test_traceback.py')
-rw-r--r-- | Lib/test/test_traceback.py | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py index c44e2b1d11..64dc748a85 100644 --- a/Lib/test/test_traceback.py +++ b/Lib/test/test_traceback.py @@ -10,16 +10,6 @@ from test.support import TESTFN, unlink 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 SyntaxTracebackCases(unittest.TestCase): 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')) |