add a test for the exception decorator, which actually fails!
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/c39488ee Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/c39488ee Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/c39488ee Branch: refs/heads/trunk Commit: c39488ee290607e376dfda591dddbe4c2e646a38 Parents: cb213b9 Author: Anthony Shaw <anthonys...@apache.org> Authored: Fri May 5 19:35:11 2017 +1000 Committer: Anthony Shaw <anthonys...@apache.org> Committed: Fri May 5 19:35:11 2017 +1000 ---------------------------------------------------------------------- libcloud/test/common/test_retry_limit.py | 7 +------ libcloud/test/test_utils.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/c39488ee/libcloud/test/common/test_retry_limit.py ---------------------------------------------------------------------- diff --git a/libcloud/test/common/test_retry_limit.py b/libcloud/test/common/test_retry_limit.py index f57ccb3..c661279 100644 --- a/libcloud/test/common/test_retry_limit.py +++ b/libcloud/test/common/test_retry_limit.py @@ -32,9 +32,6 @@ SIMPLE_RESPONSE_STATUS = ('HTTP/1.1', 429, 'CONFLICT') @patch('os.environ', {'LIBCLOUD_RETRY_FAILED_HTTP_REQUESTS': True}) class FailedRequestRetryTestCase(unittest.TestCase): - def _raise_socket_error(self): - raise socket.gaierror('') - def test_retry_connection(self): con = Connection(timeout=1, retry_delay=0.1) con.connection = Mock() @@ -46,9 +43,7 @@ class FailedRequestRetryTestCase(unittest.TestCase): con.request('/') except socket.gaierror: pass - except Exception: - self.fail('Failed to raise socket exception') - + def test_retry_connection_ssl_error(self): conn = Connection(timeout=1, retry_delay=0.1) http://git-wip-us.apache.org/repos/asf/libcloud/blob/c39488ee/libcloud/test/test_utils.py ---------------------------------------------------------------------- diff --git a/libcloud/test/test_utils.py b/libcloud/test/test_utils.py index dd9c2d2..d92e353 100644 --- a/libcloud/test/test_utils.py +++ b/libcloud/test/test_utils.py @@ -15,6 +15,7 @@ # limitations under the License. import sys +import pytest import socket import codecs import unittest @@ -44,6 +45,8 @@ from libcloud.utils.networking import is_private_subnet from libcloud.utils.networking import is_valid_ip_address from libcloud.utils.networking import join_ipv4_segments from libcloud.utils.networking import increment_ipv4_segments +from libcloud.utils.decorators import wrap_non_libcloud_exceptions +from libcloud.common.types import LibcloudError from libcloud.storage.drivers.dummy import DummyIterator @@ -381,5 +384,14 @@ class NetworkingUtilsTestCase(unittest.TestCase): self.assertEqual(result, incremented_ip) +def test_decorator(): + + @wrap_non_libcloud_exceptions + def foo(): + raise Exception("bork") + + with pytest.raises(LibcloudError): + foo() + if __name__ == '__main__': sys.exit(unittest.main())