From 3ef85cb5a948287404548120b2aaf053b4055ddd Mon Sep 17 00:00:00 2001 From: Ilya Torbin Date: Sun, 19 Jul 2026 21:22:33 +0300 Subject: [PATCH] Add test that IMAP4.enable() after SELECT raises an error Resolve the long-standing XXX TODO in test_imaplib.py by covering the case where enable() is called from the SELECTED state: ENABLE is only valid in the AUTH state, so it must raise IMAP4.error. --- Lib/test/test_imaplib.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_imaplib.py b/Lib/test/test_imaplib.py index 100791a9c3eb2c..bd521c16ee05ca 100644 --- a/Lib/test/test_imaplib.py +++ b/Lib/test/test_imaplib.py @@ -2523,7 +2523,16 @@ def test_enable_raises_error_if_not_AUTH(self): self.assertRaises(imaplib.IMAP4.error, client.enable, 'foo') self.assertFalse(client.utf8_enabled) - # XXX Also need a test that enable after SELECT raises an error. + @threading_helper.reap_threads + def test_enable_raises_error_after_select(self): + with self.reaped_pair(self.UTF8Server) as (server, client): + typ, _ = client.authenticate('MYAUTH', lambda x: b'fake') + self.assertEqual(typ, 'OK') + typ, _ = client.select() + self.assertEqual(typ, 'OK') + self.assertFalse(client.utf8_enabled) + self.assertRaises(imaplib.IMAP4.error, client.enable, 'UTF8=ACCEPT') + self.assertFalse(client.utf8_enabled) @threading_helper.reap_threads def test_enable_raises_error_if_no_capability(self):