Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(4)

Side by Side Diff: Lib/test/test_imaplib.py

Issue 4972: context managerment support in imaplib, smtplib, ftplib
Patch Set: Created 7 years ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/imaplib.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 from test import support 1 from test import support
2 # If we end up with a significant number of tests that don't require 2 # If we end up with a significant number of tests that don't require
3 # threading, this test module should be split. Right now we skip 3 # threading, this test module should be split. Right now we skip
4 # them all if we don't have threading. 4 # them all if we don't have threading.
5 threading = support.import_module('threading') 5 threading = support.import_module('threading')
6 6
7 from contextlib import contextmanager 7 from contextlib import contextmanager
8 import imaplib 8 import imaplib
9 import os.path 9 import os.path
10 import socketserver 10 import socketserver
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 args = splitline[2:] 127 args = splitline[2:]
128 128
129 if hasattr(self, 'cmd_'+cmd): 129 if hasattr(self, 'cmd_'+cmd):
130 getattr(self, 'cmd_'+cmd)(tag, args) 130 getattr(self, 'cmd_'+cmd)(tag, args)
131 else: 131 else:
132 self._send('{} BAD {} unknown\r\n'.format(tag, cmd).encode('ASCI I')) 132 self._send('{} BAD {} unknown\r\n'.format(tag, cmd).encode('ASCI I'))
133 133
134 def cmd_CAPABILITY(self, tag, args): 134 def cmd_CAPABILITY(self, tag, args):
135 self._send(b'* CAPABILITY IMAP4rev1\r\n') 135 self._send(b'* CAPABILITY IMAP4rev1\r\n')
136 self._send('{} OK CAPABILITY completed\r\n'.format(tag).encode('ASCII')) 136 self._send('{} OK CAPABILITY completed\r\n'.format(tag).encode('ASCII'))
137
138 def cmd_LOGOUT(self, tag, args):
139 self._send('{} OK LOGOUT\r\n'.format(tag).encode('ASCII'))
140
141 def cmd_LOGIN(self, tag, args):
142 self._send('{} OK LOGIN\r\n'.format(tag).encode('ASCII'))
137 143
138 144
139 class BaseThreadedNetworkedTests(unittest.TestCase): 145 class BaseThreadedNetworkedTests(unittest.TestCase):
140 146
141 def make_server(self, addr, hdlr): 147 def make_server(self, addr, hdlr):
142 148
143 class MyServer(self.server_class): 149 class MyServer(self.server_class):
144 def handle_error(self, request, client_address): 150 def handle_error(self, request, client_address):
145 self.close_request(request) 151 self.close_request(request)
146 self.server_close() 152 self.server_close()
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 class BadNewlineHandler(SimpleIMAPHandler): 213 class BadNewlineHandler(SimpleIMAPHandler):
208 214
209 def cmd_CAPABILITY(self, tag, args): 215 def cmd_CAPABILITY(self, tag, args):
210 self._send(b'* CAPABILITY IMAP4rev1 AUTH\n') 216 self._send(b'* CAPABILITY IMAP4rev1 AUTH\n')
211 self._send('{} OK CAPABILITY completed\r\n'.format(tag).encode(' ASCII')) 217 self._send('{} OK CAPABILITY completed\r\n'.format(tag).encode(' ASCII'))
212 218
213 with self.reaped_server(BadNewlineHandler) as server: 219 with self.reaped_server(BadNewlineHandler) as server:
214 self.assertRaises(imaplib.IMAP4.abort, 220 self.assertRaises(imaplib.IMAP4.abort,
215 self.imap_class, *server.server_address) 221 self.imap_class, *server.server_address)
216 222
223 @reap_threads
224 def test_simple_with_statement(self):
225 # simplest call
226 with self.reaped_server(SimpleIMAPHandler) as server:
227 with self.imap_class(*server.server_address) as imap:
228 pass
229
230 @reap_threads
231 def test_with_statement(self):
232 # doing something
233 with self.reaped_server(SimpleIMAPHandler) as server:
234 with self.imap_class(*server.server_address) as imap:
235 imap.login('user', 'pass')
236
237 @reap_threads
238 def test_with_statement_quit(self):
239 # what happens if already quit in the block ?
240 with self.reaped_server(SimpleIMAPHandler) as server:
241 with self.imap_class(*server.server_address) as imap:
242 imap.login('user', 'pass')
243 imap.logout()
ezio.melotti 2013/01/27 17:53:12 Shouldn't there be some asserts that check that af
storchaka 2013/01/27 19:57:19 Good idea.
217 244
218 245
219 class ThreadedNetworkedTests(BaseThreadedNetworkedTests): 246 class ThreadedNetworkedTests(BaseThreadedNetworkedTests):
220 247
221 server_class = socketserver.TCPServer 248 server_class = socketserver.TCPServer
222 imap_class = imaplib.IMAP4 249 imap_class = imaplib.IMAP4
223 250
224 251
225 @unittest.skipUnless(ssl, "SSL not available") 252 @unittest.skipUnless(ssl, "SSL not available")
226 class ThreadedNetworkedTestsSSL(BaseThreadedNetworkedTests): 253 class ThreadedNetworkedTestsSSL(BaseThreadedNetworkedTests):
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 ThreadedNetworkedTests, ThreadedNetworkedTestsSSL, 376 ThreadedNetworkedTests, ThreadedNetworkedTestsSSL,
350 RemoteIMAPTest, RemoteIMAP_SSLTest, RemoteIMAP_STARTTLSTest, 377 RemoteIMAPTest, RemoteIMAP_SSLTest, RemoteIMAP_STARTTLSTest,
351 ]) 378 ])
352 379
353 support.run_unittest(*tests) 380 support.run_unittest(*tests)
354 381
355 382
356 if __name__ == "__main__": 383 if __name__ == "__main__":
357 support.use_resources = ['network'] 384 support.use_resources = ['network']
358 test_main() 385 test_main()
OLDNEW
« no previous file with comments | « Lib/imaplib.py ('k') | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+