Skip to content

Commit 08b01e5

Browse files
Jack Kochclaude
andcommitted
test: Add logout error test for mark_emails coverage
Adds test_mark_emails_logout_error to cover lines 1377-1378 (the logout exception handler in mark_emails function). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent a8ebff1 commit 08b01e5

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

tests/test_email_client.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,3 +477,25 @@ async def test_mark_emails_custom_mailbox(self, email_client):
477477

478478
# Verify custom mailbox was selected (quoted)
479479
mock_imap.select.assert_called_once_with('"[Gmail]/All Mail"')
480+
481+
@pytest.mark.asyncio
482+
async def test_mark_emails_logout_error(self, email_client):
483+
"""Test mark_emails handles logout errors gracefully (covers logout exception handler)."""
484+
mock_imap = AsyncMock()
485+
mock_imap._client_task = asyncio.Future()
486+
mock_imap._client_task.set_result(None)
487+
mock_imap.wait_hello_from_server = AsyncMock()
488+
mock_imap.login = AsyncMock()
489+
mock_imap.select = AsyncMock()
490+
mock_imap.uid = AsyncMock(return_value=(None, None))
491+
mock_imap.logout = AsyncMock(side_effect=OSError("Connection closed"))
492+
493+
with patch.object(email_client, "imap_class", return_value=mock_imap):
494+
# Should complete successfully despite logout error
495+
marked_ids, failed_ids = await email_client.mark_emails(
496+
email_ids=["123"],
497+
mark_as="read",
498+
mailbox="INBOX",
499+
)
500+
assert marked_ids == ["123"]
501+
assert failed_ids == []

0 commit comments

Comments
 (0)