2020-05-12 16:07:16 +04:00
|
|
|
from contextlib import contextmanager
|
|
|
|
|
from typing import Type
|
|
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
from packaging import version
|
|
|
|
|
|
|
|
|
|
import aiogram
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@contextmanager
|
|
|
|
|
def check_deprecated(
|
2021-01-26 21:20:52 +02:00
|
|
|
max_version: str,
|
|
|
|
|
exception: Type[Exception],
|
|
|
|
|
warning: Type[Warning] = DeprecationWarning,
|
2020-05-12 16:07:16 +04:00
|
|
|
) -> None:
|
|
|
|
|
"""
|
|
|
|
|
Should be used for modules that are being deprecated or already removed from aiogram
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
parsed_max_version = version.parse(max_version)
|
|
|
|
|
current_version = version.parse(aiogram.__version__)
|
|
|
|
|
|
|
|
|
|
if parsed_max_version <= current_version:
|
|
|
|
|
with pytest.raises(exception):
|
|
|
|
|
yield
|
|
|
|
|
else:
|
|
|
|
|
with pytest.warns(warning, match=max_version):
|
|
|
|
|
yield
|