summaryrefslogtreecommitdiff
path: root/test_six.py
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2014-10-29 20:54:24 -0400
committerBenjamin Peterson <benjamin@python.org>2014-10-29 20:54:24 -0400
commitd7c4f2ed2847c1472c0e60f20e25db20e60dc7d7 (patch)
tree998168d25045fd0cefda921c2e09fe869f42288d /test_six.py
parentebe2cd1761a7da32e3fb24fdc53b80914ab1d300 (diff)
downloadsix-git-d7c4f2ed2847c1472c0e60f20e25db20e60dc7d7.tar.gz
add raise_from (fixes #102)
Patch from Robert Collins.
Diffstat (limited to 'test_six.py')
-rw-r--r--test_six.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/test_six.py b/test_six.py
index 4163520..b0ccd8d 100644
--- a/test_six.py
+++ b/test_six.py
@@ -588,6 +588,27 @@ def test_reraise():
assert tb is get_next(tb2)
+def test_raise_from():
+ try:
+ try:
+ raise Exception("blah")
+ except Exception:
+ ctx = sys.exc_info()[1]
+ f = Exception("foo")
+ six.raise_from(f, None)
+ except Exception:
+ tp, val, tb = sys.exc_info()
+ if sys.version_info[:2] > (3, 0):
+ # We should have done a raise f from None equivalent.
+ assert val.__cause__ is None
+ assert val.__context__ is ctx
+ if sys.version_info[:2] >= (3, 3):
+ # And that should suppress the context on the exception.
+ assert val.__suppress_context__
+ # For all versions the outer exception should have raised successfully.
+ assert str(val) == "foo"
+
+
def test_print_():
save = sys.stdout
out = sys.stdout = six.moves.StringIO()