From dfe5a3f37a69a71a27972dc6087a6260c6b6e31d Mon Sep 17 00:00:00 2001 From: odrling Date: Wed, 10 Jan 2024 21:49:45 +0100 Subject: [PATCH] remove asynctest --- pyproject.toml | 1 - tests/tests_client/__init__.py | 6 +++--- tests/tests_client/test_upload.py | 22 ++++++---------------- 3 files changed, 9 insertions(+), 20 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index b54c858..d5684d4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -53,7 +53,6 @@ tests = [ "python-magic", "python-magic-bin; platform_system == 'Windows'", # test dependencies - "asynctest", "codecov", "pyright", "pytest", diff --git a/tests/tests_client/__init__.py b/tests/tests_client/__init__.py index 89a454f..d461e5f 100644 --- a/tests/tests_client/__init__.py +++ b/tests/tests_client/__init__.py @@ -1,7 +1,7 @@ import asyncio import aiohttp -import asynctest as mock +from unittest.mock import patch from peony import BasePeonyClient, PeonyClient, utils @@ -51,7 +51,7 @@ async def request(self, *args, **kwargs): async def __aenter__(self): self.session = aiohttp.ClientSession() - self.patch = mock.patch.object(self.session, "request") + self.patch = patch.object(self.session, "request") self.patch.__enter__() return await super().__aenter__() @@ -70,7 +70,7 @@ async def request(self, *args, **kwargs): async def __aenter__(self): self.session = aiohttp.ClientSession() - self.patch = mock.patch.object(self.session, "request") + self.patch = patch.object(self.session, "request") self.patch.__enter__() return await super().__aenter__() diff --git a/tests/tests_client/test_upload.py b/tests/tests_client/test_upload.py index c023f67..e6048f5 100644 --- a/tests/tests_client/test_upload.py +++ b/tests/tests_client/test_upload.py @@ -4,11 +4,11 @@ import io import random import tempfile +from unittest.mock import patch import aiofiles import aiohttp import pytest -from asynctest import patch import peony import peony.exceptions @@ -51,9 +51,7 @@ async def dummy_upload(url, method, future, data, skip_params): assert skip_params is True future.set_result(None) - with patch.object( - dummy_peony_client, "request", side_effect=dummy_upload - ) as req: + with patch.object(dummy_peony_client, "request", side_effect=dummy_upload) as req: await dummy_peony_client.upload_media(media, chunked=False) assert req.called @@ -116,9 +114,7 @@ def __init__(self, client, media, chunk_size=1024**2, fail=False): self.media_id = random.randrange(1 << 16) self.fail = fail - async def __call__( - self, url, method, future, data=None, skip_params=None, params=None - ): + async def __call__(self, url, method, future, data=None, skip_params=None, params=None): if url == self.client.api.account.verify_credentials.url(): return assert url == self.client.upload.media.upload.url() @@ -186,9 +182,7 @@ async def chunked_upload(media, file): with patch.object(dummy_peony_client, "request", side_effect=dummy_request): with patch.object(asyncio, "sleep") as sleep: - await dummy_peony_client.upload_media( - file, chunk_size=chunk_size, chunked=True - ) + await dummy_peony_client.upload_media(file, chunk_size=chunk_size, chunked=True) if media.filename == "video": sleep.assert_called_with(5) @@ -243,9 +237,7 @@ async def test_chunked_upload_fail(medias): with patch.object(client, "request", side_effect=dummy_request): with patch.object(asyncio, "sleep") as sleep: with pytest.raises(peony.exceptions.MediaProcessingError): - await client.upload_media( - media_data, chunk_size=chunk_size, chunked=True - ) + await client.upload_media(media_data, chunk_size=chunk_size, chunked=True) sleep.assert_called_with(5) @@ -291,9 +283,7 @@ async def dummy_request(url, method, future, data=None, skip_params=None): with patch.object(dummy_peony_client, "_session") as session: session.get = dummy_get - with patch.object( - dummy_peony_client, "request", side_effect=dummy_request - ): + with patch.object(dummy_peony_client, "request", side_effect=dummy_request): await dummy_peony_client.upload_media(url, chunked=False)