Skip to content

Commit

Permalink
test: Migrate to pytest-asyncio 0.24 (#361)
Browse files Browse the repository at this point in the history
* refactor: migrate to pytest-asyncio 0.24

* test: fixes oriented to pytest-asyncio 0.24

* doc(readme): fix badge

* doc(readme): add badge

---------

Co-authored-by: JamzumSum <zzzzss990315@gmail.com>
  • Loading branch information
github-actions[bot] and JamzumSum authored Oct 1, 2024
1 parent 917968a commit dbfafd5
Show file tree
Hide file tree
Showing 10 changed files with 620 additions and 598 deletions.
7 changes: 4 additions & 3 deletions README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

Forward Qzone feeds to telegram.

[![Sphinx](https://img.shields.io/github/actions/workflow/status/aioqzone/Qzone2TG/sphinx.yml?label=Sphinx&logo=github)][doc]
[![ghcr.io](https://img.shields.io/github/actions/workflow/status/aioqzone/Qzone2TG/docker.yml?label=ghcr.io&logo=docker)][ghcr]
[![channel](https://img.shields.io/badge/dynamic/xml?label=Channel&query=%2F%2Fdiv%5B%40class%3D%22tgme_page_extra%22%5D&url=https%3A%2F%2Ft.me%2Fqzone2tg&style=social&logo=telegram)](https://t.me/qzone2tg)
[![latest](https://ghcr-badge.egpl.dev/aioqzone/qzone3tg/latest_tag?trim=major&label=Latest%20Image)][ghcr]
[![Sphinx](https://img.shields.io/github/actions/workflow/status/aioqzone/Qzone2TG/sphinx.yml?label=Sphinx&logo=github)][doc]
[![channel](https://img.shields.io/endpoint?label=Channel&style=social&url=https%3A%2F%2Ftg.sumanjay.workers.dev%2Fqzone2tg)](https://t.me/qzone2tg)

> [!WARNING]
> Qzone3TG is still under active development. Features and configurations may be changed in future releases.
Expand Down Expand Up @@ -41,7 +42,7 @@ Since environment variable style configuration is fully supported, one can merge
## License

```
Copyright (C) 2021-2023 aioqzone
Copyright (C) 2021-2024 aioqzone
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

转发说说到 Telegram.

[![Sphinx](https://img.shields.io/github/actions/workflow/status/aioqzone/Qzone2TG/sphinx.yml?label=Sphinx&logo=github)][doc]
[![ghcr.io](https://img.shields.io/github/actions/workflow/status/aioqzone/Qzone2TG/docker.yml?label=ghcr.io&logo=docker)][ghcr]
[![channel](https://img.shields.io/badge/dynamic/xml?label=Channel&query=%2F%2Fdiv%5B%40class%3D%22tgme_page_extra%22%5D&url=https%3A%2F%2Ft.me%2Fqzone2tg&style=social&logo=telegram)](https://t.me/qzone2tg)
[![latest](https://ghcr-badge.egpl.dev/aioqzone/qzone3tg/latest_tag?trim=major&label=Latest%20Image)][ghcr]
[![Sphinx](https://img.shields.io/github/actions/workflow/status/aioqzone/Qzone2TG/sphinx.yml?label=Sphinx&logo=github)][doc]
[![channel](https://img.shields.io/endpoint?label=Channel&style=social&url=https%3A%2F%2Ftg.sumanjay.workers.dev%2Fqzone2tg)](https://t.me/qzone2tg)

> [!WARNING]
> Qzone3TG 仍在开发阶段,任何功能和配置项都有可能在未来的版本中发生变化。
Expand Down Expand Up @@ -43,7 +44,7 @@ Qzone3TG 使用 [pydantic](https://pydantic-docs.helpmanual.io/usage/settings)
## License

```
Copyright (C) 2021-2023 aioqzone
Copyright (C) 2021-2024 aioqzone
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
Expand Down
1,126 changes: 575 additions & 551 deletions poetry.lock

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "Qzone3TG"
version = "0.9.9.dev11"
version = "0.9.9.dev13"
description = "Forward Qzone feeds to telegram."
authors = ["aioqzone <zzzzss990315@gmail.com>"]
readme = "README.md"
Expand All @@ -26,7 +26,7 @@ optional = false

[tool.poetry.group.test.dependencies]
pytest = "^8.2.0"
pytest-asyncio = "~0.21.2"
pytest-asyncio = "~0.24.0"

[tool.poetry.group.dev]
optional = true
Expand Down Expand Up @@ -61,9 +61,10 @@ build-backend = "poetry.core.masonry.api"

# customize begin
[tool.pytest.ini_options]
asyncio_default_fixture_loop_scope = "function"
log_cli_level = 'WARNING'
pythonpath = 'src'
log_cli = 1
log_cli_level = 'WARNING'

[tool.isort]
profile = "black"
Expand Down
9 changes: 6 additions & 3 deletions test/bot/test_atom.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
import pytest_asyncio
from aiogram.types import InputMedia
from qqqr.utils.net import ClientAdapter
from qzemoji.utils import build_html
Expand All @@ -16,9 +17,10 @@ def local():
return LocalSplitter()


@pytest.fixture(scope="class")
def fetch(client: ClientAdapter):
return FetchSplitter(client)
@pytest_asyncio.fixture(scope="class", loop_scope="class")
async def fetch():
async with ClientAdapter() as client:
yield FetchSplitter(client)


class TestLocal:
Expand Down Expand Up @@ -81,6 +83,7 @@ async def test_media_group_exd(self, local: LocalSplitter):
assert all(isinstance(i, InputMedia) for i in medias)


@pytest.mark.asyncio(loop_scope="class")
class TestFetch:
async def test_media_norm(self, fetch: FetchSplitter):
f = fake_feed(1)
Expand Down
15 changes: 11 additions & 4 deletions test/bot/test_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from unittest.mock import patch

import pytest
import pytest_asyncio
from aiogram import Bot
from aiogram.exceptions import TelegramBadRequest
from aiogram.types import InlineKeyboardMarkup
Expand All @@ -23,15 +24,21 @@ def fake_bot():
return FakeBot()


@pytest.fixture
def queue(client: ClientAdapter, fake_bot: Bot) -> SendQueue:
q = SendQueue(fake_bot, FetchSplitter(client), defaultdict(int))
@pytest_asyncio.fixture(loop_scope="function")
async def fetch():
async with ClientAdapter() as client:
yield FetchSplitter(client)


@pytest_asyncio.fixture(loop_scope="function")
async def queue(fetch: FetchSplitter, fake_bot: Bot):
q = SendQueue(fake_bot, fetch, defaultdict(int))

async def _unified_markup(feed):
return InlineKeyboardMarkup(inline_keyboard=[])

q.reply_markup = _unified_markup
return q
yield q


class TestQueue:
Expand Down
8 changes: 5 additions & 3 deletions test/bot/test_splitter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Callable

import pytest
import pytest_asyncio
from aiogram.types import BufferedInputFile
from qqqr.utils.net import ClientAdapter
from qzemoji.utils import build_html
Expand All @@ -27,9 +28,10 @@ def local():
return LocalSplitter()


@pytest.fixture(scope="class")
def fetch(client: ClientAdapter):
return FetchSplitter(client)
@pytest_asyncio.fixture(loop_scope="function")
async def fetch():
async with ClientAdapter() as client:
yield FetchSplitter(client)


class TestLocal:
Expand Down
19 changes: 0 additions & 19 deletions test/conftest.py

This file was deleted.

2 changes: 1 addition & 1 deletion test/test_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def minc():
return Settings(**mind).load_secrets()


@pytest_asyncio.fixture(scope="module")
@pytest_asyncio.fixture(scope="module", loop_scope="module")
async def engine():
async with AsyncEngineFactory.sqlite3(None) as engine:
yield engine
Expand Down
18 changes: 10 additions & 8 deletions test/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def fixed():
return l


@pytest_asyncio.fixture(scope="class")
@pytest_asyncio.fixture(scope="class", loop_scope="class")
async def engine():
db = Path("tmp/tmp.db")
db.unlink(missing_ok=True)
Expand All @@ -36,28 +36,29 @@ async def engine():
db.unlink(missing_ok=True)


@pytest_asyncio.fixture(scope="class")
@pytest_asyncio.fixture(loop_scope="class")
async def store(engine: AsyncEngine):
s = StorageMan(engine)
await s.create()
yield s


@pytest.fixture(scope="class")
def app(store: StorageMan):
@pytest_asyncio.fixture(loop_scope="class")
async def app(store: StorageMan):
class fake_app(StorageMixin):
def __init__(self, store) -> None:
self.store = store

return fake_app(store)


@pytest.fixture(scope="class")
def login(client: ClientAdapter, engine: AsyncEngine):
return LoginManager(client, engine, QrLoginConfig(uin=123), UpLoginConfig(uin=123))
@pytest_asyncio.fixture(scope="class", loop_scope="class")
async def login(engine: AsyncEngine):
async with ClientAdapter() as client:
yield LoginManager(client, engine, QrLoginConfig(uin=123), UpLoginConfig(uin=123))


@pytest_asyncio.fixture(scope="class")
@pytest_asyncio.fixture(loop_scope="class")
async def blockset(engine: AsyncEngine):
s = BlockSet(engine)
await s.create()
Expand Down Expand Up @@ -94,6 +95,7 @@ async def test_remove(self, store: StorageMan, fixed: list):
assert not await store.get_msg_orms(MessageOrm.mid == 1)


@pytest.mark.asyncio(loop_scope="class")
class TestCookieStore:
async def test_loginman_miss(self, login: LoginManager):
cookie = dict(errno="12")
Expand Down

0 comments on commit dbfafd5

Please sign in to comment.