mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-12 10:11:52 +00:00
refactor: remove redundant pytest marks (#654)
This commit is contained in:
parent
fff33e4ac9
commit
f2f276b8cf
111 changed files with 221 additions and 256 deletions
|
|
@ -16,6 +16,8 @@ except ImportError:
|
|||
from unittest.mock import AsyncMock as CoroutineMock # type: ignore
|
||||
from unittest.mock import patch
|
||||
|
||||
pytestmark = pytest.mark.asyncio
|
||||
|
||||
|
||||
class TestBot:
|
||||
def test_init(self):
|
||||
|
|
@ -32,7 +34,6 @@ class TestBot:
|
|||
assert bot == Bot("42:TEST")
|
||||
assert bot != "42:TEST"
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_emit(self):
|
||||
bot = Bot("42:TEST")
|
||||
|
||||
|
|
@ -45,7 +46,6 @@ class TestBot:
|
|||
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)
|
||||
|
|
@ -57,7 +57,6 @@ class TestBot:
|
|||
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(
|
||||
|
|
@ -70,7 +69,6 @@ class TestBot:
|
|||
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)
|
||||
|
|
@ -88,7 +86,6 @@ class TestBot:
|
|||
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")
|
||||
|
||||
|
|
@ -101,7 +98,6 @@ class TestBot:
|
|||
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")
|
||||
|
||||
|
|
@ -117,7 +113,6 @@ class TestBot:
|
|||
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")
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@ except ImportError:
|
|||
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):
|
||||
|
|
@ -27,7 +29,6 @@ class BareInputFile(InputFile):
|
|||
|
||||
|
||||
class TestAiohttpSession:
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_session(self):
|
||||
session = AiohttpSession()
|
||||
|
||||
|
|
@ -36,7 +37,6 @@ class TestAiohttpSession:
|
|||
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"))
|
||||
|
|
@ -50,7 +50,6 @@ class TestAiohttpSession:
|
|||
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/")
|
||||
|
||||
|
|
@ -62,7 +61,6 @@ class TestAiohttpSession:
|
|||
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=[
|
||||
|
|
@ -89,7 +87,6 @@ class TestAiohttpSession:
|
|||
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
|
||||
|
|
@ -105,7 +102,6 @@ class TestAiohttpSession:
|
|||
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()
|
||||
|
|
@ -153,7 +149,6 @@ class TestAiohttpSession:
|
|||
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,
|
||||
|
|
@ -181,7 +176,6 @@ class TestAiohttpSession:
|
|||
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")
|
||||
|
||||
|
|
@ -196,7 +190,6 @@ class TestAiohttpSession:
|
|||
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)
|
||||
|
|
@ -216,7 +209,6 @@ class TestAiohttpSession:
|
|||
size += chunk_size
|
||||
assert size == 10
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_context_manager(self):
|
||||
session = AiohttpSession()
|
||||
assert isinstance(session, AsyncContextManager)
|
||||
|
|
|
|||
|
|
@ -25,6 +25,8 @@ except ImportError:
|
|||
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):
|
||||
|
|
@ -195,13 +197,11 @@ class TestBaseSession:
|
|||
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(
|
||||
|
|
@ -212,7 +212,6 @@ class TestBaseSession:
|
|||
async for chunk in stream:
|
||||
assert isinstance(chunk, bytes)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_context_manager(self):
|
||||
session = CustomSession()
|
||||
assert isinstance(session, AsyncContextManager)
|
||||
|
|
@ -236,7 +235,6 @@ class TestBaseSession:
|
|||
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue