diff options
author | R. David Murray <rdmurray@bitdance.com> | 2009-12-09 16:41:39 (GMT) |
---|---|---|
committer | R. David Murray <rdmurray@bitdance.com> | 2009-12-09 16:41:39 (GMT) |
commit | d4e31a4316e6d96269a83f41ec341c3bb89cc3b5 (patch) | |
tree | e9987827eb1f99068bf66dc824686128626e9289 /Lib | |
parent | 93321f333c7fe4a55bdedc9511667916f8bd2ed5 (diff) | |
download | cpython-d4e31a4316e6d96269a83f41ec341c3bb89cc3b5.zip cpython-d4e31a4316e6d96269a83f41ec341c3bb89cc3b5.tar.gz cpython-d4e31a4316e6d96269a83f41ec341c3bb89cc3b5.tar.bz2 |
Skip new imaplib SSL tests if ssl is not available.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_imaplib.py | 45 |
1 files changed, 31 insertions, 14 deletions
diff --git a/Lib/test/test_imaplib.py b/Lib/test/test_imaplib.py index ded8828..bfda0de 100644 --- a/Lib/test/test_imaplib.py +++ b/Lib/test/test_imaplib.py @@ -10,13 +10,17 @@ import os.path 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 @@ class TestImaplib(unittest.TestCase): 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 @@ class ThreadedNetworkedTests(BaseThreadedNetworkedTests): imap_class = imaplib.IMAP4 +@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 @@ def test_main(): 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) |