Skip to content

Commit

Permalink
remove asynctest
Browse files Browse the repository at this point in the history
  • Loading branch information
odrling committed Jan 10, 2024
1 parent b157f7c commit dfe5a3f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 20 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ tests = [
"python-magic",
"python-magic-bin; platform_system == 'Windows'",
# test dependencies
"asynctest",
"codecov",
"pyright",
"pytest",
Expand Down
6 changes: 3 additions & 3 deletions tests/tests_client/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import asyncio

import aiohttp
import asynctest as mock
from unittest.mock import patch

from peony import BasePeonyClient, PeonyClient, utils

Expand Down Expand Up @@ -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__()
Expand All @@ -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__()
Expand Down
22 changes: 6 additions & 16 deletions tests/tests_client/test_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)


Expand Down Expand Up @@ -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)


Expand Down

0 comments on commit dfe5a3f

Please sign in to comment.