From 79336b902944185ebef1a9e08c567683cf83169f Mon Sep 17 00:00:00 2001 From: Alexandre Detiste Date: Thu, 16 Jan 2025 07:48:29 +0100 Subject: [PATCH] drop Python2 crumbs - old external "mock" module, this is now part of the Python standard library https://github.com/testing-cabal/mock "mock is now part of the Python standard library, available as unittest.mock in Python 3.3 onwards." - "(object)" object notation: this is a no-op on Python3 --- aioimaplib/aioimaplib.py | 4 ++-- aioimaplib/imap_testing_server.py | 6 +++--- pyproject.toml | 3 +-- tests/test_aioimaplib.py | 2 +- tests/test_imapserver.py | 2 +- tests/test_imapserver_imaplib2.py | 4 +--- 6 files changed, 9 insertions(+), 12 deletions(-) diff --git a/aioimaplib/aioimaplib.py b/aioimaplib/aioimaplib.py index 441c445..c2f3063 100644 --- a/aioimaplib/aioimaplib.py +++ b/aioimaplib/aioimaplib.py @@ -140,7 +140,7 @@ def arguments_rfs2971(**kwargs: Union[dict, list, str]) -> Union[dict, list]: return args -class Command(object): +class Command: def __init__(self, name: str, tag: str, *args, prefix: str = None, untagged_resp_name: str = None, loop: asyncio.AbstractEventLoop = None, timeout: float = None) -> None: self.name = name @@ -699,7 +699,7 @@ def _find_pending_async_cmd_by_tag(self, tag: str) -> list: return [c for c in self.pending_async_commands.values() if c is not None and c.tag == tag] -class IMAP4(object): +class IMAP4: TIMEOUT_SECONDS = 10.0 _client_task: Task diff --git a/aioimaplib/imap_testing_server.py b/aioimaplib/imap_testing_server.py index 22550d9..b303aa3 100644 --- a/aioimaplib/imap_testing_server.py +++ b/aioimaplib/imap_testing_server.py @@ -53,7 +53,7 @@ def __init__(self, *args) -> None: super().__init__(*args) -class ServerState(object): +class ServerState: DEFAULT_MAILBOXES = ['INBOX', 'Trash', 'Sent', 'Drafts'] def __init__(self): @@ -670,7 +670,7 @@ def getquotaroot(self, tag, *args): self.send_tagged_line(tag, 'OK GETQUOTAROOT completed.') -class MockImapServer(object): +class MockImapServer: def __init__(self, capabilities=CAPABILITIES, loop=None) -> None: self._server_state = ServerState() self._connections = list() @@ -725,7 +725,7 @@ def reset(self): self._server_state.reset() -class Mail(object): +class Mail: def __init__(self, email, date=datetime.now()): self.date = date self.email = email diff --git a/pyproject.toml b/pyproject.toml index 4de3a84..e2aa6e8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,7 +29,6 @@ python = "^3.9" pytest = "^8.3" pytest-asyncio = "^0.25" pytest-rerunfailures = "^15.0" -mock = "^5.1" pytz = "^2024" tzlocal = "^5.2" imaplib2 = "3.6" @@ -43,4 +42,4 @@ requires = ["poetry-core"] build-backend = "poetry.core.masonry.api" [tool.poetry.scripts] -imap-testing-server = "aioimaplib.imap_testing_server:main" \ No newline at end of file +imap-testing-server = "aioimaplib.imap_testing_server:main" diff --git a/tests/test_aioimaplib.py b/tests/test_aioimaplib.py index 07014c6..a3adc99 100644 --- a/tests/test_aioimaplib.py +++ b/tests/test_aioimaplib.py @@ -19,9 +19,9 @@ import ssl import unittest from datetime import datetime, timedelta +from unittest.mock import call, MagicMock import pytest -from mock import call, MagicMock from pytz import utc from aioimaplib import aioimaplib, extract_exists, STOP_WAIT_SERVER_PUSH, FetchCommand, IdleCommand diff --git a/tests/test_imapserver.py b/tests/test_imapserver.py index b875951..7485c4d 100644 --- a/tests/test_imapserver.py +++ b/tests/test_imapserver.py @@ -143,7 +143,7 @@ def test_reprocess_ids_if_a_message_is_removed(self): assert 3 == server_state.max_uid('user', 'INBOX') -class WithImapServer(object): +class WithImapServer: def _init_server(self, loop, capabilities=None, ssl_context=None): self.loop = loop if capabilities is not None: diff --git a/tests/test_imapserver_imaplib2.py b/tests/test_imapserver_imaplib2.py index 76b47ad..5434a52 100644 --- a/tests/test_imapserver_imaplib2.py +++ b/tests/test_imapserver_imaplib2.py @@ -14,13 +14,11 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . import asyncio - import functools - import time +from unittest.mock import Mock from imaplib2 import imaplib2 -from mock import Mock from aioimaplib.imap_testing_server import Mail, IDLE, SELECTED from tests.server_fixture import with_server, login_user import pytest