Floris Bruynooghe avatar Floris Bruynooghe committed 4bdd792

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.

Comments (0)

Files changed (6)

tests/__init__.py

     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

tests/api_test.py

 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)
 
         check_hub()
 
+    @skip_if_no_ssl
     def test_connect_ssl(self):
         def accept_once(listenfd):
             try:

tests/convenience_test.py

 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')
             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,

tests/ssl_test.py

-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
    
 
 class SSLTest(LimitedTestCase):
+    @skip_if_no_ssl
     def test_duplex_response(self):
         def serve(listener):
             sock, addr = listener.accept()
         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()
         client.close()
         server_coro.wait()
         
+    @skip_if_no_ssl
     def test_ssl_connect(self):
         def serve(listener):
             sock, addr = listener.accept()
         ssl_client.close()
         server_coro.wait()
 
+    @skip_if_no_ssl
     def test_ssl_unwrap(self):
         def serve():
             sock, addr = listener.accept()
         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

tests/websocket_test.py

 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
 
 
     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, 

tests/wsgi_test.py

 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
         # 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', {})
         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", [])
         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):
         fd.flush()
         read_http(sock)
 
+    @skip_if_no_ssl
     def test_028_ssl_handshake_errors(self):
         errored = [False]
         def server(sock):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.