Skip to content

Commit

Permalink
refactor: remove redundant pytest marks (#654)
Browse files Browse the repository at this point in the history
  • Loading branch information
Olegt0rr committed Aug 3, 2021
1 parent fff33e4 commit f2f276b
Show file tree
Hide file tree
Showing 111 changed files with 221 additions and 256 deletions.
9 changes: 2 additions & 7 deletions tests/test_api/test_client/test_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
from unittest.mock import AsyncMock as CoroutineMock # type: ignore
from unittest.mock import patch

pytestmark = pytest.mark.asyncio


class TestBot:
def test_init(self):
Expand All @@ -32,7 +34,6 @@ def test_equals(self):
assert bot == Bot("42:TEST")
assert bot != "42:TEST"

@pytest.mark.asyncio
async def test_emit(self):
bot = Bot("42:TEST")

Expand All @@ -45,7 +46,6 @@ async def test_emit(self):
await bot(method)
mocked_make_request.assert_awaited_with(bot, method, timeout=None)

@pytest.mark.asyncio
async def test_close(self):
session = AiohttpSession()
bot = Bot("42:TEST", session=session)
Expand All @@ -57,7 +57,6 @@ async def test_close(self):
await bot.session.close()
mocked_close.assert_awaited()

@pytest.mark.asyncio
@pytest.mark.parametrize("close", [True, False])
async def test_context_manager(self, close: bool):
with patch(
Expand All @@ -70,7 +69,6 @@ async def test_context_manager(self, close: bool):
else:
mocked_close.assert_not_awaited()

@pytest.mark.asyncio
async def test_download_file(self, aresponses: ResponsesMockServer):
aresponses.add(
aresponses.ANY, aresponses.ANY, "get", aresponses.Response(status=200, body=b"\f" * 10)
Expand All @@ -88,7 +86,6 @@ async def test_download_file(self, aresponses: ResponsesMockServer):
await bot.download_file("TEST", "file.png")
mock_file.write.assert_called_once_with(b"\f" * 10)

@pytest.mark.asyncio
async def test_download_file_default_destination(self, aresponses: ResponsesMockServer):
bot = Bot("42:TEST")

Expand All @@ -101,7 +98,6 @@ async def test_download_file_default_destination(self, aresponses: ResponsesMock
assert isinstance(result, io.BytesIO)
assert result.read() == b"\f" * 10

@pytest.mark.asyncio
async def test_download_file_custom_destination(self, aresponses: ResponsesMockServer):
bot = Bot("42:TEST")

Expand All @@ -117,7 +113,6 @@ async def test_download_file_custom_destination(self, aresponses: ResponsesMockS
assert result is custom
assert result.read() == b"\f" * 10

@pytest.mark.asyncio
async def test_download(self, bot: MockedBot, aresponses: ResponsesMockServer):
bot.add_result_for(
GetFile, ok=True, result=File(file_id="file id", file_unique_id="file id")
Expand Down
12 changes: 2 additions & 10 deletions tests/test_api/test_client/test_session/test_aiohttp_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@
from unittest.mock import AsyncMock as CoroutineMock # type: ignore
from unittest.mock import patch

pytestmark = pytest.mark.asyncio


class BareInputFile(InputFile):
async def read(self, chunk_size: int):
yield b""


class TestAiohttpSession:
@pytest.mark.asyncio
async def test_create_session(self):
session = AiohttpSession()

Expand All @@ -36,7 +37,6 @@ async def test_create_session(self):
assert session._session is not None
assert isinstance(aiohttp_session, aiohttp.ClientSession)

@pytest.mark.asyncio
async def test_create_proxy_session(self):
session = AiohttpSession(
proxy=("socks5://proxy.url/", aiohttp.BasicAuth("login", "password", "encoding"))
Expand All @@ -50,7 +50,6 @@ async def test_create_proxy_session(self):
aiohttp_session = await session.create_session()
assert isinstance(aiohttp_session.connector, aiohttp_socks.ProxyConnector)

@pytest.mark.asyncio
async def test_create_proxy_session_proxy_url(self):
session = AiohttpSession(proxy="socks4://proxy.url/")

Expand All @@ -62,7 +61,6 @@ async def test_create_proxy_session_proxy_url(self):
aiohttp_session = await session.create_session()
assert isinstance(aiohttp_session.connector, aiohttp_socks.ProxyConnector)

@pytest.mark.asyncio
async def test_create_proxy_session_chained_proxies(self):
session = AiohttpSession(
proxy=[
Expand All @@ -89,7 +87,6 @@ async def test_create_proxy_session_chained_proxies(self):
aiohttp_session = await session.create_session()
assert isinstance(aiohttp_session.connector, aiohttp_socks.ChainProxyConnector)

@pytest.mark.asyncio
async def test_reset_connector(self):
session = AiohttpSession()
assert session._should_reset_connector
Expand All @@ -105,7 +102,6 @@ async def test_reset_connector(self):
assert session._should_reset_connector is False
await session.close()

@pytest.mark.asyncio
async def test_close_session(self):
session = AiohttpSession()
await session.create_session()
Expand Down Expand Up @@ -153,7 +149,6 @@ def test_build_form_data_with_files(self):
assert fields[1][0]["filename"] == "file.txt"
assert isinstance(fields[1][2], BareInputFile)

@pytest.mark.asyncio
async def test_make_request(self, bot: MockedBot, aresponses: ResponsesMockServer):
aresponses.add(
aresponses.ANY,
Expand Down Expand Up @@ -181,7 +176,6 @@ def build_request(self, bot: Bot) -> Request:
assert result == 42

@pytest.mark.parametrize("error", [ClientError("mocked"), asyncio.TimeoutError()])
@pytest.mark.asyncio
async def test_make_request_network_error(self, error):
bot = Bot("42:TEST")

Expand All @@ -196,7 +190,6 @@ async def side_effect(*args, **kwargs):
with pytest.raises(NetworkError):
await bot.get_me()

@pytest.mark.asyncio
async def test_stream_content(self, aresponses: ResponsesMockServer):
aresponses.add(
aresponses.ANY, aresponses.ANY, "get", aresponses.Response(status=200, body=b"\f" * 10)
Expand All @@ -216,7 +209,6 @@ async def test_stream_content(self, aresponses: ResponsesMockServer):
size += chunk_size
assert size == 10

@pytest.mark.asyncio
async def test_context_manager(self):
session = AiohttpSession()
assert isinstance(session, AsyncContextManager)
Expand Down
6 changes: 2 additions & 4 deletions tests/test_api/test_client/test_session/test_base_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
from unittest.mock import AsyncMock as CoroutineMock # type: ignore
from unittest.mock import patch

pytestmark = pytest.mark.asyncio


class CustomSession(BaseSession):
async def close(self):
Expand Down Expand Up @@ -195,13 +197,11 @@ def test_check_response(self, status_code, content, error):
if error.url:
assert error.url in string

@pytest.mark.asyncio
async def test_make_request(self):
session = CustomSession()

assert await session.make_request("42:TEST", GetMe()) is None

@pytest.mark.asyncio
async def test_stream_content(self):
session = CustomSession()
stream = session.stream_content(
Expand All @@ -212,7 +212,6 @@ async def test_stream_content(self):
async for chunk in stream:
assert isinstance(chunk, bytes)

@pytest.mark.asyncio
async def test_context_manager(self):
session = CustomSession()
assert isinstance(session, AsyncContextManager)
Expand All @@ -236,7 +235,6 @@ async def my_middleware(bot, method, make_request):
assert my_middleware in session.middlewares
assert len(session.middlewares) == 1

@pytest.mark.asyncio
async def test_use_middleware(self, bot: MockedBot):
flag_before = False
flag_after = False
Expand Down
4 changes: 2 additions & 2 deletions tests/test_api/test_methods/test_add_sticker_to_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
from aiogram.methods import AddStickerToSet, Request
from tests.mocked_bot import MockedBot

pytestmark = pytest.mark.asyncio


class TestAddStickerToSet:
@pytest.mark.asyncio
async def test_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(AddStickerToSet, ok=True, result=True)

Expand All @@ -16,7 +17,6 @@ async def test_method(self, bot: MockedBot):
assert request.method == "addStickerToSet"
assert response == prepare_result.result

@pytest.mark.asyncio
async def test_bot_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(AddStickerToSet, ok=True, result=True)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_api/test_methods/test_answer_callback_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
from aiogram.methods import AnswerCallbackQuery, Request
from tests.mocked_bot import MockedBot

pytestmark = pytest.mark.asyncio


class TestAnswerCallbackQuery:
@pytest.mark.asyncio
async def test_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(AnswerCallbackQuery, ok=True, result=True)

Expand All @@ -14,7 +15,6 @@ async def test_method(self, bot: MockedBot):
assert request.method == "answerCallbackQuery"
assert response == prepare_result.result

@pytest.mark.asyncio
async def test_bot_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(AnswerCallbackQuery, ok=True, result=True)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_api/test_methods/test_answer_inline_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
from aiogram.types import InlineQueryResult, InlineQueryResultPhoto
from tests.mocked_bot import MockedBot

pytestmark = pytest.mark.asyncio


class TestAnswerInlineQuery:
@pytest.mark.asyncio
async def test_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(AnswerInlineQuery, ok=True, result=True)

Expand All @@ -18,7 +19,6 @@ async def test_method(self, bot: MockedBot):
assert request.method == "answerInlineQuery"
assert response == prepare_result.result

@pytest.mark.asyncio
async def test_bot_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(AnswerInlineQuery, ok=True, result=True)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_api/test_methods/test_answer_pre_checkout_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
from aiogram.methods import AnswerPreCheckoutQuery, Request
from tests.mocked_bot import MockedBot

pytestmark = pytest.mark.asyncio


class TestAnswerPreCheckoutQuery:
@pytest.mark.asyncio
async def test_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(AnswerPreCheckoutQuery, ok=True, result=True)

Expand All @@ -14,7 +15,6 @@ async def test_method(self, bot: MockedBot):
assert request.method == "answerPreCheckoutQuery"
assert response == prepare_result.result

@pytest.mark.asyncio
async def test_bot_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(AnswerPreCheckoutQuery, ok=True, result=True)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_api/test_methods/test_answer_shipping_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
from aiogram.methods import AnswerShippingQuery, Request
from tests.mocked_bot import MockedBot

pytestmark = pytest.mark.asyncio


class TestAnswerShippingQuery:
@pytest.mark.asyncio
async def test_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(AnswerShippingQuery, ok=True, result=True)

Expand All @@ -14,7 +15,6 @@ async def test_method(self, bot: MockedBot):
assert request.method == "answerShippingQuery"
assert response == prepare_result.result

@pytest.mark.asyncio
async def test_bot_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(AnswerShippingQuery, ok=True, result=True)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_api/test_methods/test_ban_chat_member.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
from aiogram.methods import BanChatMember, Request
from tests.mocked_bot import MockedBot

pytestmark = pytest.mark.asyncio


class TestKickChatMember:
@pytest.mark.asyncio
async def test_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(BanChatMember, ok=True, result=True)

Expand All @@ -14,7 +15,6 @@ async def test_method(self, bot: MockedBot):
assert request.method == "banChatMember"
assert response == prepare_result.result

@pytest.mark.asyncio
async def test_bot_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(BanChatMember, ok=True, result=True)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_api/test_methods/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from aiogram.methods.base import prepare_parse_mode
from tests.mocked_bot import MockedBot

pytestmark = pytest.mark.asyncio


class TestPrepareFile:
# TODO: Add tests
Expand Down Expand Up @@ -34,7 +36,6 @@ class TestPrepareParseMode:
["Markdown", {"parse_mode": "HTML"}, "HTML"],
],
)
@pytest.mark.asyncio
async def test_default_parse_mode(
self, bot: MockedBot, parse_mode: str, data: Dict[str, str], result: Optional[str]
):
Expand All @@ -43,7 +44,6 @@ async def test_default_parse_mode(
prepare_parse_mode(bot, data)
assert data.get("parse_mode") == result

@pytest.mark.asyncio
async def test_list(self):
data = [{}] * 2
data.append({"parse_mode": "HTML"})
Expand Down
4 changes: 2 additions & 2 deletions tests/test_api/test_methods/test_close.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
from aiogram.methods import Close, Request
from tests.mocked_bot import MockedBot

pytestmark = pytest.mark.asyncio


class TestClose:
@pytest.mark.asyncio
async def test_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(Close, ok=True, result=True)

Expand All @@ -15,7 +16,6 @@ async def test_method(self, bot: MockedBot):
# assert request.data == {}
assert response == prepare_result.result

@pytest.mark.asyncio
async def test_bot_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(Close, ok=True, result=True)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_api/test_methods/test_copy_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
from aiogram.types import MessageId
from tests.mocked_bot import MockedBot

pytestmark = pytest.mark.asyncio


class TestCopyMessage:
@pytest.mark.asyncio
async def test_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(CopyMessage, ok=True, result=MessageId(message_id=42))

Expand All @@ -20,7 +21,6 @@ async def test_method(self, bot: MockedBot):
# assert request.data == {}
assert response == prepare_result.result

@pytest.mark.asyncio
async def test_bot_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(CopyMessage, ok=True, result=MessageId(message_id=42))

Expand Down
4 changes: 2 additions & 2 deletions tests/test_api/test_methods/test_create_chat_invite_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
from aiogram.types import ChatInviteLink, User
from tests.mocked_bot import MockedBot

pytestmark = pytest.mark.asyncio


class TestCreateChatInviteLink:
@pytest.mark.asyncio
async def test_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(
CreateChatInviteLink,
Expand All @@ -27,7 +28,6 @@ async def test_method(self, bot: MockedBot):
# assert request.data == {"chat_id": -42}
assert response == prepare_result.result

@pytest.mark.asyncio
async def test_bot_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(
CreateChatInviteLink,
Expand Down

0 comments on commit f2f276b

Please sign in to comment.