summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_traceback.py
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2008-04-28 03:23:50 (GMT)
committerBrett Cannon <bcannon@gmail.com>2008-04-28 03:23:50 (GMT)
commit141534e56fccd9feb049c0c4115ab7e66688196c (patch)
tree807d95a7e49eadb6d09c71f341acae2c328f2535 /Lib/test/test_traceback.py
parentf30f6e82166bb9364a833e09de002ee438c74ad9 (diff)
downloadcpython-141534e56fccd9feb049c0c4115ab7e66688196c.zip
cpython-141534e56fccd9feb049c0c4115ab7e66688196c.tar.gz
cpython-141534e56fccd9feb049c0c4115ab7e66688196c.tar.bz2
Fix a bug introduced by the warnings rewrite where tracebacks were being
improperly indented. Closes issue #2699.
Diffstat (limited to 'Lib/test/test_traceback.py')
-rw-r--r--Lib/test/test_traceback.py30
1 files changed, 28 insertions, 2 deletions
diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py
index b42dbc4..a3a5e39 100644
--- a/Lib/test/test_traceback.py
+++ b/Lib/test/test_traceback.py
@@ -1,10 +1,24 @@
"""Test cases for traceback module"""
+from _testcapi import test_traceback_print
+from StringIO import StringIO
+import sys
import unittest
-from test.test_support import run_unittest, is_jython
+from test.test_support import run_unittest, is_jython, Error
import traceback
+try:
+ raise KeyError
+except KeyError:
+ type_, value, tb = sys.exc_info()
+ file_ = StringIO()
+ test_traceback_print(tb, file_)
+ example_traceback = file_.getvalue()
+else:
+ raise Error("unable to create test traceback string")
+
+
class TracebackCases(unittest.TestCase):
# For now, a very minimal set of tests. I want to be sure that
# formatting of SyntaxErrors works based on changes for 2.1.
@@ -154,8 +168,20 @@ def test():
self.assertEqual(err, ['None\n'])
+class TracebackFormatTests(unittest.TestCase):
+
+ def test_traceback_indentation(self):
+ # Make sure that the traceback is properly indented.
+ tb_lines = example_traceback.splitlines()
+ self.assertEquals(len(tb_lines), 3)
+ banner, location, source_line = tb_lines
+ self.assert_(banner.startswith('Traceback'))
+ self.assert_(location.startswith(' File'))
+ self.assert_(source_line.startswith('raise'))
+
+
def test_main():
- run_unittest(TracebackCases)
+ run_unittest(TracebackCases, TracebackFormatTests)
if __name__ == "__main__":