From e065285857b7d6df4b85d742220caf0d1c0d9a3b Mon Sep 17 00:00:00 2001 From: Oleg A Date: Sun, 18 Sep 2022 15:32:42 +0300 Subject: [PATCH] fix: recover tests (#1004) - applied pytest_async; - fixed requirements; - minor typos; --- dev_requirements.txt | 32 +++++++++---------- tests/conftest.py | 5 +-- tests/contrib/fsm_storage/test_storage.py | 13 +++++--- tests/test_bot.py | 3 +- tests/test_bot/test_bot_download_file.py | 3 +- .../test_filters/test_state.py | 8 ++--- tests/test_message.py | 12 +++---- tests/test_utils/test_auth_widget.py | 4 +-- tests/test_utils/test_markdown.py | 10 +++--- tests/types/dataset.py | 2 +- tests/types/test_mixins.py | 3 +- 11 files changed, 49 insertions(+), 46 deletions(-) diff --git a/dev_requirements.txt b/dev_requirements.txt index 26e410aa..01b4c76e 100644 --- a/dev_requirements.txt +++ b/dev_requirements.txt @@ -1,19 +1,19 @@ -r requirements.txt -ujson>=1.35 -python-rapidjson>=0.7.0 -emoji>=0.5.2 -pytest>=6.2.1 -pytest-asyncio>=0.10.0 -tox>=3.9.0 -aresponses>=1.1.1 -aioredis>=1.2.0 -wheel>=0.31.1 -sphinx>=2.0.1 -sphinx-rtd-theme>=0.4.3 -sphinxcontrib-programoutput>=0.14 -aiohttp-socks>=0.3.4 -rethinkdb>=2.4.1 -coverage==4.5.3 -motor>=2.2.0 +ujson==5.5.* +python-rapidjson==1.8 +emoji==2.1.* +pytest==7.1.* +pytest-asyncio==0.19.* +tox==3.26.* +aresponses==2.1.* +aioredis==2.0.* +wheel>=0.31.* +Sphinx==5.1.* +sphinx-rtd-theme==1.0.* +sphinxcontrib-programoutput==0.17 +aiohttp-socks==0.7.* +rethinkdb==2.4.* +coverage==6.4.* +motor==3.0.* pytest-lazy-fixture==0.6.* diff --git a/tests/conftest.py b/tests/conftest.py index 455f8b0d..b2581bd9 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,4 +1,5 @@ import asyncio +import pytest_asyncio import aioredis import pytest @@ -57,7 +58,7 @@ def pytest_collection_modifyitems(config, items): raise UsageError(f"Invalid redis URI {redis_uri!r}: {e}") -@pytest.fixture(scope='session') +@pytest_asyncio.fixture(scope='session') def redis_options(request): redis_uri = request.config.getoption("--redis") if redis_uri is None: @@ -79,7 +80,7 @@ def redis_options(request): raise UsageError("Unsupported aioredis version") -@pytest.fixture(name='bot') +@pytest_asyncio.fixture(name='bot') async def bot_fixture(): """Bot fixture.""" bot = Bot(TOKEN) diff --git a/tests/contrib/fsm_storage/test_storage.py b/tests/contrib/fsm_storage/test_storage.py index 2668cdab..ae06025c 100644 --- a/tests/contrib/fsm_storage/test_storage.py +++ b/tests/contrib/fsm_storage/test_storage.py @@ -1,11 +1,13 @@ import aioredis import pytest +import pytest_asyncio from pytest_lazyfixture import lazy_fixture + from aiogram.contrib.fsm_storage.memory import MemoryStorage from aiogram.contrib.fsm_storage.redis import RedisStorage, RedisStorage2 -@pytest.fixture() +@pytest_asyncio.fixture() @pytest.mark.redis async def redis_store(redis_options): if int(aioredis.__version__.split(".")[0]) == 2: @@ -21,7 +23,7 @@ async def redis_store(redis_options): await s.wait_closed() -@pytest.fixture() +@pytest_asyncio.fixture() @pytest.mark.redis async def redis_store2(redis_options): s = RedisStorage2(**redis_options) @@ -34,7 +36,7 @@ async def redis_store2(redis_options): await s.wait_closed() -@pytest.fixture() +@pytest_asyncio.fixture() async def memory_store(): yield MemoryStorage() @@ -79,6 +81,9 @@ class TestRedisStorage2: pool_id = id(store._redis) await store.close() await store.wait_closed() + + # new pool will be open at this point assert await store.get_data(chat='1234') == { - 'foo': 'bar'} # new pool was opened at this point + 'foo': 'bar', + } assert id(store._redis) != pool_id diff --git a/tests/test_bot.py b/tests/test_bot.py index eea20b44..9e4d45de 100644 --- a/tests/test_bot.py +++ b/tests/test_bot.py @@ -1,7 +1,7 @@ import pytest from aiogram import Bot, types -from . import FakeTelegram, TOKEN, BOT_ID +from . import BOT_ID, FakeTelegram pytestmark = pytest.mark.asyncio @@ -542,5 +542,4 @@ async def test_set_sticker_set_thumb(bot: Bot): async def test_bot_id(bot: Bot): """ Check getting id from token. """ - bot = Bot(TOKEN) assert bot.id == BOT_ID # BOT_ID is a correct id from TOKEN diff --git a/tests/test_bot/test_bot_download_file.py b/tests/test_bot/test_bot_download_file.py index 11b16934..c5b5077c 100644 --- a/tests/test_bot/test_bot_download_file.py +++ b/tests/test_bot/test_bot_download_file.py @@ -4,6 +4,7 @@ from pathlib import Path from unittest.mock import AsyncMock import pytest +import pytest_asyncio from aiohttp import ClientResponseError from aiogram import Bot @@ -15,7 +16,7 @@ from tests.types.dataset import FILE pytestmark = pytest.mark.asyncio -@pytest.fixture(name='bot') +@pytest_asyncio.fixture(name='bot') async def bot_fixture(): """ Bot fixture """ _bot = Bot(TOKEN) diff --git a/tests/test_dispatcher/test_filters/test_state.py b/tests/test_dispatcher/test_filters/test_state.py index b7f5a5fd..7789398e 100644 --- a/tests/test_dispatcher/test_filters/test_state.py +++ b/tests/test_dispatcher/test_filters/test_state.py @@ -1,9 +1,9 @@ from aiogram.dispatcher.filters.state import StatesGroup + class TestStatesGroup: - def test_all_childs(self): - + def test_all_children(self): class InnerState1(StatesGroup): pass @@ -14,5 +14,5 @@ class TestStatesGroup: inner1 = InnerState1 inner2 = InnerState2 - form_childs = Form.all_childs - assert form_childs == (InnerState1, InnerState2) + form_children = Form.all_childs + assert form_children == (InnerState1, InnerState2) diff --git a/tests/test_message.py b/tests/test_message.py index bc53dfbc..aea11302 100644 --- a/tests/test_message.py +++ b/tests/test_message.py @@ -1,23 +1,21 @@ -from asyncio import BaseEventLoop - import pytest +import pytest_asyncio from aiogram import Bot, types -from . import FakeTelegram, TOKEN +from . import FakeTelegram pytestmark = pytest.mark.asyncio -@pytest.fixture() -async def message(bot: Bot): +@pytest_asyncio.fixture(name="message") +async def message_fixture(bot: Bot): """ Message fixture :param bot: Telegram bot fixture :type bot: Bot - :param event_loop: asyncio event loop - :type event_loop: BaseEventLoop """ from .types.dataset import MESSAGE + msg = types.Message(**MESSAGE) async with FakeTelegram(message_data=MESSAGE): diff --git a/tests/test_utils/test_auth_widget.py b/tests/test_utils/test_auth_widget.py index 8c6f5941..91ef325f 100644 --- a/tests/test_utils/test_auth_widget.py +++ b/tests/test_utils/test_auth_widget.py @@ -1,7 +1,6 @@ import pytest -from aiogram.utils.auth_widget import check_integrity, \ - generate_hash, check_token +from aiogram.utils.auth_widget import check_integrity, check_token, generate_hash TOKEN = '123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11' @@ -28,6 +27,7 @@ class Test_check_token: """ This case gonna be deleted """ + def test_ok(self, data): assert check_token(data, TOKEN) is True diff --git a/tests/test_utils/test_markdown.py b/tests/test_utils/test_markdown.py index 02faea2a..a2de0aad 100644 --- a/tests/test_utils/test_markdown.py +++ b/tests/test_utils/test_markdown.py @@ -1,11 +1,9 @@ -import pytest - from aiogram.utils import markdown class TestMarkdownEscape: - def test_equality_sign_is_escaped(self): - assert markdown.escape_md(r"e = mc2") == r"e \= mc2" + def test_equality_sign_is_escaped(self): + assert markdown.escape_md(r"e = mc2") == r"e \= mc2" - def test_pre_escaped(self): - assert markdown.escape_md(r"hello\.") == r"hello\\\." + def test_pre_escaped(self): + assert markdown.escape_md(r"hello\.") == r"hello\\\." diff --git a/tests/types/dataset.py b/tests/types/dataset.py index bd73f377..093c2ea5 100644 --- a/tests/types/dataset.py +++ b/tests/types/dataset.py @@ -110,7 +110,7 @@ ENTITY_LINK = { "offset": 10, "length": 6, "type": "text_link", - "url": "http://google.com/", + "url": "https://google.com/", } ENTITY_CODE = { diff --git a/tests/types/test_mixins.py b/tests/types/test_mixins.py index c3f816c8..84ec991a 100644 --- a/tests/types/test_mixins.py +++ b/tests/types/test_mixins.py @@ -4,6 +4,7 @@ from pathlib import Path from unittest.mock import AsyncMock import pytest +import pytest_asyncio from aiohttp import ClientResponseError from aiogram import Bot @@ -16,7 +17,7 @@ from tests.types.dataset import FILE pytestmark = pytest.mark.asyncio -@pytest.fixture(name='bot') +@pytest_asyncio.fixture(name='bot') async def bot_fixture(): """ Bot fixture """ _bot = Bot(TOKEN)