Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6a2a2a0

Browse files
committed
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.
1 parent 59baa75 commit 6a2a2a0

6 files changed

Lines changed: 13 additions & 8 deletions

File tree

Lib/decimal.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
...
8686
...
8787
...
88-
DivisionByZero: x / 0
88+
decimal.DivisionByZero: x / 0
8989
>>> c = Context()
9090
>>> c.traps[InvalidOperation] = 0
9191
>>> print c.flags[InvalidOperation]
@@ -103,7 +103,7 @@
103103
...
104104
...
105105
...
106-
InvalidOperation: 0 / 0
106+
decimal.InvalidOperation: 0 / 0
107107
>>> print c.flags[InvalidOperation]
108108
1
109109
>>> c.flags[InvalidOperation] = 0

Lib/doctest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,7 +1581,7 @@ class UnexpectedException(Exception):
15811581
15821582
- test: the DocTest object being run
15831583
1584-
- excample: the Example object that failed
1584+
- example: the Example object that failed
15851585
15861586
- exc_info: the exception info
15871587
"""
@@ -1664,7 +1664,7 @@ class DebugRunner(DocTestRunner):
16641664
>>> runner.run(test)
16651665
Traceback (most recent call last):
16661666
...
1667-
UnexpectedException: <DocTest foo from foo.py:0 (2 examples)>
1667+
doctest.UnexpectedException: <DocTest foo from foo.py:0 (2 examples)>
16681668
16691669
>>> del test.globs['__builtins__']
16701670
>>> test.globs

Lib/test/test_doctest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2234,7 +2234,7 @@ def test_testfile(): r"""
22342234
>>> doctest.testfile('test_doctest.txt', raise_on_error=True)
22352235
... # doctest: +ELLIPSIS
22362236
Traceback (most recent call last):
2237-
UnexpectedException: ...
2237+
doctest.UnexpectedException: ...
22382238
>>> doctest.master = None # Reset master.
22392239
22402240
If the tests contain non-ASCII characters, the tests might fail, since

Lib/test/test_traceback.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ def __str__(self):
118118
err = traceback.format_exception_only(X, X())
119119
self.assertEqual(len(err), 1)
120120
str_value = '<unprintable %s object>' % X.__name__
121-
self.assertEqual(err[0], X.__name__ + ': ' + str_value + '\n')
121+
self.assertEqual(err[0], "%s.%s: %s\n" % (X.__module__,
122+
X.__name__,
123+
str_value))
122124

123125

124126
def test_main():

Lib/test/test_unpack.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,15 @@
107107
>>> a, b, c, d, e = BadSeq()
108108
Traceback (most recent call last):
109109
...
110-
BozoError
110+
test.test_unpack.BozoError
111111
112112
Trigger code while expecting an IndexError (unpack sequence too short, wrong
113113
error)
114114
115115
>>> a, b, c = BadSeq()
116116
Traceback (most recent call last):
117117
...
118-
BozoError
118+
test.test_unpack.BozoError
119119
120120
"""
121121

Lib/traceback.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ def format_exception_only(etype, value):
163163
"""
164164

165165
stype = etype.__name__
166+
smod = etype.__module__
167+
if smod not in ("exceptions", "__main__", "__builtin__"):
168+
stype = smod + '.' + stype
166169

167170
if not issubclass(etype, SyntaxError):
168171
return [_format_final_exc_line(stype, value)]

0 commit comments

Comments
 (0)