diff options
author | Dong-hee Na <donghee.na92@gmail.com> | 2020-01-08 02:28:10 +0900 |
---|---|---|
committer | Victor Stinner <vstinner@python.org> | 2020-01-07 18:28:10 +0100 |
commit | 13a7ee8d62dafe7d2291708312fa2a86e171c7fa (patch) | |
tree | 1e7faf47f7cb00a2a540553c8686941d1f4a0852 /Lib/test/test_imaplib.py | |
parent | 950c6795aa0ffa85e103a13e7a04e08cb34c66ad (diff) | |
download | cpython-git-13a7ee8d62dafe7d2291708312fa2a86e171c7fa.tar.gz |
bpo-38615: Add timeout parameter for IMAP4 and IMAP4_SSL constructor (GH-17203)
imaplib.IMAP4 and imaplib.IMAP4_SSL now have an
optional *timeout* parameter for their constructors.
Also, the imaplib.IMAP4.open() method now has an optional *timeout* parameter
with this change. The overridden methods of imaplib.IMAP4_SSL and
imaplib.IMAP4_stream were applied to this change.
Diffstat (limited to 'Lib/test/test_imaplib.py')
-rw-r--r-- | Lib/test/test_imaplib.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/Lib/test/test_imaplib.py b/Lib/test/test_imaplib.py index 795276e0a7..91aa77126a 100644 --- a/Lib/test/test_imaplib.py +++ b/Lib/test/test_imaplib.py @@ -440,6 +440,29 @@ class NewIMAPTestsMixin(): with self.imap_class(*server.server_address): pass + def test_imaplib_timeout_test(self): + _, server = self._setup(SimpleIMAPHandler) + addr = server.server_address[1] + client = self.imap_class("localhost", addr, timeout=None) + self.assertEqual(client.sock.timeout, None) + client.shutdown() + client = self.imap_class("localhost", addr, timeout=support.LOOPBACK_TIMEOUT) + self.assertEqual(client.sock.timeout, support.LOOPBACK_TIMEOUT) + client.shutdown() + with self.assertRaises(ValueError): + client = self.imap_class("localhost", addr, timeout=0) + + def test_imaplib_timeout_functionality_test(self): + class TimeoutHandler(SimpleIMAPHandler): + def handle(self): + time.sleep(1) + SimpleIMAPHandler.handle(self) + + _, server = self._setup(TimeoutHandler) + addr = server.server_address[1] + with self.assertRaises(socket.timeout): + client = self.imap_class("localhost", addr, timeout=0.001) + def test_with_statement(self): _, server = self._setup(SimpleIMAPHandler, connect=False) with self.imap_class(*server.server_address) as imap: |