Skip SSL tests if SSL is not available
This is particularly useful to not require the external OpenSSL module in order to run the tests on python2.5.
This commit is contained in:
@@ -110,6 +110,17 @@ def skip_if_no_itimer(func):
|
||||
return skip_unless(has_itimer)(func)
|
||||
|
||||
|
||||
def skip_if_no_ssl(func):
|
||||
""" Decorator that skips a test if SSL is not available."""
|
||||
try:
|
||||
import eventlet.green.ssl
|
||||
except ImportError:
|
||||
try:
|
||||
import eventlet.green.OpenSSL
|
||||
except ImportError:
|
||||
skipped(func)
|
||||
|
||||
|
||||
class TestIsTakingTooLong(Exception):
|
||||
""" Custom exception class to be raised when a test's runtime exceeds a limit. """
|
||||
pass
|
||||
|
@@ -10,6 +10,9 @@ from eventlet import api
|
||||
warnings.simplefilter('default', DeprecationWarning)
|
||||
from eventlet import greenio, util, hubs, greenthread, spawn
|
||||
|
||||
from tests import skip_if_no_ssl
|
||||
|
||||
|
||||
def check_hub():
|
||||
# Clear through the descriptor queue
|
||||
api.sleep(0)
|
||||
@@ -60,6 +63,7 @@ class TestApi(TestCase):
|
||||
|
||||
check_hub()
|
||||
|
||||
@skip_if_no_ssl
|
||||
def test_connect_ssl(self):
|
||||
def accept_once(listenfd):
|
||||
try:
|
||||
|
@@ -3,7 +3,7 @@ import os
|
||||
import eventlet
|
||||
from eventlet import event
|
||||
from eventlet.green import socket
|
||||
from tests import LimitedTestCase, s2b
|
||||
from tests import LimitedTestCase, s2b, skip_if_no_ssl
|
||||
|
||||
certificate_file = os.path.join(os.path.dirname(__file__), 'test_server.crt')
|
||||
private_key_file = os.path.join(os.path.dirname(__file__), 'test_server.key')
|
||||
@@ -107,6 +107,7 @@ class TestServe(LimitedTestCase):
|
||||
timeout_value="timed out")
|
||||
self.assertEquals(x, "timed out")
|
||||
|
||||
@skip_if_no_ssl
|
||||
def test_wrap_ssl(self):
|
||||
server = eventlet.wrap_ssl(eventlet.listen(('localhost', 0)),
|
||||
certfile=certificate_file,
|
||||
|
@@ -1,4 +1,5 @@
|
||||
from tests import skipped, LimitedTestCase, skip_unless, certificate_file, private_key_file
|
||||
from tests import LimitedTestCase, certificate_file, private_key_file
|
||||
from tests import skip_if_no_ssl
|
||||
from unittest import main
|
||||
import eventlet
|
||||
from eventlet import util, coros, greenio
|
||||
@@ -15,6 +16,7 @@ def listen_ssl_socket(address=('127.0.0.1', 0)):
|
||||
|
||||
|
||||
class SSLTest(LimitedTestCase):
|
||||
@skip_if_no_ssl
|
||||
def test_duplex_response(self):
|
||||
def serve(listener):
|
||||
sock, addr = listener.accept()
|
||||
@@ -30,6 +32,7 @@ class SSLTest(LimitedTestCase):
|
||||
self.assertEquals(client.read(8192), 'response')
|
||||
server_coro.wait()
|
||||
|
||||
@skip_if_no_ssl
|
||||
def test_ssl_close(self):
|
||||
def serve(listener):
|
||||
sock, addr = listener.accept()
|
||||
@@ -50,6 +53,7 @@ class SSLTest(LimitedTestCase):
|
||||
client.close()
|
||||
server_coro.wait()
|
||||
|
||||
@skip_if_no_ssl
|
||||
def test_ssl_connect(self):
|
||||
def serve(listener):
|
||||
sock, addr = listener.accept()
|
||||
@@ -65,6 +69,7 @@ class SSLTest(LimitedTestCase):
|
||||
ssl_client.close()
|
||||
server_coro.wait()
|
||||
|
||||
@skip_if_no_ssl
|
||||
def test_ssl_unwrap(self):
|
||||
def serve():
|
||||
sock, addr = listener.accept()
|
||||
@@ -89,7 +94,7 @@ class SSLTest(LimitedTestCase):
|
||||
server_coro.wait()
|
||||
|
||||
class SocketSSLTest(LimitedTestCase):
|
||||
@skip_unless(hasattr(socket, 'ssl'))
|
||||
@skip_if_no_ssl
|
||||
def test_greensslobject(self):
|
||||
import warnings
|
||||
# disabling socket.ssl warnings because we're testing it here
|
||||
|
@@ -10,6 +10,7 @@ from eventlet import event
|
||||
from eventlet import greenio
|
||||
|
||||
from tests import mock, LimitedTestCase, certificate_file, private_key_file
|
||||
from tests import skip_if_no_ssl
|
||||
from tests.wsgi_test import _TestBase
|
||||
|
||||
|
||||
@@ -517,6 +518,7 @@ class TestWebSocketSSL(_TestBase):
|
||||
def set_site(self):
|
||||
self.site = wsapp
|
||||
|
||||
@skip_if_no_ssl
|
||||
def test_ssl_sending_messages(self):
|
||||
s = eventlet.wrap_ssl(eventlet.listen(('localhost', 0)),
|
||||
certfile=certificate_file,
|
||||
|
@@ -5,7 +5,7 @@ import errno
|
||||
import os
|
||||
import socket
|
||||
import sys
|
||||
from tests import skipped, LimitedTestCase, skip_with_pyevent
|
||||
from tests import skipped, LimitedTestCase, skip_with_pyevent, skip_if_no_ssl
|
||||
from unittest import main
|
||||
|
||||
from eventlet import greenio
|
||||
@@ -370,6 +370,7 @@ class TestHttpd(_TestBase):
|
||||
# Require a CRLF to close the message body
|
||||
self.assertEqual(response, '\r\n')
|
||||
|
||||
@skip_if_no_ssl
|
||||
def test_012_ssl_server(self):
|
||||
def wsgi_app(environ, start_response):
|
||||
start_response('200 OK', {})
|
||||
@@ -390,6 +391,7 @@ class TestHttpd(_TestBase):
|
||||
result = sock.read(8192)
|
||||
self.assertEquals(result[-3:], 'abc')
|
||||
|
||||
@skip_if_no_ssl
|
||||
def test_013_empty_return(self):
|
||||
def wsgi_app(environ, start_response):
|
||||
start_response("200 OK", [])
|
||||
@@ -487,6 +489,7 @@ class TestHttpd(_TestBase):
|
||||
self.assertEquals(1, len([l for l in header_lines
|
||||
if l.lower().startswith('content-length')]))
|
||||
|
||||
@skip_if_no_ssl
|
||||
def test_017_ssl_zeroreturnerror(self):
|
||||
|
||||
def server(sock, site, log):
|
||||
@@ -781,6 +784,7 @@ class TestHttpd(_TestBase):
|
||||
fd.flush()
|
||||
read_http(sock)
|
||||
|
||||
@skip_if_no_ssl
|
||||
def test_028_ssl_handshake_errors(self):
|
||||
errored = [False]
|
||||
def server(sock):
|
||||
|
Reference in New Issue
Block a user