summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2015-01-14 21:32:39 -0500
committerJason R. Coombs <jaraco@jaraco.com>2015-01-14 21:32:39 -0500
commitd893e5b562bedd4d63c3533016abe19c29c0f3f6 (patch)
treec42faf7b94bc6618d601bdc7f6db74642267b153
parentc393a4b3045bf8b339d81e59afa78b2066513b59 (diff)
downloadpython-setuptools-bitbucket-d893e5b562bedd4d63c3533016abe19c29c0f3f6.tar.gz
Add tests for new ExceptionSaver
-rw-r--r--setuptools/tests/test_sandbox.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/setuptools/tests/test_sandbox.py b/setuptools/tests/test_sandbox.py
index 9a2a6b7b..33fb3329 100644
--- a/setuptools/tests/test_sandbox.py
+++ b/setuptools/tests/test_sandbox.py
@@ -54,3 +54,31 @@ class TestSandbox:
with setup_py.open('wb') as stream:
stream.write(b'"degenerate script"\r\n')
setuptools.sandbox._execfile(str(setup_py), globals())
+
+
+class TestExceptionSaver:
+ def test_exception_trapped(self):
+ with setuptools.sandbox.ExceptionSaver():
+ raise ValueError("details")
+
+ def test_exception_resumed(self):
+ with setuptools.sandbox.ExceptionSaver() as saved_exc:
+ raise ValueError("details")
+
+ with pytest.raises(ValueError) as caught:
+ saved_exc.resume()
+
+ assert isinstance(caught.value, ValueError)
+ assert str(caught.value) == 'details'
+
+ def test_exception_reconstructed(self):
+ orig_exc = ValueError("details")
+
+ with setuptools.sandbox.ExceptionSaver() as saved_exc:
+ raise orig_exc
+
+ with pytest.raises(ValueError) as caught:
+ saved_exc.resume()
+
+ assert isinstance(caught.value, ValueError)
+ assert caught.value is not orig_exc