| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent dfd7344 commit 236f797
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,16 +10,6 @@ | |||
| 10 | 10 | ||
| 11 | 11 | import traceback | |
| 12 | 12 | ||
| 13 | - try: | ||
| 14 | - raise KeyError | ||
| 15 | - except KeyError: | ||
| 16 | - type_, value, tb = sys.exc_info() | ||
| 17 | - file_ = StringIO() | ||
| 18 | - traceback_print(tb, file_) | ||
| 19 | - example_traceback = file_.getvalue() | ||
| 20 | - else: | ||
| 21 | - raise Error("unable to create test traceback string") | ||
| 22 | - | ||
| 23 | 13 | ||
| 24 | 14 | class SyntaxTracebackCases(unittest.TestCase): | |
| 25 | 15 | # For now, a very minimal set of tests. I want to be sure that | |
@@ -158,9 +148,24 @@ def do_test(firstlines, message, charset, lineno): | |||
| 158 | 148 | ||
| 159 | 149 | class TracebackFormatTests(unittest.TestCase): | |
| 160 | 150 | ||
| 161 | - def test_traceback_indentation(self): | ||
| 151 | + def test_traceback_format(self): | ||
| 152 | + try: | ||
| 153 | + raise KeyError('blah') | ||
| 154 | + except KeyError: | ||
| 155 | + type_, value, tb = sys.exc_info() | ||
| 156 | + traceback_fmt = 'Traceback (most recent call last):\n' + \ | ||
| 157 | + ''.join(traceback.format_tb(tb)) | ||
| 158 | + file_ = StringIO() | ||
| 159 | + traceback_print(tb, file_) | ||
| 160 | + python_fmt = file_.getvalue() | ||
| 161 | + else: | ||
| 162 | + raise Error("unable to create test traceback string") | ||
| 163 | + | ||
| 164 | + # Make sure that Python and the traceback module format the same thing | ||
| 165 | + self.assertEquals(traceback_fmt, python_fmt) | ||
| 166 | + | ||
| 162 | 167 | # Make sure that the traceback is properly indented. | |
| 163 | - tb_lines = example_traceback.splitlines() | ||
| 168 | + tb_lines = python_fmt.splitlines() | ||
| 164 | 169 | self.assertEquals(len(tb_lines), 3) | |
| 165 | 170 | banner, location, source_line = tb_lines | |
| 166 | 171 | self.assert_(banner.startswith('Traceback')) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -63,7 +63,7 @@ def print_tb(tb, limit=None, file=None): | |||
| 63 | 63 | filename = co.co_filename | |
| 64 | 64 | name = co.co_name | |
| 65 | 65 | _print(file, | |
| 66 | - ' File "%s", line %d, in %s' % (filename,lineno,name)) | ||
| 66 | + ' File "%s", line %d, in %s' % (filename, lineno, name)) | ||
| 67 | 67 | linecache.checkcache(filename) | |
| 68 | 68 | line = linecache.getline(filename, lineno, f.f_globals) | |
| 69 | 69 | if line: _print(file, ' ' + line.strip()) | |
@@ -159,9 +159,8 @@ def print_exception(etype, value, tb, limit=None, file=None, chain=True): | |||
| 159 | 159 | _print(file, 'Traceback (most recent call last):') | |
| 160 | 160 | print_tb(tb, limit, file) | |
| 161 | 161 | lines = format_exception_only(type(value), value) | |
| 162 | - for line in lines[:-1]: | ||
| 163 | - _print(file, line, ' ') | ||
| 164 | - _print(file, lines[-1], '') | ||
| 162 | + for line in lines: | ||
| 163 | + _print(file, line, '') | ||
| 165 | 164 | ||
| 166 | 165 | def format_exception(etype, value, tb, limit=None, chain=True): | |
| 167 | 166 | """Format a stack trace and the exception information. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -327,6 +327,8 @@ Core and Builtins | |||
| 327 | 327 | Library | |
| 328 | 328 | ------- | |
| 329 | 329 | ||
| 330 | + - Issue 1326077: fix the formatting of SyntaxErrors by the traceback module. | ||
| 331 | + | ||
| 330 | 332 | - Issue #1665206 (partially): Move imports in cgitb to the top of the module | |
| 331 | 333 | instead of performing them in functions. Helps prevent import deadlocking in | |
| 332 | 334 | threads. | |
| Back | FazBrowse Home | New Git URL |
0 commit comments