From 5e612d0ac078bae569dece5f718166a834fa9f7e Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Sat, 4 Jan 2014 19:42:36 -0600 Subject: add is_available() to CommonCrypto binding, use it for skipif --- cryptography/hazmat/bindings/commoncrypto/binding.py | 8 +++++++- tests/hazmat/bindings/test_commoncrypto.py | 7 ++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/cryptography/hazmat/bindings/commoncrypto/binding.py b/cryptography/hazmat/bindings/commoncrypto/binding.py index 796135fc..ac5997ea 100644 --- a/cryptography/hazmat/bindings/commoncrypto/binding.py +++ b/cryptography/hazmat/bindings/commoncrypto/binding.py @@ -13,7 +13,9 @@ from __future__ import absolute_import, division, print_function -from cryptography.hazmat.bindings.utils import build_ffi +from cryptography.hazmat.bindings.utils import ( + build_ffi, binding_available +) class Binding(object): @@ -38,3 +40,7 @@ class Binding(object): cls.ffi, cls.lib = build_ffi(cls._module_prefix, cls._modules, "", "", []) + + @classmethod + def is_available(cls): + return binding_available(cls._ensure_ffi_initialized) diff --git a/tests/hazmat/bindings/test_commoncrypto.py b/tests/hazmat/bindings/test_commoncrypto.py index 1eb71151..db3d1b74 100644 --- a/tests/hazmat/bindings/test_commoncrypto.py +++ b/tests/hazmat/bindings/test_commoncrypto.py @@ -13,18 +13,19 @@ import pytest +from cryptography.hazmat.bindings.commoncrypto.binding import Binding -@pytest.mark.commoncrypto + +@pytest.mark.skipif(not Binding.is_available(), + reason="CommonCrypto not available") class TestCommonCrypto(object): def test_binding_loads(self): - from cryptography.hazmat.bindings.commoncrypto.binding import Binding binding = Binding() assert binding assert binding.lib assert binding.ffi def test_binding_returns_same_lib(self): - from cryptography.hazmat.bindings.commoncrypto.binding import Binding binding = Binding() binding2 = Binding() assert binding.lib == binding2.lib -- cgit v1.2.3