Fix brownbag in issue 17911 commit

This commit is contained in:
Robert Collins 2015-03-05 12:26:00 +13:00
parent 1f22df9651
commit 4330215880
2 changed files with 7 additions and 4 deletions

View File

@ -445,7 +445,10 @@ class TracebackException:
@classmethod
def from_exception(self, exc, *args, **kwargs):
"""Create a TracebackException from an exception."""
"""Create a TracebackException from an exception.
Only useful in Python 3 specific code.
"""
return TracebackException(
type(exc), exc, exc.__traceback__, *args, **kwargs)

View File

@ -616,6 +616,7 @@ class TestTracebackException(unittest.TestCase):
self.assertEqual(exc_info[0], exc.exc_type)
self.assertEqual(str(exc_info[1]), str(exc))
@unittest.skipIf(sys.version_info[:2] < (3, 0), "Only applies to 3+")
def test_from_exception(self):
# Check all the parameters are accepted.
def foo():
@ -625,10 +626,9 @@ class TestTracebackException(unittest.TestCase):
except Exception as e:
exc_info = sys.exc_info()
self.expected_stack = traceback.StackSummary.extract(
traceback.walk_tb(exc_info[2]), limit=1, lookup_lines=False,
capture_locals=True)
traceback.walk_tb(exc_info[2]), limit=1, lookup_lines=False)
self.exc = traceback.TracebackException.from_exception(
e, limit=1, lookup_lines=False, capture_locals=True)
e, limit=1, lookup_lines=False)
expected_stack = self.expected_stack
exc = self.exc
self.assertEqual(None, exc.__cause__)