diff options
Diffstat (limited to 'Lib/test/test_imaplib.py')
-rw-r--r-- | Lib/test/test_imaplib.py | 50 |
1 files changed, 34 insertions, 16 deletions
diff --git a/Lib/test/test_imaplib.py b/Lib/test/test_imaplib.py index 6116c8b..8034000 100644 --- a/Lib/test/test_imaplib.py +++ b/Lib/test/test_imaplib.py @@ -7,10 +7,7 @@ threading = support.import_module('threading') from contextlib import contextmanager import imaplib import os.path -import select -import socket import socketserver -import sys import time import calendar @@ -76,7 +73,7 @@ class SimpleIMAPHandler(socketserver.StreamRequestHandler): timeout = 1 def _send(self, message): - if verbose: print("SENT:", message.strip()) + if verbose: print("SENT: %r" % message.strip()) self.wfile.write(message) def handle(self): @@ -100,7 +97,7 @@ class SimpleIMAPHandler(socketserver.StreamRequestHandler): if line.endswith(b'\r\n'): break - if verbose: print('GOT:', line.strip()) + if verbose: print('GOT: %r' % line.strip()) splitline = line.split() tag = splitline[0].decode('ASCII') cmd = splitline[1].decode('ASCII') @@ -151,6 +148,7 @@ class BaseThreadedNetworkedTests(unittest.TestCase): def reap_server(self, server, thread): if verbose: print("waiting for server") server.shutdown() + server.server_close() thread.join() if verbose: print("done") @@ -221,20 +219,38 @@ class RemoteIMAPTest(unittest.TestCase): def tearDown(self): if self.server is not None: - self.server.logout() + with transient_internet(self.host): + self.server.logout() def test_logincapa(self): - self.assertTrue('LOGINDISABLED' in self.server.capabilities) - - def test_anonlogin(self): - self.assertTrue('AUTH=ANONYMOUS' in self.server.capabilities) - rs = self.server.login(self.username, self.password) - self.assertEqual(rs[0], 'OK') + with transient_internet(self.host): + for cap in self.server.capabilities: + self.assertIsInstance(cap, str) + self.assertTrue('LOGINDISABLED' in self.server.capabilities) + self.assertTrue('AUTH=ANONYMOUS' in self.server.capabilities) + rs = self.server.login(self.username, self.password) + self.assertEqual(rs[0], 'OK') def test_logout(self): - rs = self.server.logout() - self.server = None - self.assertEqual(rs[0], 'BYE') + with transient_internet(self.host): + rs = self.server.logout() + self.server = None + self.assertEqual(rs[0], 'BYE') + + +@unittest.skipUnless(ssl, "SSL not available") +class RemoteIMAP_STARTTLSTest(RemoteIMAPTest): + + def setUp(self): + super().setUp() + with transient_internet(self.host): + rs = self.server.starttls() + self.assertEqual(rs[0], 'OK') + + def test_logincapa(self): + for cap in self.server.capabilities: + self.assertIsInstance(cap, str) + self.assertFalse('LOGINDISABLED' in self.server.capabilities) @unittest.skipUnless(ssl, "SSL not available") @@ -243,6 +259,8 @@ class RemoteIMAP_SSLTest(RemoteIMAPTest): imap_class = IMAP4_SSL def test_logincapa(self): + for cap in self.server.capabilities: + self.assertIsInstance(cap, str) self.assertFalse('LOGINDISABLED' in self.server.capabilities) self.assertTrue('AUTH=PLAIN' in self.server.capabilities) @@ -259,7 +277,7 @@ def test_main(): raise support.TestFailed("Can't read certificate files!") tests.extend([ ThreadedNetworkedTests, ThreadedNetworkedTestsSSL, - RemoteIMAPTest, RemoteIMAP_SSLTest, + RemoteIMAPTest, RemoteIMAP_SSLTest, RemoteIMAP_STARTTLSTest, ]) support.run_unittest(*tests) |