mirror of
https://github.com/python/cpython.git
synced 2025-11-26 21:33:10 +00:00
Inspired by SF patch #860326, make the exception formatting by
traceback.py be closer to the built-in formatting. A few unittests had to be fixed, too.
This commit is contained in:
parent
59baa759e4
commit
6a2a2a0832
6 changed files with 13 additions and 8 deletions
|
|
@ -85,7 +85,7 @@ Traceback (most recent call last):
|
||||||
...
|
...
|
||||||
...
|
...
|
||||||
...
|
...
|
||||||
DivisionByZero: x / 0
|
decimal.DivisionByZero: x / 0
|
||||||
>>> c = Context()
|
>>> c = Context()
|
||||||
>>> c.traps[InvalidOperation] = 0
|
>>> c.traps[InvalidOperation] = 0
|
||||||
>>> print c.flags[InvalidOperation]
|
>>> print c.flags[InvalidOperation]
|
||||||
|
|
@ -103,7 +103,7 @@ Traceback (most recent call last):
|
||||||
...
|
...
|
||||||
...
|
...
|
||||||
...
|
...
|
||||||
InvalidOperation: 0 / 0
|
decimal.InvalidOperation: 0 / 0
|
||||||
>>> print c.flags[InvalidOperation]
|
>>> print c.flags[InvalidOperation]
|
||||||
1
|
1
|
||||||
>>> c.flags[InvalidOperation] = 0
|
>>> c.flags[InvalidOperation] = 0
|
||||||
|
|
|
||||||
|
|
@ -1581,7 +1581,7 @@ class UnexpectedException(Exception):
|
||||||
|
|
||||||
- test: the DocTest object being run
|
- test: the DocTest object being run
|
||||||
|
|
||||||
- excample: the Example object that failed
|
- example: the Example object that failed
|
||||||
|
|
||||||
- exc_info: the exception info
|
- exc_info: the exception info
|
||||||
"""
|
"""
|
||||||
|
|
@ -1664,7 +1664,7 @@ class DebugRunner(DocTestRunner):
|
||||||
>>> runner.run(test)
|
>>> runner.run(test)
|
||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
...
|
...
|
||||||
UnexpectedException: <DocTest foo from foo.py:0 (2 examples)>
|
doctest.UnexpectedException: <DocTest foo from foo.py:0 (2 examples)>
|
||||||
|
|
||||||
>>> del test.globs['__builtins__']
|
>>> del test.globs['__builtins__']
|
||||||
>>> test.globs
|
>>> test.globs
|
||||||
|
|
|
||||||
|
|
@ -2234,7 +2234,7 @@ debugging):
|
||||||
>>> doctest.testfile('test_doctest.txt', raise_on_error=True)
|
>>> doctest.testfile('test_doctest.txt', raise_on_error=True)
|
||||||
... # doctest: +ELLIPSIS
|
... # doctest: +ELLIPSIS
|
||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
UnexpectedException: ...
|
doctest.UnexpectedException: ...
|
||||||
>>> doctest.master = None # Reset master.
|
>>> doctest.master = None # Reset master.
|
||||||
|
|
||||||
If the tests contain non-ASCII characters, the tests might fail, since
|
If the tests contain non-ASCII characters, the tests might fail, since
|
||||||
|
|
|
||||||
|
|
@ -118,7 +118,9 @@ def test():
|
||||||
err = traceback.format_exception_only(X, X())
|
err = traceback.format_exception_only(X, X())
|
||||||
self.assertEqual(len(err), 1)
|
self.assertEqual(len(err), 1)
|
||||||
str_value = '<unprintable %s object>' % X.__name__
|
str_value = '<unprintable %s object>' % X.__name__
|
||||||
self.assertEqual(err[0], X.__name__ + ': ' + str_value + '\n')
|
self.assertEqual(err[0], "%s.%s: %s\n" % (X.__module__,
|
||||||
|
X.__name__,
|
||||||
|
str_value))
|
||||||
|
|
||||||
|
|
||||||
def test_main():
|
def test_main():
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,7 @@ error)
|
||||||
>>> a, b, c, d, e = BadSeq()
|
>>> a, b, c, d, e = BadSeq()
|
||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
...
|
...
|
||||||
BozoError
|
test.test_unpack.BozoError
|
||||||
|
|
||||||
Trigger code while expecting an IndexError (unpack sequence too short, wrong
|
Trigger code while expecting an IndexError (unpack sequence too short, wrong
|
||||||
error)
|
error)
|
||||||
|
|
@ -115,7 +115,7 @@ error)
|
||||||
>>> a, b, c = BadSeq()
|
>>> a, b, c = BadSeq()
|
||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
...
|
...
|
||||||
BozoError
|
test.test_unpack.BozoError
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -163,6 +163,9 @@ def format_exception_only(etype, value):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
stype = etype.__name__
|
stype = etype.__name__
|
||||||
|
smod = etype.__module__
|
||||||
|
if smod not in ("exceptions", "__main__", "__builtin__"):
|
||||||
|
stype = smod + '.' + stype
|
||||||
|
|
||||||
if not issubclass(etype, SyntaxError):
|
if not issubclass(etype, SyntaxError):
|
||||||
return [_format_final_exc_line(stype, value)]
|
return [_format_final_exc_line(stype, value)]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue