[Python-checkins] r76727 - python/trunk/Lib/test/test_imaplib.py
r.david.murray
python-checkins at python.org
Wed Dec 9 17:41:39 CET 2009
Author: r.david.murray
Date: Wed Dec 9 17:41:39 2009
New Revision: 76727
Log:
Skip new imaplib SSL tests if ssl is not available.
Modified:
python/trunk/Lib/test/test_imaplib.py
Modified: python/trunk/Lib/test/test_imaplib.py
==============================================================================
--- python/trunk/Lib/test/test_imaplib.py (original)
+++ python/trunk/Lib/test/test_imaplib.py Wed Dec 9 17:41:39 2009
@@ -10,13 +10,17 @@
import select
import socket
import SocketServer
-import ssl
import sys
import time
from test_support import reap_threads, verbose
import unittest
+try:
+ import ssl
+except ImportError:
+ ssl = None
+
CERTFILE = None
@@ -33,14 +37,25 @@
imaplib.Time2Internaldate(t)
-class SecureTCPServer(SocketServer.TCPServer):
+if ssl:
+
+ class SecureTCPServer(SocketServer.TCPServer):
+
+ def get_request(self):
+ newsocket, fromaddr = self.socket.accept()
+ connstream = ssl.wrap_socket(newsocket,
+ server_side=True,
+ certfile=CERTFILE)
+ return connstream, fromaddr
+
+ IMAP4_SSL = imaplib.IMAP4_SSL
+
+else:
+
+ class SecureTCPServer:
+ pass
- def get_request(self):
- newsocket, fromaddr = self.socket.accept()
- connstream = ssl.wrap_socket(newsocket,
- server_side=True,
- certfile=CERTFILE)
- return connstream, fromaddr
+ IMAP4_SSL = None
class SimpleIMAPHandler(SocketServer.StreamRequestHandler):
@@ -159,10 +174,11 @@
imap_class = imaplib.IMAP4
+ at unittest.skipUnless(ssl, "SSL not available")
class ThreadedNetworkedTestsSSL(BaseThreadedNetworkedTests):
server_class = SecureTCPServer
- imap_class = imaplib.IMAP4_SSL
+ imap_class = IMAP4_SSL
def test_main():
@@ -170,11 +186,12 @@
tests = [TestImaplib]
if support.is_resource_enabled('network'):
- global CERTFILE
- CERTFILE = os.path.join(os.path.dirname(__file__) or os.curdir,
- "keycert.pem")
- if not os.path.exists(CERTFILE):
- raise support.TestFailed("Can't read certificate files!")
+ if ssl:
+ global CERTFILE
+ CERTFILE = os.path.join(os.path.dirname(__file__) or os.curdir,
+ "keycert.pem")
+ if not os.path.exists(CERTFILE):
+ raise support.TestFailed("Can't read certificate files!")
tests.extend([ThreadedNetworkedTests, ThreadedNetworkedTestsSSL])
support.run_unittest(*tests)
More information about the Python-checkins
mailing list