Update tests

This commit is contained in:
Alex Root Junior 2022-09-18 02:33:12 +03:00
parent 4dfd86fd7d
commit 237c98636a
No known key found for this signature in database
GPG key ID: 074C1D455EBEA4AC
14 changed files with 440 additions and 396 deletions

View file

@ -41,6 +41,7 @@ jobs:
- '3.8'
- '3.9'
- '3.10'
- '3.11'
- 'pypy3.8'
- 'pypy3.9'

View file

@ -15,7 +15,7 @@ repos:
- id: "check-toml"
- repo: https://github.com/psf/black
rev: 22.6.0
rev: 22.8.0
hooks:
- id: black
files: &files '^(aiogram|tests|examples)'

View file

@ -38,13 +38,10 @@ class Filter(ABC):
def _signature_to_string(self, *args: Any, **kwargs: Any) -> str:
items = [repr(arg) for arg in args]
items.extend([f"{k}={v!r}" for k, v in kwargs.items()])
items.extend([f"{k}={v!r}" for k, v in kwargs.items() if v is not None])
return f"{type(self).__name__}({', '.join(items)})"
def __str__(self) -> str:
return self._signature_to_string()
def __await__(self): # type: ignore # pragma: no cover
# Is needed only for inspection and this method is never be called
return self.__call__

View file

@ -67,7 +67,7 @@ class BufferedInputFile(InputFile):
:param path: Path to file
:param filename: Filename to be propagated to telegram.
By default will be parsed from path
By default, will be parsed from path
:param chunk_size: Uploading chunk size
:return: instance of :obj:`BufferedInputFile`
"""
@ -95,7 +95,7 @@ class FSInputFile(InputFile):
:param path: Path to file
:param filename: Filename to be propagated to telegram.
By default will be parsed from path
By default, will be parsed from path
:param chunk_size: Uploading chunk size
"""
if filename is None:
@ -106,10 +106,8 @@ class FSInputFile(InputFile):
async def read(self, chunk_size: int) -> AsyncGenerator[bytes, None]:
async with aiofiles.open(self.path, "rb") as f:
chunk = await f.read(chunk_size)
while chunk:
while chunk := await f.read(chunk_size):
yield chunk
chunk = await f.read(chunk_size)
class URLInputFile(InputFile):

782
poetry.lock generated

File diff suppressed because it is too large Load diff

View file

@ -34,15 +34,19 @@ classifiers = [
"Programming Language :: Python :: 3.10",
"Topic :: Software Development :: Libraries :: Application Frameworks",
]
packages = [
{ include = "aiogram" }
]
[tool.poetry.dependencies]
python = "^3.8"
magic-filter = "^1.0.8"
magic-filter = "^1.0.9"
aiohttp = "^3.8.1"
pydantic = "^1.10.2"
aiofiles = "^22.1.0"
# Fast
uvloop = { version = "^0.16.0", markers = "sys_platform == 'darwin' or sys_platform == 'linux'", optional = true }
uvloop = { version = "^0.17.0", markers = "sys_platform == 'darwin' or sys_platform == 'linux'", optional = true }
# i18n
Babel = { version = "^2.9.1", optional = true }
# Proxy

View file

@ -37,6 +37,8 @@ class TestBaseFilter:
my_filter = MyFilter()
my_inverted_filter = ~my_filter
assert str(my_inverted_filter) == f"~{str(my_filter)}"
assert isinstance(my_inverted_filter, _InvertFilter)
with patch(

View file

@ -179,3 +179,7 @@ class TestCallbackDataFilter:
async def test_invalid_call(self):
filter_object = MyCallback.filter(F.test)
assert not await filter_object(User(id=42, is_bot=False, first_name="test"))
def test_str(self):
filter_object = MyCallback.filter(F.test)
assert str(filter_object).startswith("CallbackQueryFilter(callback_data=")

View file

@ -343,3 +343,7 @@ class TestChatMemberUpdatedStatusFilter:
)
assert await updated_filter(event) is result
def test_str(self):
updated_filter = ChatMemberUpdatedFilter(member_status_changed=JOIN_TRANSITION)
assert str(updated_filter).startswith("ChatMemberUpdatedFilter(member_status_changed=")

View file

@ -151,3 +151,7 @@ class TestCommandObject:
cmd.update_handler_flags(flags)
assert len(flags["commands"]) == 2
def test_str(self):
cmd = Command(commands=["start"])
assert str(cmd) == "Command('start', prefix='/', ignore_case=False, ignore_mention=False)"

View file

@ -26,6 +26,10 @@ class TestExceptionMessageFilter:
assert isinstance(result, dict)
assert "match_exception" in result
async def test_str(self):
obj = ExceptionMessageFilter(pattern="KABOOM")
assert str(obj) == "ExceptionMessageFilter(pattern=re.compile('KABOOM'))"
class MyException(Exception):
pass

View file

@ -28,3 +28,7 @@ class TestMagicDataFilter:
assert called
assert isinstance(result, dict)
assert result["test"]
def test_str(self):
f = MagicData(magic_data=F.event.text == "test")
assert str(f).startswith("MagicData(magic_data=")

View file

@ -68,3 +68,7 @@ class TestStateFilter:
states = {SG.state: "OK"}
assert states.get(copy(SG.state)) == "OK"
def test_str(self):
f = StateFilter("test")
assert str(f) == "StateFilter('test')"

View file

@ -233,3 +233,7 @@ class TestText:
text = Text(**{argument: input_value}, ignore_case=ignore_case)
test = await text(update_type)
assert test is result
def test_str(self):
text = Text("test")
assert str(text) == "Text(text=['test'], ignore_case=False)"