tests: skip_if_no_ssl decorator always returned None

This commit is contained in:
Sergey Shepelev
2013-01-10 16:06:31 +04:00
parent d4565ee6a0
commit b0b82a2f8a

View File

@@ -1,12 +1,12 @@
# package is named tests, not test, so it won't be confused with test in stdlib # package is named tests, not test, so it won't be confused with test in stdlib
import sys
import os
import errno import errno
import os
import unittest import unittest
import warnings import warnings
from eventlet import debug, hubs from eventlet import debug, hubs
# convenience for importers # convenience for importers
main = unittest.main main = unittest.main
@@ -34,7 +34,7 @@ def skipped(func):
def skip_if(condition): def skip_if(condition):
""" Decorator that skips a test if the *condition* evaluates True. """ Decorator that skips a test if the *condition* evaluates True.
*condition* can be a boolean or a callable that accepts one argument. *condition* can be a boolean or a callable that accepts one argument.
The callable will be called with the function to be decorated, and The callable will be called with the function to be decorated, and
should return True to skip the test. should return True to skip the test.
""" """
def skipped_wrapper(func): def skipped_wrapper(func):
@@ -55,9 +55,9 @@ def skip_if(condition):
def skip_unless(condition): def skip_unless(condition):
""" Decorator that skips a test if the *condition* does not return True. """ Decorator that skips a test if the *condition* does not return True.
*condition* can be a boolean or a callable that accepts one argument. *condition* can be a boolean or a callable that accepts one argument.
The callable will be called with the function to be decorated, and The callable will be called with the function to be decorated, and
should return True if the condition is satisfied. should return True if the condition is satisfied.
""" """
def skipped_wrapper(func): def skipped_wrapper(func):
def wrapped(*a, **kw): def wrapped(*a, **kw):
if isinstance(condition, bool): if isinstance(condition, bool):
@@ -82,13 +82,13 @@ def requires_twisted(func):
except Exception: except Exception:
return False return False
return skip_unless(requirement)(func) return skip_unless(requirement)(func)
def using_pyevent(_f): def using_pyevent(_f):
from eventlet.hubs import get_hub from eventlet.hubs import get_hub
return 'pyevent' in type(get_hub()).__module__ return 'pyevent' in type(get_hub()).__module__
def skip_with_pyevent(func): def skip_with_pyevent(func):
""" Decorator that skips a test if we're using the pyevent hub.""" """ Decorator that skips a test if we're using the pyevent hub."""
return skip_if(using_pyevent)(func) return skip_if(using_pyevent)(func)
@@ -114,11 +114,13 @@ def skip_if_no_ssl(func):
""" Decorator that skips a test if SSL is not available.""" """ Decorator that skips a test if SSL is not available."""
try: try:
import eventlet.green.ssl import eventlet.green.ssl
return func
except ImportError: except ImportError:
try: try:
import eventlet.green.OpenSSL import eventlet.green.OpenSSL
return func
except ImportError: except ImportError:
skipped(func) return skipped(func)
class TestIsTakingTooLong(Exception): class TestIsTakingTooLong(Exception):
@@ -223,7 +225,7 @@ def get_database_auth():
import simplejson as json import simplejson as json
except ImportError: except ImportError:
print "No json implementation, using baked-in db credentials." print "No json implementation, using baked-in db credentials."
return retval return retval
if 'EVENTLET_DB_TEST_AUTH' in os.environ: if 'EVENTLET_DB_TEST_AUTH' in os.environ:
return json.loads(os.environ.get('EVENTLET_DB_TEST_AUTH')) return json.loads(os.environ.get('EVENTLET_DB_TEST_AUTH'))