]> arthur.barton.de Git - bup.git/blobdiff - lib/bup/t/tcompat.py
compat: add "with pending_raise(ex)" to simplify nested exceptions
[bup.git] / lib / bup / t / tcompat.py
diff --git a/lib/bup/t/tcompat.py b/lib/bup/t/tcompat.py
new file mode 100644 (file)
index 0000000..039eb12
--- /dev/null
@@ -0,0 +1,32 @@
+
+from __future__ import absolute_import, print_function
+
+from wvtest import *
+
+from bup.compat import pending_raise
+
+@wvtest
+def test_pending_raise():
+    outer = Exception('outer')
+    inner = Exception('inner')
+
+    try:
+        try:
+            raise outer
+        except Exception as ex:
+            with pending_raise(ex):
+                pass
+    except Exception as ex:
+        WVPASSEQ(outer, ex)
+        WVPASSEQ(None, getattr(outer, '__context__', None))
+
+    try:
+        try:
+            raise outer
+        except Exception as ex:
+            with pending_raise(ex):
+                raise inner
+    except Exception as ex:
+        WVPASSEQ(inner, ex)
+        WVPASSEQ(None, getattr(outer, '__context__', None))
+        WVPASSEQ(outer, getattr(inner, '__context__', None))