fix: recover tests (#1004)

- applied pytest_async;
- fixed requirements;
- minor typos;
This commit is contained in:
Oleg A 2022-09-18 15:32:42 +03:00 committed by GitHub
parent 96ebee26e4
commit e065285857
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 49 additions and 46 deletions

View file

@ -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.*

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -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)

View file

@ -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):

View file

@ -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

View file

@ -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\\\."

View file

@ -110,7 +110,7 @@ ENTITY_LINK = {
"offset": 10,
"length": 6,
"type": "text_link",
"url": "http://google.com/",
"url": "https://google.com/",
}
ENTITY_CODE = {

View file

@ -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)