diff options
| author | Floris Bruynooghe <flub@devork.be> | 2012-09-05 00:49:20 +0100 |
|---|---|---|
| committer | Floris Bruynooghe <flub@devork.be> | 2012-09-05 00:49:20 +0100 |
| commit | 2fc5857c8a09d8f488eeba8b74c1af7680e9bfcd (patch) | |
| tree | c25b585dd374b2ed840e161304cb989ea0831df7 /tests | |
| parent | 3003d941d7d969a8a9d92d0829d2e4bbbf59b7fb (diff) | |
| download | eventlet-2fc5857c8a09d8f488eeba8b74c1af7680e9bfcd.tar.gz | |
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.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/__init__.py | 11 | ||||
| -rw-r--r-- | tests/api_test.py | 4 | ||||
| -rw-r--r-- | tests/convenience_test.py | 3 | ||||
| -rw-r--r-- | tests/ssl_test.py | 9 | ||||
| -rw-r--r-- | tests/websocket_test.py | 2 | ||||
| -rw-r--r-- | tests/wsgi_test.py | 6 |
6 files changed, 31 insertions, 4 deletions
diff --git a/tests/__init__.py b/tests/__init__.py index f7c1d59..7732f8c 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -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 diff --git a/tests/api_test.py b/tests/api_test.py index 3a9f337..5aa0e4a 100644 --- a/tests/api_test.py +++ b/tests/api_test.py @@ -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: diff --git a/tests/convenience_test.py b/tests/convenience_test.py index b7ae926..08e3705 100644 --- a/tests/convenience_test.py +++ b/tests/convenience_test.py @@ -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, diff --git a/tests/ssl_test.py b/tests/ssl_test.py index 0130014..eb7dbeb 100644 --- a/tests/ssl_test.py +++ b/tests/ssl_test.py @@ -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 diff --git a/tests/websocket_test.py b/tests/websocket_test.py index f8bb45f..791ed99 100644 --- a/tests/websocket_test.py +++ b/tests/websocket_test.py @@ -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, diff --git a/tests/wsgi_test.py b/tests/wsgi_test.py index 040eb4c..2939b03 100644 --- a/tests/wsgi_test.py +++ b/tests/wsgi_test.py @@ -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): |
