mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Reformat tests code and bump Makefile
This commit is contained in:
parent
98de096f3b
commit
3d17984f59
16 changed files with 57 additions and 72 deletions
53
Makefile
53
Makefile
|
|
@ -4,6 +4,10 @@ base_python := python3
|
|||
py := poetry run
|
||||
python := $(py) python
|
||||
|
||||
package_dir := aiogram
|
||||
tests_dir := tests
|
||||
scripts_dir := scripts
|
||||
code_dir := $(package_dir) $(tests_dir) $(scripts_dir)
|
||||
reports_dir := reports
|
||||
|
||||
redis_connection := redis://localhost:6379
|
||||
|
|
@ -19,13 +23,8 @@ help:
|
|||
@echo " clean: Delete temporary files"
|
||||
@echo ""
|
||||
@echo "Code quality:"
|
||||
@echo " isort: Run isort tool"
|
||||
@echo " black: Run black tool"
|
||||
@echo " flake8: Run flake8 tool"
|
||||
@echo " flake8-report: Run flake8 with HTML reporting"
|
||||
@echo " mypy: Run mypy tool"
|
||||
@echo " mypy-report: Run mypy tool with HTML reporting"
|
||||
@echo " lint: Run isort, black, flake8 and mypy tools"
|
||||
@echo " lint: Lint code by isort, black, flake8 and mypy tools"
|
||||
@echo " reformat: Reformat code by isort and black tools"
|
||||
@echo ""
|
||||
@echo "Tests:"
|
||||
@echo " test: Run tests"
|
||||
|
|
@ -33,8 +32,8 @@ help:
|
|||
@echo " test-coverage-report: Open coverage report in default system web browser"
|
||||
@echo ""
|
||||
@echo "Documentation:"
|
||||
@echo " docs: Build docs"
|
||||
@echo " docs-serve: Serve docs for local development"
|
||||
@echo " docs: Build docs"
|
||||
@echo " docs-serve: Serve docs for local development"
|
||||
@echo " docs-prepare-reports: Move all HTML reports to docs dir"
|
||||
@echo ""
|
||||
@echo "Project"
|
||||
|
|
@ -67,33 +66,17 @@ clean:
|
|||
# Code quality
|
||||
# =================================================================================================
|
||||
|
||||
.PHONY: isort
|
||||
isort:
|
||||
$(py) isort aiogram tests scripts
|
||||
|
||||
.PHONY: black
|
||||
black:
|
||||
$(py) black aiogram tests scripts
|
||||
|
||||
.PHONY: flake8
|
||||
flake8:
|
||||
$(py) flake8 aiogram
|
||||
|
||||
.PHONY: flake8-report
|
||||
flake8-report:
|
||||
mkdir -p $(reports_dir)/flake8
|
||||
$(py) flake8 --format=html --htmldir=$(reports_dir)/flake8 aiogram
|
||||
|
||||
.PHONY: mypy
|
||||
mypy:
|
||||
$(py) mypy aiogram
|
||||
|
||||
.PHONY: mypy-report
|
||||
mypy-report:
|
||||
$(py) mypy aiogram --html-report $(reports_dir)/typechecking
|
||||
|
||||
.PHONY: lint
|
||||
lint: isort black flake8 mypy
|
||||
lint:
|
||||
$(py) isort --check-only $(code_dir)
|
||||
$(py) black --check --diff $(code_dir)
|
||||
$(py) flake8 $(code_dir)
|
||||
$(py) mypy $(package_dir)
|
||||
|
||||
.PHONY: reformat
|
||||
reformat:
|
||||
$(py) black $(code_dir)
|
||||
$(py) isort $(code_dir)
|
||||
|
||||
# =================================================================================================
|
||||
# Tests
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import pytest
|
|||
|
||||
from aiogram.client.session.base import BaseSession, TelegramType
|
||||
from aiogram.client.telegram import PRODUCTION, TelegramAPIServer
|
||||
from aiogram.methods import DeleteMessage, GetMe, Response, TelegramMethod
|
||||
from aiogram.methods import DeleteMessage, GetMe, TelegramMethod
|
||||
from aiogram.types import UNSET
|
||||
|
||||
try:
|
||||
|
|
@ -20,7 +20,9 @@ class CustomSession(BaseSession):
|
|||
async def close(self):
|
||||
pass
|
||||
|
||||
async def make_request(self, token: str, method: TelegramMethod[TelegramType], timeout: Optional[int] = UNSET) -> None: # type: ignore
|
||||
async def make_request(
|
||||
self, token: str, method: TelegramMethod[TelegramType], timeout: Optional[int] = UNSET
|
||||
) -> None: # type: ignore
|
||||
assert isinstance(token, str)
|
||||
assert isinstance(method, TelegramMethod)
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ from typing import Union
|
|||
import pytest
|
||||
|
||||
from aiogram.methods import EditMessageMedia, Request
|
||||
from aiogram.types import BufferedInputFile, InputMedia, InputMediaPhoto, Message
|
||||
from aiogram.types import BufferedInputFile, InputMediaPhoto, Message
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import datetime
|
|||
import pytest
|
||||
|
||||
from aiogram.methods import Request, SendAudio
|
||||
from aiogram.types import Audio, Chat, File, Message
|
||||
from aiogram.types import Audio, Chat, Message
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import pytest
|
||||
|
||||
from aiogram.methods import Request, SetChatAdministratorCustomTitle, SetChatTitle
|
||||
from aiogram.methods import Request, SetChatAdministratorCustomTitle
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import pytest
|
||||
|
||||
from aiogram.methods import Request, SetChatPhoto
|
||||
from aiogram.types import BufferedInputFile, InputFile
|
||||
from aiogram.types import BufferedInputFile
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -9,8 +9,6 @@ import pytest
|
|||
from aiogram import Bot
|
||||
from aiogram.dispatcher.dispatcher import Dispatcher
|
||||
from aiogram.dispatcher.event.bases import UNHANDLED, SkipHandler
|
||||
from aiogram.dispatcher.fsm.strategy import FSMStrategy
|
||||
from aiogram.dispatcher.middlewares.user_context import UserContextMiddleware
|
||||
from aiogram.dispatcher.router import Router
|
||||
from aiogram.methods import GetMe, GetUpdates, SendMessage
|
||||
from aiogram.types import (
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import pytest
|
|||
|
||||
from aiogram import F
|
||||
from aiogram.dispatcher.event.handler import CallableMixin, FilterObject, HandlerObject
|
||||
from aiogram.dispatcher.filters import Text
|
||||
from aiogram.dispatcher.filters.base import BaseFilter
|
||||
from aiogram.dispatcher.handler.base import BaseHandler
|
||||
from aiogram.types import Update
|
||||
|
|
|
|||
|
|
@ -1,12 +1,11 @@
|
|||
import datetime
|
||||
import re
|
||||
from typing import Any, Dict, Match
|
||||
|
||||
import pytest
|
||||
|
||||
from aiogram import F
|
||||
from aiogram.dispatcher.filters import Command, CommandObject
|
||||
from aiogram.dispatcher.filters.command import CommandException, CommandStart
|
||||
from aiogram.dispatcher.filters.command import CommandStart
|
||||
from aiogram.methods import GetMe
|
||||
from aiogram.types import Chat, Message, User
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ from typing import Any
|
|||
import pytest
|
||||
|
||||
from aiogram.dispatcher.handler import ChosenInlineResultHandler
|
||||
from aiogram.types import CallbackQuery, ChosenInlineResult, User
|
||||
from aiogram.types import ChosenInlineResult, User
|
||||
|
||||
|
||||
class TestChosenInlineResultHandler:
|
||||
|
|
|
|||
|
|
@ -2,16 +2,7 @@ from typing import Any
|
|||
|
||||
import pytest
|
||||
|
||||
from aiogram.dispatcher.handler import ErrorHandler, PollHandler
|
||||
from aiogram.types import (
|
||||
CallbackQuery,
|
||||
InlineQuery,
|
||||
Poll,
|
||||
PollOption,
|
||||
ShippingAddress,
|
||||
ShippingQuery,
|
||||
User,
|
||||
)
|
||||
from aiogram.dispatcher.handler import ErrorHandler
|
||||
|
||||
|
||||
class TestErrorHandler:
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ from typing import Any
|
|||
import pytest
|
||||
|
||||
from aiogram.dispatcher.handler import InlineQueryHandler
|
||||
from aiogram.types import CallbackQuery, InlineQuery, User
|
||||
from aiogram.types import InlineQuery, User
|
||||
|
||||
|
||||
class TestCallbackQueryHandler:
|
||||
|
|
|
|||
|
|
@ -3,15 +3,7 @@ from typing import Any
|
|||
import pytest
|
||||
|
||||
from aiogram.dispatcher.handler import PollHandler
|
||||
from aiogram.types import (
|
||||
CallbackQuery,
|
||||
InlineQuery,
|
||||
Poll,
|
||||
PollOption,
|
||||
ShippingAddress,
|
||||
ShippingQuery,
|
||||
User,
|
||||
)
|
||||
from aiogram.types import Poll, PollOption
|
||||
|
||||
|
||||
class TestShippingQueryHandler:
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ from typing import Any
|
|||
import pytest
|
||||
|
||||
from aiogram.dispatcher.handler import ShippingQueryHandler
|
||||
from aiogram.types import CallbackQuery, InlineQuery, ShippingAddress, ShippingQuery, User
|
||||
from aiogram.types import ShippingAddress, ShippingQuery, User
|
||||
|
||||
|
||||
class TestShippingQueryHandler:
|
||||
|
|
|
|||
|
|
@ -7,12 +7,8 @@ from aiogram.utils.deep_linking import (
|
|||
decode_payload,
|
||||
encode_payload,
|
||||
)
|
||||
|
||||
# enable asyncio mode
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
pytestmark = pytest.mark.asyncio
|
||||
|
||||
PAYLOADS = [
|
||||
"foo",
|
||||
"AAbbCCddEEff1122334455",
|
||||
|
|
@ -58,6 +54,7 @@ def get_bot_user_fixture(monkeypatch):
|
|||
monkeypatch.setattr(MockedBot, "me", get_bot_user_mock)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
class TestDeepLinking:
|
||||
async def test_get_start_link(self, bot, payload):
|
||||
link = await create_start_link(bot=bot, payload=payload)
|
||||
|
|
|
|||
24
tests/test_utils/test_link.py
Normal file
24
tests/test_utils/test_link.py
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
from typing import Any, Dict
|
||||
|
||||
import pytest
|
||||
|
||||
from aiogram.utils.link import create_telegram_link, create_tg_link
|
||||
|
||||
|
||||
class TestLink:
|
||||
@pytest.mark.parametrize(
|
||||
"base,params,result",
|
||||
[["user", dict(id=42), "tg://user?id=42"]],
|
||||
)
|
||||
def test_create_tg_link(self, base: str, params: Dict[str, Any], result: str):
|
||||
assert create_tg_link(base, **params) == result
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"base,params,result",
|
||||
[
|
||||
["username", dict(), "https://t.me/username"],
|
||||
["username", dict(start="test"), "https://t.me/username?start=test"],
|
||||
],
|
||||
)
|
||||
def test_create_telegram_link(self, base: str, params: Dict[str, Any], result: str):
|
||||
assert create_telegram_link(base, **params) == result
|
||||
Loading…
Add table
Add a link
Reference in a new issue