diff options
Diffstat (limited to 'Lib/test/test_traceback.py')
-rw-r--r-- | Lib/test/test_traceback.py | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py index 93e5126..600c7b5 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 traceback_print +from io 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() + 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. @@ -76,8 +90,20 @@ class TracebackCases(unittest.TestCase): 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__": |