Remove assert statement from non-test files

This commit is contained in:
deepsource-autofix[bot] 2020-11-08 21:48:49 +00:00 committed by GitHub
parent 44cd1fd974
commit dd50a9b13e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
29 changed files with 637 additions and 323 deletions

View file

@ -31,10 +31,11 @@ DEFAULT_RATE_LIMIT = .1
def _ensure_loop(x: "asyncio.AbstractEventLoop"): def _ensure_loop(x: "asyncio.AbstractEventLoop"):
assert isinstance( if not isinstance(
x, asyncio.AbstractEventLoop x, asyncio.AbstractEventLoop
), f"Loop must be the implementation of {asyncio.AbstractEventLoop!r}, " \ ):
f"not {type(x)!r}" raise AssertionError(f"Loop must be the implementation of {asyncio.AbstractEventLoop!r}, " \
f"not {type(x)!r}")
class Dispatcher(DataMixin, ContextInstanceMixin): class Dispatcher(DataMixin, ContextInstanceMixin):

View file

@ -22,7 +22,8 @@ def pytest_collection_modifyitems(config, items):
return return
try: try:
address, options = aioredis.util.parse_url(redis_uri) address, options = aioredis.util.parse_url(redis_uri)
assert isinstance(address, tuple), "Only redis and rediss schemas are supported, eg redis://foo." if not isinstance(address, tuple):
raise AssertionError("Only redis and rediss schemas are supported, eg redis://foo.")
except AssertionError as e: except AssertionError as e:
raise UsageError(f"Invalid redis URI {redis_uri!r}: {e}") raise UsageError(f"Invalid redis URI {redis_uri!r}: {e}")

View file

@ -19,15 +19,20 @@ async def store(redis_options):
class TestRedisStorage2: class TestRedisStorage2:
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_set_get(self, store): async def test_set_get(self, store):
assert await store.get_data(chat='1234') == {} if await store.get_data(chat='1234') != {}:
raise AssertionError
await store.set_data(chat='1234', data={'foo': 'bar'}) await store.set_data(chat='1234', data={'foo': 'bar'})
assert await store.get_data(chat='1234') == {'foo': 'bar'} if await store.get_data(chat='1234') != {'foo': 'bar'}:
raise AssertionError
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_close_and_open_connection(self, store): async def test_close_and_open_connection(self, store):
await store.set_data(chat='1234', data={'foo': 'bar'}) await store.set_data(chat='1234', data={'foo': 'bar'})
assert await store.get_data(chat='1234') == {'foo': 'bar'} if await store.get_data(chat='1234') != {'foo': 'bar'}:
raise AssertionError
pool_id = id(store._redis) pool_id = id(store._redis)
await store.close() await store.close()
assert await store.get_data(chat='1234') == {'foo': 'bar'} # new pool was opened at this point if await store.get_data(chat='1234') != {'foo': 'bar'}:
assert id(store._redis) != pool_id raise AssertionError
if id(store._redis) == pool_id:
raise AssertionError

View file

@ -22,7 +22,8 @@ async def test_get_me(bot: Bot, event_loop):
async with FakeTelegram(message_data=USER, loop=event_loop): async with FakeTelegram(message_data=USER, loop=event_loop):
result = await bot.me result = await bot.me
assert result == user if result != user:
raise AssertionError
async def test_log_out(bot: Bot, event_loop): async def test_log_out(bot: Bot, event_loop):
@ -30,7 +31,8 @@ async def test_log_out(bot: Bot, event_loop):
async with FakeTelegram(message_data=True, loop=event_loop): async with FakeTelegram(message_data=True, loop=event_loop):
result = await bot.log_out() result = await bot.log_out()
assert result is True if result is not True:
raise AssertionError
async def test_close_bot(bot: Bot, event_loop): async def test_close_bot(bot: Bot, event_loop):
@ -38,7 +40,8 @@ async def test_close_bot(bot: Bot, event_loop):
async with FakeTelegram(message_data=True, loop=event_loop): async with FakeTelegram(message_data=True, loop=event_loop):
result = await bot.close_bot() result = await bot.close_bot()
assert result is True if result is not True:
raise AssertionError
async def test_send_message(bot: Bot, event_loop): async def test_send_message(bot: Bot, event_loop):
@ -48,7 +51,8 @@ async def test_send_message(bot: Bot, event_loop):
async with FakeTelegram(message_data=MESSAGE, loop=event_loop): async with FakeTelegram(message_data=MESSAGE, loop=event_loop):
result = await bot.send_message(chat_id=msg.chat.id, text=msg.text) result = await bot.send_message(chat_id=msg.chat.id, text=msg.text)
assert result == msg if result != msg:
raise AssertionError
async def test_forward_message(bot: Bot, event_loop): async def test_forward_message(bot: Bot, event_loop):
@ -59,7 +63,8 @@ async def test_forward_message(bot: Bot, event_loop):
async with FakeTelegram(message_data=FORWARDED_MESSAGE, loop=event_loop): async with FakeTelegram(message_data=FORWARDED_MESSAGE, loop=event_loop):
result = await bot.forward_message(chat_id=msg.chat.id, from_chat_id=msg.forward_from_chat.id, result = await bot.forward_message(chat_id=msg.chat.id, from_chat_id=msg.forward_from_chat.id,
message_id=msg.forward_from_message_id) message_id=msg.forward_from_message_id)
assert result == msg if result != msg:
raise AssertionError
async def test_send_photo(bot: Bot, event_loop): async def test_send_photo(bot: Bot, event_loop):
@ -71,7 +76,8 @@ async def test_send_photo(bot: Bot, event_loop):
async with FakeTelegram(message_data=MESSAGE_WITH_PHOTO, loop=event_loop): async with FakeTelegram(message_data=MESSAGE_WITH_PHOTO, loop=event_loop):
result = await bot.send_photo(msg.chat.id, photo=photo.file_id, caption=msg.caption, result = await bot.send_photo(msg.chat.id, photo=photo.file_id, caption=msg.caption,
parse_mode=types.ParseMode.HTML, disable_notification=False) parse_mode=types.ParseMode.HTML, disable_notification=False)
assert result == msg if result != msg:
raise AssertionError
async def test_send_audio(bot: Bot, event_loop): async def test_send_audio(bot: Bot, event_loop):
@ -83,7 +89,8 @@ async def test_send_audio(bot: Bot, event_loop):
result = await bot.send_audio(chat_id=msg.chat.id, audio=msg.audio.file_id, caption=msg.caption, result = await bot.send_audio(chat_id=msg.chat.id, audio=msg.audio.file_id, caption=msg.caption,
parse_mode=types.ParseMode.HTML, duration=msg.audio.duration, parse_mode=types.ParseMode.HTML, duration=msg.audio.duration,
performer=msg.audio.performer, title=msg.audio.title, disable_notification=False) performer=msg.audio.performer, title=msg.audio.title, disable_notification=False)
assert result == msg if result != msg:
raise AssertionError
async def test_send_document(bot: Bot, event_loop): async def test_send_document(bot: Bot, event_loop):
@ -94,7 +101,8 @@ async def test_send_document(bot: Bot, event_loop):
async with FakeTelegram(message_data=MESSAGE_WITH_DOCUMENT, loop=event_loop): async with FakeTelegram(message_data=MESSAGE_WITH_DOCUMENT, loop=event_loop):
result = await bot.send_document(chat_id=msg.chat.id, document=msg.document.file_id, caption=msg.caption, result = await bot.send_document(chat_id=msg.chat.id, document=msg.document.file_id, caption=msg.caption,
parse_mode=types.ParseMode.HTML, disable_notification=False) parse_mode=types.ParseMode.HTML, disable_notification=False)
assert result == msg if result != msg:
raise AssertionError
async def test_send_video(bot: Bot, event_loop): async def test_send_video(bot: Bot, event_loop):
@ -108,7 +116,8 @@ async def test_send_video(bot: Bot, event_loop):
width=video.width, height=video.height, caption=msg.caption, width=video.width, height=video.height, caption=msg.caption,
parse_mode=types.ParseMode.HTML, supports_streaming=True, parse_mode=types.ParseMode.HTML, supports_streaming=True,
disable_notification=False) disable_notification=False)
assert result == msg if result != msg:
raise AssertionError
async def test_send_voice(bot: Bot, event_loop): async def test_send_voice(bot: Bot, event_loop):
@ -121,7 +130,8 @@ async def test_send_voice(bot: Bot, event_loop):
result = await bot.send_voice(chat_id=msg.chat.id, voice=voice.file_id, caption=msg.caption, result = await bot.send_voice(chat_id=msg.chat.id, voice=voice.file_id, caption=msg.caption,
parse_mode=types.ParseMode.HTML, duration=voice.duration, parse_mode=types.ParseMode.HTML, duration=voice.duration,
disable_notification=False) disable_notification=False)
assert result == msg if result != msg:
raise AssertionError
async def test_send_video_note(bot: Bot, event_loop): async def test_send_video_note(bot: Bot, event_loop):
@ -134,7 +144,8 @@ async def test_send_video_note(bot: Bot, event_loop):
result = await bot.send_video_note(chat_id=msg.chat.id, video_note=video_note.file_id, result = await bot.send_video_note(chat_id=msg.chat.id, video_note=video_note.file_id,
duration=video_note.duration, length=video_note.length, duration=video_note.duration, length=video_note.length,
disable_notification=False) disable_notification=False)
assert result == msg if result != msg:
raise AssertionError
async def test_send_media_group(bot: Bot, event_loop): async def test_send_media_group(bot: Bot, event_loop):
@ -146,8 +157,10 @@ async def test_send_media_group(bot: Bot, event_loop):
async with FakeTelegram(message_data=[MESSAGE_WITH_MEDIA_GROUP, MESSAGE_WITH_MEDIA_GROUP], loop=event_loop): async with FakeTelegram(message_data=[MESSAGE_WITH_MEDIA_GROUP, MESSAGE_WITH_MEDIA_GROUP], loop=event_loop):
result = await bot.send_media_group(msg.chat.id, media=media, disable_notification=False) result = await bot.send_media_group(msg.chat.id, media=media, disable_notification=False)
assert len(result) == len(media) if len(result) != len(media):
assert result.pop().media_group_id raise AssertionError
if not result.pop().media_group_id:
raise AssertionError
async def test_send_location(bot: Bot, event_loop): async def test_send_location(bot: Bot, event_loop):
@ -159,7 +172,8 @@ async def test_send_location(bot: Bot, event_loop):
async with FakeTelegram(message_data=MESSAGE_WITH_LOCATION, loop=event_loop): async with FakeTelegram(message_data=MESSAGE_WITH_LOCATION, loop=event_loop):
result = await bot.send_location(msg.chat.id, latitude=location.latitude, longitude=location.longitude, result = await bot.send_location(msg.chat.id, latitude=location.latitude, longitude=location.longitude,
live_period=10, disable_notification=False) live_period=10, disable_notification=False)
assert result == msg if result != msg:
raise AssertionError
async def test_edit_message_live_location_by_bot(bot: Bot, event_loop): async def test_edit_message_live_location_by_bot(bot: Bot, event_loop):
@ -172,7 +186,8 @@ async def test_edit_message_live_location_by_bot(bot: Bot, event_loop):
async with FakeTelegram(message_data=MESSAGE_WITH_LOCATION, loop=event_loop): async with FakeTelegram(message_data=MESSAGE_WITH_LOCATION, loop=event_loop):
result = await bot.edit_message_live_location(chat_id=msg.chat.id, message_id=msg.message_id, result = await bot.edit_message_live_location(chat_id=msg.chat.id, message_id=msg.message_id,
latitude=location.latitude, longitude=location.longitude) latitude=location.latitude, longitude=location.longitude)
assert result == msg if result != msg:
raise AssertionError
async def test_edit_message_live_location_by_user(bot: Bot, event_loop): async def test_edit_message_live_location_by_user(bot: Bot, event_loop):
@ -185,7 +200,8 @@ async def test_edit_message_live_location_by_user(bot: Bot, event_loop):
async with FakeTelegram(message_data=True, loop=event_loop): async with FakeTelegram(message_data=True, loop=event_loop):
result = await bot.edit_message_live_location(chat_id=msg.chat.id, message_id=msg.message_id, result = await bot.edit_message_live_location(chat_id=msg.chat.id, message_id=msg.message_id,
latitude=location.latitude, longitude=location.longitude) latitude=location.latitude, longitude=location.longitude)
assert isinstance(result, bool) and result is True if not (isinstance(result, bool) and result is True):
raise AssertionError
async def test_stop_message_live_location_by_bot(bot: Bot, event_loop): async def test_stop_message_live_location_by_bot(bot: Bot, event_loop):
@ -196,7 +212,8 @@ async def test_stop_message_live_location_by_bot(bot: Bot, event_loop):
# stopping bot message # stopping bot message
async with FakeTelegram(message_data=MESSAGE_WITH_LOCATION, loop=event_loop): async with FakeTelegram(message_data=MESSAGE_WITH_LOCATION, loop=event_loop):
result = await bot.stop_message_live_location(chat_id=msg.chat.id, message_id=msg.message_id) result = await bot.stop_message_live_location(chat_id=msg.chat.id, message_id=msg.message_id)
assert result == msg if result != msg:
raise AssertionError
async def test_stop_message_live_location_by_user(bot: Bot, event_loop): async def test_stop_message_live_location_by_user(bot: Bot, event_loop):
@ -207,8 +224,10 @@ async def test_stop_message_live_location_by_user(bot: Bot, event_loop):
# stopping user's message # stopping user's message
async with FakeTelegram(message_data=True, loop=event_loop): async with FakeTelegram(message_data=True, loop=event_loop):
result = await bot.stop_message_live_location(chat_id=msg.chat.id, message_id=msg.message_id) result = await bot.stop_message_live_location(chat_id=msg.chat.id, message_id=msg.message_id)
assert isinstance(result, bool) if not isinstance(result, bool):
assert result is True raise AssertionError
if result is not True:
raise AssertionError
async def test_send_venue(bot: Bot, event_loop): async def test_send_venue(bot: Bot, event_loop):
@ -222,7 +241,8 @@ async def test_send_venue(bot: Bot, event_loop):
result = await bot.send_venue(msg.chat.id, latitude=location.latitude, longitude=location.longitude, result = await bot.send_venue(msg.chat.id, latitude=location.latitude, longitude=location.longitude,
title=venue.title, address=venue.address, foursquare_id=venue.foursquare_id, title=venue.title, address=venue.address, foursquare_id=venue.foursquare_id,
disable_notification=False) disable_notification=False)
assert result == msg if result != msg:
raise AssertionError
async def test_send_contact(bot: Bot, event_loop): async def test_send_contact(bot: Bot, event_loop):
@ -234,7 +254,8 @@ async def test_send_contact(bot: Bot, event_loop):
async with FakeTelegram(message_data=MESSAGE_WITH_CONTACT, loop=event_loop): async with FakeTelegram(message_data=MESSAGE_WITH_CONTACT, loop=event_loop):
result = await bot.send_contact(msg.chat.id, phone_number=contact.phone_number, first_name=contact.first_name, result = await bot.send_contact(msg.chat.id, phone_number=contact.phone_number, first_name=contact.first_name,
last_name=contact.last_name, disable_notification=False) last_name=contact.last_name, disable_notification=False)
assert result == msg if result != msg:
raise AssertionError
async def test_send_dice(bot: Bot, event_loop): async def test_send_dice(bot: Bot, event_loop):
@ -244,7 +265,8 @@ async def test_send_dice(bot: Bot, event_loop):
async with FakeTelegram(message_data=MESSAGE_WITH_DICE, loop=event_loop): async with FakeTelegram(message_data=MESSAGE_WITH_DICE, loop=event_loop):
result = await bot.send_dice(msg.chat.id, disable_notification=False) result = await bot.send_dice(msg.chat.id, disable_notification=False)
assert result == msg if result != msg:
raise AssertionError
async def test_send_chat_action(bot: Bot, event_loop): async def test_send_chat_action(bot: Bot, event_loop):
@ -254,8 +276,10 @@ async def test_send_chat_action(bot: Bot, event_loop):
async with FakeTelegram(message_data=True, loop=event_loop): async with FakeTelegram(message_data=True, loop=event_loop):
result = await bot.send_chat_action(chat_id=chat.id, action=types.ChatActions.TYPING) result = await bot.send_chat_action(chat_id=chat.id, action=types.ChatActions.TYPING)
assert isinstance(result, bool) if not isinstance(result, bool):
assert result is True raise AssertionError
if result is not True:
raise AssertionError
async def test_get_user_profile_photo(bot: Bot, event_loop): async def test_get_user_profile_photo(bot: Bot, event_loop):
@ -265,7 +289,8 @@ async def test_get_user_profile_photo(bot: Bot, event_loop):
async with FakeTelegram(message_data=USER_PROFILE_PHOTOS, loop=event_loop): async with FakeTelegram(message_data=USER_PROFILE_PHOTOS, loop=event_loop):
result = await bot.get_user_profile_photos(user_id=user.id, offset=1, limit=1) result = await bot.get_user_profile_photos(user_id=user.id, offset=1, limit=1)
assert isinstance(result, types.UserProfilePhotos) if not isinstance(result, types.UserProfilePhotos):
raise AssertionError
async def test_get_file(bot: Bot, event_loop): async def test_get_file(bot: Bot, event_loop):
@ -275,7 +300,8 @@ async def test_get_file(bot: Bot, event_loop):
async with FakeTelegram(message_data=FILE, loop=event_loop): async with FakeTelegram(message_data=FILE, loop=event_loop):
result = await bot.get_file(file_id=file.file_id) result = await bot.get_file(file_id=file.file_id)
assert isinstance(result, types.File) if not isinstance(result, types.File):
raise AssertionError
async def test_kick_chat_member(bot: Bot, event_loop): async def test_kick_chat_member(bot: Bot, event_loop):
@ -286,8 +312,10 @@ async def test_kick_chat_member(bot: Bot, event_loop):
async with FakeTelegram(message_data=True, loop=event_loop): async with FakeTelegram(message_data=True, loop=event_loop):
result = await bot.kick_chat_member(chat_id=chat.id, user_id=user.id, until_date=123) result = await bot.kick_chat_member(chat_id=chat.id, user_id=user.id, until_date=123)
assert isinstance(result, bool) if not isinstance(result, bool):
assert result is True raise AssertionError
if result is not True:
raise AssertionError
async def test_unban_chat_member(bot: Bot, event_loop): async def test_unban_chat_member(bot: Bot, event_loop):
@ -298,8 +326,10 @@ async def test_unban_chat_member(bot: Bot, event_loop):
async with FakeTelegram(message_data=True, loop=event_loop): async with FakeTelegram(message_data=True, loop=event_loop):
result = await bot.unban_chat_member(chat_id=chat.id, user_id=user.id) result = await bot.unban_chat_member(chat_id=chat.id, user_id=user.id)
assert isinstance(result, bool) if not isinstance(result, bool):
assert result is True raise AssertionError
if result is not True:
raise AssertionError
async def test_restrict_chat_member(bot: Bot, event_loop): async def test_restrict_chat_member(bot: Bot, event_loop):
@ -318,8 +348,10 @@ async def test_restrict_chat_member(bot: Bot, event_loop):
can_send_messages=False, can_send_messages=False,
can_send_other_messages=False can_send_other_messages=False
), until_date=123) ), until_date=123)
assert isinstance(result, bool) if not isinstance(result, bool):
assert result is True raise AssertionError
if result is not True:
raise AssertionError
async def test_promote_chat_member(bot: Bot, event_loop): async def test_promote_chat_member(bot: Bot, event_loop):
@ -333,8 +365,10 @@ async def test_promote_chat_member(bot: Bot, event_loop):
can_delete_messages=True, can_edit_messages=True, can_delete_messages=True, can_edit_messages=True,
can_invite_users=True, can_pin_messages=True, can_post_messages=True, can_invite_users=True, can_pin_messages=True, can_post_messages=True,
can_promote_members=True, can_restrict_members=True) can_promote_members=True, can_restrict_members=True)
assert isinstance(result, bool) if not isinstance(result, bool):
assert result is True raise AssertionError
if result is not True:
raise AssertionError
async def test_export_chat_invite_link(bot: Bot, event_loop): async def test_export_chat_invite_link(bot: Bot, event_loop):
@ -344,7 +378,8 @@ async def test_export_chat_invite_link(bot: Bot, event_loop):
async with FakeTelegram(message_data=INVITE_LINK, loop=event_loop): async with FakeTelegram(message_data=INVITE_LINK, loop=event_loop):
result = await bot.export_chat_invite_link(chat_id=chat.id) result = await bot.export_chat_invite_link(chat_id=chat.id)
assert result == INVITE_LINK if result != INVITE_LINK:
raise AssertionError
async def test_delete_chat_photo(bot: Bot, event_loop): async def test_delete_chat_photo(bot: Bot, event_loop):
@ -354,8 +389,10 @@ async def test_delete_chat_photo(bot: Bot, event_loop):
async with FakeTelegram(message_data=True, loop=event_loop): async with FakeTelegram(message_data=True, loop=event_loop):
result = await bot.delete_chat_photo(chat_id=chat.id) result = await bot.delete_chat_photo(chat_id=chat.id)
assert isinstance(result, bool) if not isinstance(result, bool):
assert result is True raise AssertionError
if result is not True:
raise AssertionError
async def test_set_chat_title(bot: Bot, event_loop): async def test_set_chat_title(bot: Bot, event_loop):
@ -365,8 +402,10 @@ async def test_set_chat_title(bot: Bot, event_loop):
async with FakeTelegram(message_data=True, loop=event_loop): async with FakeTelegram(message_data=True, loop=event_loop):
result = await bot.set_chat_title(chat_id=chat.id, title='Test title') result = await bot.set_chat_title(chat_id=chat.id, title='Test title')
assert isinstance(result, bool) if not isinstance(result, bool):
assert result is True raise AssertionError
if result is not True:
raise AssertionError
async def test_set_chat_description(bot: Bot, event_loop): async def test_set_chat_description(bot: Bot, event_loop):
@ -376,8 +415,10 @@ async def test_set_chat_description(bot: Bot, event_loop):
async with FakeTelegram(message_data=True, loop=event_loop): async with FakeTelegram(message_data=True, loop=event_loop):
result = await bot.set_chat_description(chat_id=chat.id, description='Test description') result = await bot.set_chat_description(chat_id=chat.id, description='Test description')
assert isinstance(result, bool) if not isinstance(result, bool):
assert result is True raise AssertionError
if result is not True:
raise AssertionError
async def test_pin_chat_message(bot: Bot, event_loop): async def test_pin_chat_message(bot: Bot, event_loop):
@ -388,8 +429,10 @@ async def test_pin_chat_message(bot: Bot, event_loop):
async with FakeTelegram(message_data=True, loop=event_loop): async with FakeTelegram(message_data=True, loop=event_loop):
result = await bot.pin_chat_message(chat_id=message.chat.id, message_id=message.message_id, result = await bot.pin_chat_message(chat_id=message.chat.id, message_id=message.message_id,
disable_notification=False) disable_notification=False)
assert isinstance(result, bool) if not isinstance(result, bool):
assert result is True raise AssertionError
if result is not True:
raise AssertionError
async def test_unpin_chat_message(bot: Bot, event_loop): async def test_unpin_chat_message(bot: Bot, event_loop):
@ -399,8 +442,10 @@ async def test_unpin_chat_message(bot: Bot, event_loop):
async with FakeTelegram(message_data=True, loop=event_loop): async with FakeTelegram(message_data=True, loop=event_loop):
result = await bot.unpin_chat_message(chat_id=chat.id) result = await bot.unpin_chat_message(chat_id=chat.id)
assert isinstance(result, bool) if not isinstance(result, bool):
assert result is True raise AssertionError
if result is not True:
raise AssertionError
async def test_leave_chat(bot: Bot, event_loop): async def test_leave_chat(bot: Bot, event_loop):
@ -410,8 +455,10 @@ async def test_leave_chat(bot: Bot, event_loop):
async with FakeTelegram(message_data=True, loop=event_loop): async with FakeTelegram(message_data=True, loop=event_loop):
result = await bot.leave_chat(chat_id=chat.id) result = await bot.leave_chat(chat_id=chat.id)
assert isinstance(result, bool) if not isinstance(result, bool):
assert result is True raise AssertionError
if result is not True:
raise AssertionError
async def test_get_chat(bot: Bot, event_loop): async def test_get_chat(bot: Bot, event_loop):
@ -421,7 +468,8 @@ async def test_get_chat(bot: Bot, event_loop):
async with FakeTelegram(message_data=CHAT, loop=event_loop): async with FakeTelegram(message_data=CHAT, loop=event_loop):
result = await bot.get_chat(chat_id=chat.id) result = await bot.get_chat(chat_id=chat.id)
assert result == chat if result != chat:
raise AssertionError
async def test_get_chat_administrators(bot: Bot, event_loop): async def test_get_chat_administrators(bot: Bot, event_loop):
@ -432,8 +480,10 @@ async def test_get_chat_administrators(bot: Bot, event_loop):
async with FakeTelegram(message_data=[CHAT_MEMBER, CHAT_MEMBER], loop=event_loop): async with FakeTelegram(message_data=[CHAT_MEMBER, CHAT_MEMBER], loop=event_loop):
result = await bot.get_chat_administrators(chat_id=chat.id) result = await bot.get_chat_administrators(chat_id=chat.id)
assert result[0] == member if result[0] != member:
assert len(result) == 2 raise AssertionError
if len(result) != 2:
raise AssertionError
async def test_get_chat_members_count(bot: Bot, event_loop): async def test_get_chat_members_count(bot: Bot, event_loop):
@ -444,7 +494,8 @@ async def test_get_chat_members_count(bot: Bot, event_loop):
async with FakeTelegram(message_data=count, loop=event_loop): async with FakeTelegram(message_data=count, loop=event_loop):
result = await bot.get_chat_members_count(chat_id=chat.id) result = await bot.get_chat_members_count(chat_id=chat.id)
assert result == count if result != count:
raise AssertionError
async def test_get_chat_member(bot: Bot, event_loop): async def test_get_chat_member(bot: Bot, event_loop):
@ -455,8 +506,10 @@ async def test_get_chat_member(bot: Bot, event_loop):
async with FakeTelegram(message_data=CHAT_MEMBER, loop=event_loop): async with FakeTelegram(message_data=CHAT_MEMBER, loop=event_loop):
result = await bot.get_chat_member(chat_id=chat.id, user_id=member.user.id) result = await bot.get_chat_member(chat_id=chat.id, user_id=member.user.id)
assert isinstance(result, types.ChatMember) if not isinstance(result, types.ChatMember):
assert result == member raise AssertionError
if result != member:
raise AssertionError
async def test_set_chat_sticker_set(bot: Bot, event_loop): async def test_set_chat_sticker_set(bot: Bot, event_loop):
@ -466,8 +519,10 @@ async def test_set_chat_sticker_set(bot: Bot, event_loop):
async with FakeTelegram(message_data=True, loop=event_loop): async with FakeTelegram(message_data=True, loop=event_loop):
result = await bot.set_chat_sticker_set(chat_id=chat.id, sticker_set_name='aiogram_stickers') result = await bot.set_chat_sticker_set(chat_id=chat.id, sticker_set_name='aiogram_stickers')
assert isinstance(result, bool) if not isinstance(result, bool):
assert result is True raise AssertionError
if result is not True:
raise AssertionError
async def test_delete_chat_sticker_set(bot: Bot, event_loop): async def test_delete_chat_sticker_set(bot: Bot, event_loop):
@ -477,8 +532,10 @@ async def test_delete_chat_sticker_set(bot: Bot, event_loop):
async with FakeTelegram(message_data=True, loop=event_loop): async with FakeTelegram(message_data=True, loop=event_loop):
result = await bot.delete_chat_sticker_set(chat_id=chat.id) result = await bot.delete_chat_sticker_set(chat_id=chat.id)
assert isinstance(result, bool) if not isinstance(result, bool):
assert result is True raise AssertionError
if result is not True:
raise AssertionError
async def test_answer_callback_query(bot: Bot, event_loop): async def test_answer_callback_query(bot: Bot, event_loop):
@ -486,8 +543,10 @@ async def test_answer_callback_query(bot: Bot, event_loop):
async with FakeTelegram(message_data=True, loop=event_loop): async with FakeTelegram(message_data=True, loop=event_loop):
result = await bot.answer_callback_query(callback_query_id='QuERyId', text='Test Answer') result = await bot.answer_callback_query(callback_query_id='QuERyId', text='Test Answer')
assert isinstance(result, bool) if not isinstance(result, bool):
assert result is True raise AssertionError
if result is not True:
raise AssertionError
async def test_set_my_commands(bot: Bot, event_loop): async def test_set_my_commands(bot: Bot, event_loop):
@ -497,8 +556,10 @@ async def test_set_my_commands(bot: Bot, event_loop):
async with FakeTelegram(message_data=True, loop=event_loop): async with FakeTelegram(message_data=True, loop=event_loop):
commands = [types.BotCommand(**BOT_COMMAND), types.BotCommand(**BOT_COMMAND)] commands = [types.BotCommand(**BOT_COMMAND), types.BotCommand(**BOT_COMMAND)]
result = await bot.set_my_commands(commands) result = await bot.set_my_commands(commands)
assert isinstance(result, bool) if not isinstance(result, bool):
assert result is True raise AssertionError
if result is not True:
raise AssertionError
async def test_get_my_commands(bot: Bot, event_loop): async def test_get_my_commands(bot: Bot, event_loop):
@ -508,8 +569,10 @@ async def test_get_my_commands(bot: Bot, event_loop):
commands = [command, command] commands = [command, command]
async with FakeTelegram(message_data=commands, loop=event_loop): async with FakeTelegram(message_data=commands, loop=event_loop):
result = await bot.get_my_commands() result = await bot.get_my_commands()
assert isinstance(result, list) if not isinstance(result, list):
assert all(isinstance(command, types.BotCommand) for command in result) raise AssertionError
if not all(isinstance(command, types.BotCommand) for command in result):
raise AssertionError
async def test_edit_message_text_by_bot(bot: Bot, event_loop): async def test_edit_message_text_by_bot(bot: Bot, event_loop):
@ -520,7 +583,8 @@ async def test_edit_message_text_by_bot(bot: Bot, event_loop):
# message by bot # message by bot
async with FakeTelegram(message_data=EDITED_MESSAGE, loop=event_loop): async with FakeTelegram(message_data=EDITED_MESSAGE, loop=event_loop):
result = await bot.edit_message_text(text=msg.text, chat_id=msg.chat.id, message_id=msg.message_id) result = await bot.edit_message_text(text=msg.text, chat_id=msg.chat.id, message_id=msg.message_id)
assert result == msg if result != msg:
raise AssertionError
async def test_edit_message_text_by_user(bot: Bot, event_loop): async def test_edit_message_text_by_user(bot: Bot, event_loop):
@ -531,8 +595,10 @@ async def test_edit_message_text_by_user(bot: Bot, event_loop):
# message by user # message by user
async with FakeTelegram(message_data=True, loop=event_loop): async with FakeTelegram(message_data=True, loop=event_loop):
result = await bot.edit_message_text(text=msg.text, chat_id=msg.chat.id, message_id=msg.message_id) result = await bot.edit_message_text(text=msg.text, chat_id=msg.chat.id, message_id=msg.message_id)
assert isinstance(result, bool) if not isinstance(result, bool):
assert result is True raise AssertionError
if result is not True:
raise AssertionError
async def test_set_sticker_set_thumb(bot: Bot, event_loop): async def test_set_sticker_set_thumb(bot: Bot, event_loop):
@ -540,11 +606,14 @@ async def test_set_sticker_set_thumb(bot: Bot, event_loop):
async with FakeTelegram(message_data=True, loop=event_loop): async with FakeTelegram(message_data=True, loop=event_loop):
result = await bot.set_sticker_set_thumb(name='test', user_id=123456789, thumb='file_id') result = await bot.set_sticker_set_thumb(name='test', user_id=123456789, thumb='file_id')
assert isinstance(result, bool) if not isinstance(result, bool):
assert result is True raise AssertionError
if result is not True:
raise AssertionError
async def test_bot_id(bot: Bot): async def test_bot_id(bot: Bot):
""" Check getting id from token. """ """ Check getting id from token. """
bot = Bot(TOKEN) bot = Bot(TOKEN)
assert bot.id == BOT_ID # BOT_ID is a correct id from TOKEN if bot.id != BOT_ID:
raise AssertionError

View file

@ -25,7 +25,8 @@ def invalid_token_fixture(request):
class TestCheckToken: class TestCheckToken:
def test_valid(self): def test_valid(self):
assert check_token(VALID_TOKEN) is True if check_token(VALID_TOKEN) is not True:
raise AssertionError
def test_invalid_token(self, invalid_token): def test_invalid_token(self, invalid_token):
with pytest.raises(ValidationError): with pytest.raises(ValidationError):

View file

@ -16,16 +16,24 @@ class TestAiohttpSession:
async def test_create_bot(self): async def test_create_bot(self):
bot = BaseBot(token="42:correct") bot = BaseBot(token="42:correct")
assert bot._session is None if bot._session is not None:
assert isinstance(bot._connector_init, dict) raise AssertionError
assert all(key in {"limit", "ssl", "loop"} for key in bot._connector_init) if not isinstance(bot._connector_init, dict):
assert isinstance(bot._connector_class, type) raise AssertionError
assert issubclass(bot._connector_class, aiohttp.TCPConnector) if not all(key in {"limit", "ssl", "loop"} for key in bot._connector_init):
raise AssertionError
if not isinstance(bot._connector_class, type):
raise AssertionError
if not issubclass(bot._connector_class, aiohttp.TCPConnector):
raise AssertionError
assert bot._session is None if bot._session is not None:
raise AssertionError
assert isinstance(bot.session, aiohttp.ClientSession) if not isinstance(bot.session, aiohttp.ClientSession):
assert bot.session == bot._session raise AssertionError
if bot.session != bot._session:
raise AssertionError
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_create_proxy_bot(self): async def test_create_proxy_bot(self):
@ -39,15 +47,21 @@ class TestAiohttpSession:
proxy_auth=aiohttp.BasicAuth(username, password, "encoding"), proxy_auth=aiohttp.BasicAuth(username, password, "encoding"),
) )
assert bot._connector_class == aiohttp_socks.SocksConnector if bot._connector_class != aiohttp_socks.SocksConnector:
raise AssertionError
assert isinstance(bot._connector_init, dict) if not isinstance(bot._connector_init, dict):
raise AssertionError
init_kwargs = bot._connector_init init_kwargs = bot._connector_init
assert init_kwargs["username"] == username if init_kwargs["username"] != username:
assert init_kwargs["password"] == password raise AssertionError
assert init_kwargs["host"] == host if init_kwargs["password"] != password:
assert init_kwargs["port"] == port raise AssertionError
if init_kwargs["host"] != host:
raise AssertionError
if init_kwargs["port"] != port:
raise AssertionError
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_close_session(self): async def test_close_session(self):
@ -59,4 +73,5 @@ class TestAiohttpSession:
mocked_close.assert_called_once() mocked_close.assert_called_once()
await aiohttp_client_0.close() await aiohttp_client_0.close()
assert aiohttp_client_0 != bot.session # will create new session if aiohttp_client_0 == bot.session:
raise AssertionError

View file

@ -23,7 +23,8 @@ class TestDispatcherInit:
:type bot: Bot :type bot: Bot
""" """
dp = Dispatcher(bot=bot) dp = Dispatcher(bot=bot)
assert isinstance(dp, Dispatcher) if not isinstance(dp, Dispatcher):
raise AssertionError
@pytest.mark.parametrize("bot_instance", [None, Bot, 123, 'abc']) @pytest.mark.parametrize("bot_instance", [None, Bot, 123, 'abc'])
async def test_wrong_bot_instance(self, bot_instance): async def test_wrong_bot_instance(self, bot_instance):

View file

@ -23,7 +23,8 @@ class TestText:
value = 'spam and eggs' value = 'spam and eggs'
config = {param: value} config = {param: value}
res = Text.validate(config) res = Text.validate(config)
assert res == {key: value} if res != {key: value}:
raise AssertionError
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -70,7 +71,8 @@ class TestText:
), ),
) )
def test_extract_chat_ids(chat_id: ChatIDArgumentType, expected: Set[int]): def test_extract_chat_ids(chat_id: ChatIDArgumentType, expected: Set[int]):
assert extract_chat_ids(chat_id) == expected if extract_chat_ids(chat_id) != expected:
raise AssertionError
class TestForwardedMessageFilter: class TestForwardedMessageFilter:
@ -84,7 +86,8 @@ class TestForwardedMessageFilter:
not_forwarded_message = Message(**MESSAGE) not_forwarded_message = Message(**MESSAGE)
assert await filter.check(forwarded_message) assert await filter.check(forwarded_message)
assert not await filter.check(not_forwarded_message) if await filter.check(not_forwarded_message):
raise AssertionError
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_filter_not_forwarded_messages(self): async def test_filter_not_forwarded_messages(self):
@ -95,7 +98,8 @@ class TestForwardedMessageFilter:
not_forwarded_message = Message(**MESSAGE) not_forwarded_message = Message(**MESSAGE)
assert await filter.check(not_forwarded_message) assert await filter.check(not_forwarded_message)
assert not await filter.check(forwarded_message) if await filter.check(forwarded_message):
raise AssertionError
class TestIDFilter: class TestIDFilter:

View file

@ -16,4 +16,5 @@ class TestStatesGroup:
inner2 = InnerState2 inner2 = InnerState2
form_childs = Form.all_childs form_childs = Form.all_childs
assert form_childs == (InnerState1, InnerState2) if form_childs != (InnerState1, InnerState2):
raise AssertionError

View file

@ -38,10 +38,14 @@ class TestHandlerObj:
obj1 = Handler.HandlerObj(callback1, _get_spec(callback1)) obj1 = Handler.HandlerObj(callback1, _get_spec(callback1))
obj2 = Handler.HandlerObj(callback2, _get_spec(callback2)) obj2 = Handler.HandlerObj(callback2, _get_spec(callback2))
assert set(obj1.spec.args) == {"foo", "bar", "baz"} if set(obj1.spec.args) != {"foo", "bar", "baz"}:
assert obj1.handler == callback1 raise AssertionError
assert set(obj2.spec.args) == {"foo", "bar", "baz"} if obj1.handler != callback1:
assert obj2.handler == callback2 raise AssertionError
if set(obj2.spec.args) != {"foo", "bar", "baz"}:
raise AssertionError
if obj2.handler != callback2:
raise AssertionError
@pytest.mark.parametrize( @pytest.mark.parametrize(
"callback,kwargs,result", "callback,kwargs,result",
@ -63,4 +67,5 @@ class TestHandlerObj:
) )
def test__check_spec(self, callback, kwargs, result): def test__check_spec(self, callback, kwargs, result):
spec = _get_spec(callback) spec = _get_spec(callback)
assert _check_spec(spec, kwargs) == result if _check_spec(spec, kwargs) != result:
raise AssertionError

View file

@ -256,7 +256,8 @@ class TestTextFilter:
else: else:
_test_filter_list = test_filter_list _test_filter_list = test_filter_list
_test_text = test_text _test_text = test_text
assert result is (_test_text in _test_filter_list) if result is not (_test_text in _test_filter_list):
raise AssertionError
await check(Message(text=test_text)) await check(Message(text=test_text))
await check(CallbackQuery(data=test_text)) await check(CallbackQuery(data=test_text))
@ -276,36 +277,43 @@ class TestCommandStart:
test_filter = CommandStart() # empty filter test_filter = CommandStart() # empty filter
message = Message(text=self.START) message = Message(text=self.START)
result = await test_filter.check(message) result = await test_filter.check(message)
assert result if not result:
raise AssertionError
async def test_start_command_payload_is_matched(self): async def test_start_command_payload_is_matched(self):
test_filter = CommandStart(deep_link=self.GOOD) test_filter = CommandStart(deep_link=self.GOOD)
message = Message(text=f'{self.START} {self.GOOD}') message = Message(text=f'{self.START} {self.GOOD}')
result = await test_filter.check(message) result = await test_filter.check(message)
assert result == {'deep_link': self.GOOD} if result != {'deep_link': self.GOOD}:
raise AssertionError
async def test_start_command_payload_is_not_matched(self): async def test_start_command_payload_is_not_matched(self):
test_filter = CommandStart(deep_link=self.GOOD) test_filter = CommandStart(deep_link=self.GOOD)
message = Message(text=f'{self.START} {self.BAD}') message = Message(text=f'{self.START} {self.BAD}')
result = await test_filter.check(message) result = await test_filter.check(message)
assert result is False if result is not False:
raise AssertionError
async def test_start_command_payload_pattern_is_matched(self): async def test_start_command_payload_pattern_is_matched(self):
test_filter = CommandStart(deep_link=self.GOOD_PATTERN) test_filter = CommandStart(deep_link=self.GOOD_PATTERN)
message = Message(text=f'{self.START} {self.GOOD}') message = Message(text=f'{self.START} {self.GOOD}')
result = await test_filter.check(message) result = await test_filter.check(message)
assert isinstance(result, dict) if not isinstance(result, dict):
raise AssertionError
match = result.get('deep_link') match = result.get('deep_link')
assert isinstance(match, Match) if not isinstance(match, Match):
raise AssertionError
async def test_start_command_payload_pattern_is_not_matched(self): async def test_start_command_payload_pattern_is_not_matched(self):
test_filter = CommandStart(deep_link=self.BAD_PATTERN) test_filter = CommandStart(deep_link=self.BAD_PATTERN)
message = Message(text=f'{self.START} {self.GOOD}') message = Message(text=f'{self.START} {self.GOOD}')
result = await test_filter.check(message) result = await test_filter.check(message)
assert result is False if result is not False:
raise AssertionError
async def test_start_command_payload_is_encoded(self): async def test_start_command_payload_is_encoded(self):
test_filter = CommandStart(deep_link=self.GOOD, encoded=True) test_filter = CommandStart(deep_link=self.GOOD, encoded=True)
message = Message(text=f'{self.START} {self.ENCODED}') message = Message(text=f'{self.START} {self.ENCODED}')
result = await test_filter.check(message) result = await test_filter.check(message)
assert result == {'deep_link': self.GOOD} if result != {'deep_link': self.GOOD}:
raise AssertionError

View file

@ -26,78 +26,102 @@ alone_in_group = State('alone', group_name='home')
def test_default_state(): def test_default_state():
assert default_state.state is None if default_state.state is not None:
raise AssertionError
def test_any_state(): def test_any_state():
assert any_state.state == '*' if any_state.state != '*':
raise AssertionError
def test_alone_state(): def test_alone_state():
assert alone_state.state == '@:alone' if alone_state.state != '@:alone':
assert alone_in_group.state == 'home:alone' raise AssertionError
if alone_in_group.state != 'home:alone':
raise AssertionError
def test_group_names(): def test_group_names():
assert MyGroup.__group_name__ == 'MyGroup' if MyGroup.__group_name__ != 'MyGroup':
assert MyGroup.__full_group_name__ == 'MyGroup' raise AssertionError
if MyGroup.__full_group_name__ != 'MyGroup':
raise AssertionError
assert MyGroup.MySubGroup.__group_name__ == 'MySubGroup' if MyGroup.MySubGroup.__group_name__ != 'MySubGroup':
assert MyGroup.MySubGroup.__full_group_name__ == 'MyGroup.MySubGroup' raise AssertionError
if MyGroup.MySubGroup.__full_group_name__ != 'MyGroup.MySubGroup':
raise AssertionError
assert MyGroup.MySubGroup.NewGroup.__group_name__ == 'NewGroup' if MyGroup.MySubGroup.NewGroup.__group_name__ != 'NewGroup':
assert MyGroup.MySubGroup.NewGroup.__full_group_name__ == 'MyGroup.MySubGroup.NewGroup' raise AssertionError
if MyGroup.MySubGroup.NewGroup.__full_group_name__ != 'MyGroup.MySubGroup.NewGroup':
raise AssertionError
def test_custom_group_in_group(): def test_custom_group_in_group():
assert MyGroup.MySubGroup.in_custom_group.state == 'custom_group:in_custom_group' if MyGroup.MySubGroup.in_custom_group.state != 'custom_group:in_custom_group':
raise AssertionError
def test_custom_state_name_in_group(): def test_custom_state_name_in_group():
assert MyGroup.MySubGroup.NewGroup.renamed_state.state == 'MyGroup.MySubGroup.NewGroup:spam_state' if MyGroup.MySubGroup.NewGroup.renamed_state.state != 'MyGroup.MySubGroup.NewGroup:spam_state':
raise AssertionError
def test_group_states_names(): def test_group_states_names():
assert len(MyGroup.states) == 3 if len(MyGroup.states) != 3:
assert len(MyGroup.all_states) == 9 raise AssertionError
if len(MyGroup.all_states) != 9:
raise AssertionError
assert MyGroup.states_names == ('MyGroup:state', 'MyGroup:state_1', 'MyGroup:state_2') if MyGroup.states_names != ('MyGroup:state', 'MyGroup:state_1', 'MyGroup:state_2'):
assert MyGroup.MySubGroup.states_names == ( raise AssertionError
if MyGroup.MySubGroup.states_names != (
'MyGroup.MySubGroup:sub_state', 'MyGroup.MySubGroup:sub_state_1', 'MyGroup.MySubGroup:sub_state_2', 'MyGroup.MySubGroup:sub_state', 'MyGroup.MySubGroup:sub_state_1', 'MyGroup.MySubGroup:sub_state_2',
'custom_group:in_custom_group') 'custom_group:in_custom_group'):
assert MyGroup.MySubGroup.NewGroup.states_names == ( raise AssertionError
'MyGroup.MySubGroup.NewGroup:spam', 'MyGroup.MySubGroup.NewGroup:spam_state') if MyGroup.MySubGroup.NewGroup.states_names != (
'MyGroup.MySubGroup.NewGroup:spam', 'MyGroup.MySubGroup.NewGroup:spam_state'):
raise AssertionError
assert MyGroup.all_states_names == ( if MyGroup.all_states_names != (
'MyGroup:state', 'MyGroup:state_1', 'MyGroup:state_2', 'MyGroup:state', 'MyGroup:state_1', 'MyGroup:state_2',
'MyGroup.MySubGroup:sub_state', 'MyGroup.MySubGroup:sub_state',
'MyGroup.MySubGroup:sub_state_1', 'MyGroup.MySubGroup:sub_state_1',
'MyGroup.MySubGroup:sub_state_2', 'MyGroup.MySubGroup:sub_state_2',
'custom_group:in_custom_group', 'custom_group:in_custom_group',
'MyGroup.MySubGroup.NewGroup:spam', 'MyGroup.MySubGroup.NewGroup:spam',
'MyGroup.MySubGroup.NewGroup:spam_state') 'MyGroup.MySubGroup.NewGroup:spam_state'):
raise AssertionError
assert MyGroup.MySubGroup.all_states_names == ( if MyGroup.MySubGroup.all_states_names != (
'MyGroup.MySubGroup:sub_state', 'MyGroup.MySubGroup:sub_state',
'MyGroup.MySubGroup:sub_state_1', 'MyGroup.MySubGroup:sub_state_1',
'MyGroup.MySubGroup:sub_state_2', 'MyGroup.MySubGroup:sub_state_2',
'custom_group:in_custom_group', 'custom_group:in_custom_group',
'MyGroup.MySubGroup.NewGroup:spam', 'MyGroup.MySubGroup.NewGroup:spam',
'MyGroup.MySubGroup.NewGroup:spam_state') 'MyGroup.MySubGroup.NewGroup:spam_state'):
raise AssertionError
assert MyGroup.MySubGroup.NewGroup.all_states_names == ( if MyGroup.MySubGroup.NewGroup.all_states_names != (
'MyGroup.MySubGroup.NewGroup:spam', 'MyGroup.MySubGroup.NewGroup:spam',
'MyGroup.MySubGroup.NewGroup:spam_state') 'MyGroup.MySubGroup.NewGroup:spam_state'):
raise AssertionError
def test_root_element(): def test_root_element():
root = MyGroup.MySubGroup.NewGroup.spam.get_root() root = MyGroup.MySubGroup.NewGroup.spam.get_root()
assert issubclass(root, StatesGroup) if not issubclass(root, StatesGroup):
assert root == MyGroup raise AssertionError
if root != MyGroup:
raise AssertionError
assert root == MyGroup.state.get_root() if root != MyGroup.state.get_root():
assert root == MyGroup.MySubGroup.get_root() raise AssertionError
if root != MyGroup.MySubGroup.get_root():
raise AssertionError
with pytest.raises(RuntimeError): with pytest.raises(RuntimeError):
any_state.get_root() any_state.get_root()

View file

@ -21,7 +21,8 @@ def data():
def test_generate_hash(data): def test_generate_hash(data):
res = generate_hash(data, TOKEN) res = generate_hash(data, TOKEN)
assert res == data['hash'] if res != data['hash']:
raise AssertionError
class Test_check_token: class Test_check_token:
@ -29,18 +30,22 @@ class Test_check_token:
This case gonna be deleted This case gonna be deleted
""" """
def test_ok(self, data): def test_ok(self, data):
assert check_token(data, TOKEN) is True if check_token(data, TOKEN) is not True:
raise AssertionError
def test_fail(self, data): def test_fail(self, data):
data.pop('username') data.pop('username')
assert check_token(data, TOKEN) is False if check_token(data, TOKEN) is not False:
raise AssertionError
class Test_check_integrity: class Test_check_integrity:
def test_ok(self, data): def test_ok(self, data):
assert check_integrity(TOKEN, data) is True if check_integrity(TOKEN, data) is not True:
raise AssertionError
def test_fail(self, data): def test_fail(self, data):
data.pop('username') data.pop('username')
assert check_integrity(TOKEN, data) is False if check_integrity(TOKEN, data) is not False:
raise AssertionError

View file

@ -48,7 +48,8 @@ def get_bot_user_fixture(monkeypatch):
class TestDeepLinking: class TestDeepLinking:
async def test_get_start_link(self, payload): async def test_get_start_link(self, payload):
link = await get_start_link(payload) link = await get_start_link(payload)
assert link == f'https://t.me/{dataset.USER["username"]}?start={payload}' if link != f'https://t.me/{dataset.USER["username"]}?start={payload}':
raise AssertionError
async def test_wrong_symbols(self, wrong_payload): async def test_wrong_symbols(self, wrong_payload):
with pytest.raises(ValueError): with pytest.raises(ValueError):
@ -56,13 +57,15 @@ class TestDeepLinking:
async def test_get_startgroup_link(self, payload): async def test_get_startgroup_link(self, payload):
link = await get_startgroup_link(payload) link = await get_startgroup_link(payload)
assert link == f'https://t.me/{dataset.USER["username"]}?startgroup={payload}' if link != f'https://t.me/{dataset.USER["username"]}?startgroup={payload}':
raise AssertionError
async def test_filter_encode_and_decode(self, payload): async def test_filter_encode_and_decode(self, payload):
_payload = filter_payload(payload) _payload = filter_payload(payload)
encoded = encode_payload(_payload) encoded = encode_payload(_payload)
decoded = decode_payload(encoded) decoded = decode_payload(encoded)
assert decoded == str(payload) if decoded != str(payload):
raise AssertionError
async def test_get_start_link_with_encoding(self, payload): async def test_get_start_link_with_encoding(self, payload):
# define link # define link
@ -72,4 +75,5 @@ class TestDeepLinking:
payload = filter_payload(payload) payload = filter_payload(payload)
encoded_payload = encode_payload(payload) encoded_payload = encode_payload(payload)
assert link == f'https://t.me/{dataset.USER["username"]}?start={encoded_payload}' if link != f'https://t.me/{dataset.USER["username"]}?start={encoded_payload}':
raise AssertionError

View file

@ -4,11 +4,13 @@ from aiogram.utils.deprecated import DeprecatedReadOnlyClassVar
def test_DeprecatedReadOnlyClassVarCD(): def test_DeprecatedReadOnlyClassVarCD():
assert DeprecatedReadOnlyClassVar.__slots__ == ("_new_value_getter", "_warning_message") if DeprecatedReadOnlyClassVar.__slots__ != ("_new_value_getter", "_warning_message"):
raise AssertionError
new_value_of_deprecated_cls_cd = "mpa" new_value_of_deprecated_cls_cd = "mpa"
deprecated_cd = DeprecatedReadOnlyClassVar("mopekaa", lambda owner: new_value_of_deprecated_cls_cd) deprecated_cd = DeprecatedReadOnlyClassVar("mopekaa", lambda owner: new_value_of_deprecated_cls_cd)
with pytest.warns(DeprecationWarning): with pytest.warns(DeprecationWarning):
pseudo_owner_cls = type("OpekaCla$$", (), {}) pseudo_owner_cls = type("OpekaCla$$", (), {})
assert deprecated_cd.__get__(None, pseudo_owner_cls) == new_value_of_deprecated_cls_cd if deprecated_cd.__get__(None, pseudo_owner_cls) != new_value_of_deprecated_cls_cd:
raise AssertionError

View file

@ -10,7 +10,8 @@ class TestOrderedHelper:
C = Item() C = Item()
B = Item() B = Item()
assert Helper.all() == ['A', 'D', 'C', 'B'] if Helper.all() != ['A', 'D', 'C', 'B']:
raise AssertionError
def test_list_items_are_ordered(self): def test_list_items_are_ordered(self):
class Helper(OrderedHelper): class Helper(OrderedHelper):
@ -19,4 +20,5 @@ class TestOrderedHelper:
C = ListItem() C = ListItem()
B = ListItem() B = ListItem()
assert Helper.all() == ['A', 'D', 'C', 'B'] if Helper.all() != ['A', 'D', 'C', 'B']:
raise AssertionError

View file

@ -5,7 +5,9 @@ from aiogram.utils import markdown
class TestMarkdownEscape: class TestMarkdownEscape:
def test_equality_sign_is_escaped(self): def test_equality_sign_is_escaped(self):
assert markdown.escape_md(r"e = mc2") == r"e \= mc2" if markdown.escape_md(r"e = mc2") != r"e \= mc2":
raise AssertionError
def test_pre_escaped(self): def test_pre_escaped(self):
assert markdown.escape_md(r"hello\.") == r"hello\\\." if markdown.escape_md(r"hello\.") != r"hello\\\.":
raise AssertionError

View file

@ -4,22 +4,24 @@ from aiogram.utils import text_decorations
class TestTextDecorations: class TestTextDecorations:
def test_unparse_entities_normal_text(self): def test_unparse_entities_normal_text(self):
assert text_decorations.markdown_decoration.unparse( if text_decorations.markdown_decoration.unparse(
"hi i'm bold and italic and still bold", "hi i'm bold and italic and still bold",
entities=[ entities=[
MessageEntity(offset=3, length=34, type=MessageEntityType.BOLD), MessageEntity(offset=3, length=34, type=MessageEntityType.BOLD),
MessageEntity(offset=12, length=10, type=MessageEntityType.ITALIC), MessageEntity(offset=12, length=10, type=MessageEntityType.ITALIC),
] ]
) == "hi *i'm bold _\rand italic_\r and still bold*" ) != "hi *i'm bold _\rand italic_\r and still bold*":
raise AssertionError
def test_unparse_entities_emoji_text(self): def test_unparse_entities_emoji_text(self):
""" """
emoji is encoded as two chars in json emoji is encoded as two chars in json
""" """
assert text_decorations.markdown_decoration.unparse( if text_decorations.markdown_decoration.unparse(
"🚀 i'm bold and italic and still bold", "🚀 i'm bold and italic and still bold",
entities=[ entities=[
MessageEntity(offset=3, length=34, type=MessageEntityType.BOLD), MessageEntity(offset=3, length=34, type=MessageEntityType.BOLD),
MessageEntity(offset=12, length=10, type=MessageEntityType.ITALIC), MessageEntity(offset=12, length=10, type=MessageEntityType.ITALIC),
] ]
) == "🚀 *i'm bold _\rand italic_\r and still bold*" ) != "🚀 *i'm bold _\rand italic_\r and still bold*":
raise AssertionError

View file

@ -7,34 +7,49 @@ animation = types.Animation(**ANIMATION)
def test_export(): def test_export():
exported = animation.to_python() exported = animation.to_python()
assert isinstance(exported, dict) if not isinstance(exported, dict):
assert exported == ANIMATION raise AssertionError
if exported != ANIMATION:
raise AssertionError
def test_file_name(): def test_file_name():
assert isinstance(animation.file_name, str) if not isinstance(animation.file_name, str):
assert animation.file_name == ANIMATION['file_name'] raise AssertionError
if animation.file_name != ANIMATION['file_name']:
raise AssertionError
def test_mime_type(): def test_mime_type():
assert isinstance(animation.mime_type, str) if not isinstance(animation.mime_type, str):
assert animation.mime_type == ANIMATION['mime_type'] raise AssertionError
if animation.mime_type != ANIMATION['mime_type']:
raise AssertionError
def test_file_id(): def test_file_id():
assert isinstance(animation.file_id, str) if not isinstance(animation.file_id, str):
raise AssertionError
# assert hash(animation) == ANIMATION['file_id'] # assert hash(animation) == ANIMATION['file_id']
assert animation.file_id == ANIMATION['file_id'] if animation.file_id != ANIMATION['file_id']:
raise AssertionError
def test_file_size(): def test_file_size():
assert isinstance(animation.file_size, int) if not isinstance(animation.file_size, int):
assert animation.file_size == ANIMATION['file_size'] raise AssertionError
if animation.file_size != ANIMATION['file_size']:
raise AssertionError
def test_thumb(): def test_thumb():
assert isinstance(animation.thumb, types.PhotoSize) if not isinstance(animation.thumb, types.PhotoSize):
assert animation.thumb.file_id == ANIMATION['thumb']['file_id'] raise AssertionError
assert animation.thumb.width == ANIMATION['thumb']['width'] if animation.thumb.file_id != ANIMATION['thumb']['file_id']:
assert animation.thumb.height == ANIMATION['thumb']['height'] raise AssertionError
assert animation.thumb.file_size == ANIMATION['thumb']['file_size'] if animation.thumb.width != ANIMATION['thumb']['width']:
raise AssertionError
if animation.thumb.height != ANIMATION['thumb']['height']:
raise AssertionError
if animation.thumb.file_size != ANIMATION['thumb']['file_size']:
raise AssertionError

View file

@ -7,56 +7,87 @@ chat = types.Chat(**CHAT)
def test_export(): def test_export():
exported = chat.to_python() exported = chat.to_python()
assert isinstance(exported, dict) if not isinstance(exported, dict):
assert exported == CHAT raise AssertionError
if exported != CHAT:
raise AssertionError
def test_id(): def test_id():
assert isinstance(chat.id, int) if not isinstance(chat.id, int):
assert chat.id == CHAT['id'] raise AssertionError
if chat.id != CHAT['id']:
raise AssertionError
# assert hash(chat) == CHAT['id'] # assert hash(chat) == CHAT['id']
def test_name(): def test_name():
assert isinstance(chat.first_name, str) if not isinstance(chat.first_name, str):
assert chat.first_name == CHAT['first_name'] raise AssertionError
if chat.first_name != CHAT['first_name']:
raise AssertionError
assert isinstance(chat.last_name, str) if not isinstance(chat.last_name, str):
assert chat.last_name == CHAT['last_name'] raise AssertionError
if chat.last_name != CHAT['last_name']:
raise AssertionError
assert isinstance(chat.username, str) if not isinstance(chat.username, str):
assert chat.username == CHAT['username'] raise AssertionError
if chat.username != CHAT['username']:
raise AssertionError
def test_type(): def test_type():
assert isinstance(chat.type, str) if not isinstance(chat.type, str):
assert chat.type == CHAT['type'] raise AssertionError
if chat.type != CHAT['type']:
raise AssertionError
def test_chat_types(): def test_chat_types():
assert types.ChatType.PRIVATE == 'private' if types.ChatType.PRIVATE != 'private':
assert types.ChatType.GROUP == 'group' raise AssertionError
assert types.ChatType.SUPER_GROUP == 'supergroup' if types.ChatType.GROUP != 'group':
assert types.ChatType.CHANNEL == 'channel' raise AssertionError
if types.ChatType.SUPER_GROUP != 'supergroup':
raise AssertionError
if types.ChatType.CHANNEL != 'channel':
raise AssertionError
def test_chat_type_filters(): def test_chat_type_filters():
from . import test_message from . import test_message
assert types.ChatType.is_private(test_message.message) if not types.ChatType.is_private(test_message.message):
assert not types.ChatType.is_group(test_message.message) raise AssertionError
assert not types.ChatType.is_super_group(test_message.message) if types.ChatType.is_group(test_message.message):
assert not types.ChatType.is_group_or_super_group(test_message.message) raise AssertionError
assert not types.ChatType.is_channel(test_message.message) if types.ChatType.is_super_group(test_message.message):
raise AssertionError
if types.ChatType.is_group_or_super_group(test_message.message):
raise AssertionError
if types.ChatType.is_channel(test_message.message):
raise AssertionError
def test_chat_actions(): def test_chat_actions():
assert types.ChatActions.TYPING == 'typing' if types.ChatActions.TYPING != 'typing':
assert types.ChatActions.UPLOAD_PHOTO == 'upload_photo' raise AssertionError
assert types.ChatActions.RECORD_VIDEO == 'record_video' if types.ChatActions.UPLOAD_PHOTO != 'upload_photo':
assert types.ChatActions.UPLOAD_VIDEO == 'upload_video' raise AssertionError
assert types.ChatActions.RECORD_AUDIO == 'record_audio' if types.ChatActions.RECORD_VIDEO != 'record_video':
assert types.ChatActions.UPLOAD_AUDIO == 'upload_audio' raise AssertionError
assert types.ChatActions.UPLOAD_DOCUMENT == 'upload_document' if types.ChatActions.UPLOAD_VIDEO != 'upload_video':
assert types.ChatActions.FIND_LOCATION == 'find_location' raise AssertionError
assert types.ChatActions.RECORD_VIDEO_NOTE == 'record_video_note' if types.ChatActions.RECORD_AUDIO != 'record_audio':
assert types.ChatActions.UPLOAD_VIDEO_NOTE == 'upload_video_note' raise AssertionError
if types.ChatActions.UPLOAD_AUDIO != 'upload_audio':
raise AssertionError
if types.ChatActions.UPLOAD_DOCUMENT != 'upload_document':
raise AssertionError
if types.ChatActions.FIND_LOCATION != 'find_location':
raise AssertionError
if types.ChatActions.RECORD_VIDEO_NOTE != 'record_video_note':
raise AssertionError
if types.ChatActions.UPLOAD_VIDEO_NOTE != 'upload_video_note':
raise AssertionError

View file

@ -7,72 +7,111 @@ chat_member = types.ChatMember(**CHAT_MEMBER)
def test_export(): def test_export():
exported = chat_member.to_python() exported = chat_member.to_python()
assert isinstance(exported, dict) if not isinstance(exported, dict):
assert exported == CHAT_MEMBER raise AssertionError
if exported != CHAT_MEMBER:
raise AssertionError
def test_user(): def test_user():
assert isinstance(chat_member.user, types.User) if not isinstance(chat_member.user, types.User):
raise AssertionError
def test_status(): def test_status():
assert isinstance(chat_member.status, str) if not isinstance(chat_member.status, str):
assert chat_member.status == CHAT_MEMBER['status'] raise AssertionError
if chat_member.status != CHAT_MEMBER['status']:
raise AssertionError
def test_privileges(): def test_privileges():
assert isinstance(chat_member.can_be_edited, bool) if not isinstance(chat_member.can_be_edited, bool):
assert chat_member.can_be_edited == CHAT_MEMBER['can_be_edited'] raise AssertionError
if chat_member.can_be_edited != CHAT_MEMBER['can_be_edited']:
raise AssertionError
assert isinstance(chat_member.can_change_info, bool) if not isinstance(chat_member.can_change_info, bool):
assert chat_member.can_change_info == CHAT_MEMBER['can_change_info'] raise AssertionError
if chat_member.can_change_info != CHAT_MEMBER['can_change_info']:
raise AssertionError
assert isinstance(chat_member.can_delete_messages, bool) if not isinstance(chat_member.can_delete_messages, bool):
assert chat_member.can_delete_messages == CHAT_MEMBER['can_delete_messages'] raise AssertionError
if chat_member.can_delete_messages != CHAT_MEMBER['can_delete_messages']:
raise AssertionError
assert isinstance(chat_member.can_invite_users, bool) if not isinstance(chat_member.can_invite_users, bool):
assert chat_member.can_invite_users == CHAT_MEMBER['can_invite_users'] raise AssertionError
if chat_member.can_invite_users != CHAT_MEMBER['can_invite_users']:
raise AssertionError
assert isinstance(chat_member.can_restrict_members, bool) if not isinstance(chat_member.can_restrict_members, bool):
assert chat_member.can_restrict_members == CHAT_MEMBER['can_restrict_members'] raise AssertionError
if chat_member.can_restrict_members != CHAT_MEMBER['can_restrict_members']:
raise AssertionError
assert isinstance(chat_member.can_pin_messages, bool) if not isinstance(chat_member.can_pin_messages, bool):
assert chat_member.can_pin_messages == CHAT_MEMBER['can_pin_messages'] raise AssertionError
if chat_member.can_pin_messages != CHAT_MEMBER['can_pin_messages']:
raise AssertionError
assert isinstance(chat_member.can_promote_members, bool) if not isinstance(chat_member.can_promote_members, bool):
assert chat_member.can_promote_members == CHAT_MEMBER['can_promote_members'] raise AssertionError
if chat_member.can_promote_members != CHAT_MEMBER['can_promote_members']:
raise AssertionError
def test_int(): def test_int():
assert int(chat_member) == chat_member.user.id if int(chat_member) != chat_member.user.id:
assert isinstance(int(chat_member), int) raise AssertionError
if not isinstance(int(chat_member), int):
raise AssertionError
def test_chat_member_status(): def test_chat_member_status():
assert types.ChatMemberStatus.CREATOR == 'creator' if types.ChatMemberStatus.CREATOR != 'creator':
assert types.ChatMemberStatus.ADMINISTRATOR == 'administrator' raise AssertionError
assert types.ChatMemberStatus.MEMBER == 'member' if types.ChatMemberStatus.ADMINISTRATOR != 'administrator':
assert types.ChatMemberStatus.RESTRICTED == 'restricted' raise AssertionError
assert types.ChatMemberStatus.LEFT == 'left' if types.ChatMemberStatus.MEMBER != 'member':
assert types.ChatMemberStatus.KICKED == 'kicked' raise AssertionError
if types.ChatMemberStatus.RESTRICTED != 'restricted':
raise AssertionError
if types.ChatMemberStatus.LEFT != 'left':
raise AssertionError
if types.ChatMemberStatus.KICKED != 'kicked':
raise AssertionError
def test_chat_member_status_filters(): def test_chat_member_status_filters():
assert types.ChatMemberStatus.is_chat_admin(chat_member.status) if not types.ChatMemberStatus.is_chat_admin(chat_member.status):
assert types.ChatMemberStatus.is_chat_member(chat_member.status) raise AssertionError
if not types.ChatMemberStatus.is_chat_member(chat_member.status):
raise AssertionError
assert types.ChatMemberStatus.is_chat_admin(types.ChatMemberStatus.CREATOR) if not types.ChatMemberStatus.is_chat_admin(types.ChatMemberStatus.CREATOR):
assert types.ChatMemberStatus.is_chat_admin(types.ChatMemberStatus.ADMINISTRATOR) raise AssertionError
if not types.ChatMemberStatus.is_chat_admin(types.ChatMemberStatus.ADMINISTRATOR):
raise AssertionError
assert types.ChatMemberStatus.is_chat_member(types.ChatMemberStatus.CREATOR) if not types.ChatMemberStatus.is_chat_member(types.ChatMemberStatus.CREATOR):
assert types.ChatMemberStatus.is_chat_member(types.ChatMemberStatus.ADMINISTRATOR) raise AssertionError
assert types.ChatMemberStatus.is_chat_member(types.ChatMemberStatus.MEMBER) if not types.ChatMemberStatus.is_chat_member(types.ChatMemberStatus.ADMINISTRATOR):
assert types.ChatMemberStatus.is_chat_member(types.ChatMemberStatus.RESTRICTED) raise AssertionError
if not types.ChatMemberStatus.is_chat_member(types.ChatMemberStatus.MEMBER):
raise AssertionError
if not types.ChatMemberStatus.is_chat_member(types.ChatMemberStatus.RESTRICTED):
raise AssertionError
assert not types.ChatMemberStatus.is_chat_member(types.ChatMemberStatus.LEFT) if types.ChatMemberStatus.is_chat_member(types.ChatMemberStatus.LEFT):
assert not types.ChatMemberStatus.is_chat_member(types.ChatMemberStatus.KICKED) raise AssertionError
if types.ChatMemberStatus.is_chat_member(types.ChatMemberStatus.KICKED):
raise AssertionError
def test_chat_member_filters(): def test_chat_member_filters():
assert chat_member.is_chat_admin() if not chat_member.is_chat_admin():
assert chat_member.is_chat_member() raise AssertionError
if not chat_member.is_chat_member():
raise AssertionError

View file

@ -7,30 +7,41 @@ document = types.Document(**DOCUMENT)
def test_export(): def test_export():
exported = document.to_python() exported = document.to_python()
assert isinstance(exported, dict) if not isinstance(exported, dict):
assert exported == DOCUMENT raise AssertionError
if exported != DOCUMENT:
raise AssertionError
def test_file_name(): def test_file_name():
assert isinstance(document.file_name, str) if not isinstance(document.file_name, str):
assert document.file_name == DOCUMENT['file_name'] raise AssertionError
if document.file_name != DOCUMENT['file_name']:
raise AssertionError
def test_mime_type(): def test_mime_type():
assert isinstance(document.mime_type, str) if not isinstance(document.mime_type, str):
assert document.mime_type == DOCUMENT['mime_type'] raise AssertionError
if document.mime_type != DOCUMENT['mime_type']:
raise AssertionError
def test_file_id(): def test_file_id():
assert isinstance(document.file_id, str) if not isinstance(document.file_id, str):
raise AssertionError
# assert hash(document) == DOCUMENT['file_id'] # assert hash(document) == DOCUMENT['file_id']
assert document.file_id == DOCUMENT['file_id'] if document.file_id != DOCUMENT['file_id']:
raise AssertionError
def test_file_size(): def test_file_size():
assert isinstance(document.file_size, int) if not isinstance(document.file_size, int):
assert document.file_size == DOCUMENT['file_size'] raise AssertionError
if document.file_size != DOCUMENT['file_size']:
raise AssertionError
def test_thumb(): def test_thumb():
assert document.thumb is None if document.thumb is not None:
raise AssertionError

View file

@ -7,25 +7,35 @@ game = types.Game(**GAME)
def test_export(): def test_export():
exported = game.to_python() exported = game.to_python()
assert isinstance(exported, dict) if not isinstance(exported, dict):
assert exported == GAME raise AssertionError
if exported != GAME:
raise AssertionError
def test_title(): def test_title():
assert isinstance(game.title, str) if not isinstance(game.title, str):
assert game.title == GAME['title'] raise AssertionError
if game.title != GAME['title']:
raise AssertionError
def test_description(): def test_description():
assert isinstance(game.description, str) if not isinstance(game.description, str):
assert game.description == GAME['description'] raise AssertionError
if game.description != GAME['description']:
raise AssertionError
def test_photo(): def test_photo():
assert isinstance(game.photo, list) if not isinstance(game.photo, list):
assert len(game.photo) == len(GAME['photo']) raise AssertionError
assert all(map(lambda t: isinstance(t, types.PhotoSize), game.photo)) if len(game.photo) != len(GAME['photo']):
raise AssertionError
if not all(map(lambda t: isinstance(t, types.PhotoSize), game.photo)):
raise AssertionError
def test_animation(): def test_animation():
assert isinstance(game.animation, types.Animation) if not isinstance(game.animation, types.Animation):
raise AssertionError

View file

@ -21,21 +21,31 @@ def test_field_width():
""" """
https://core.telegram.org/bots/api#inputmedia https://core.telegram.org/bots/api#inputmedia
""" """
assert not hasattr(input_media_audio, WIDTH) if hasattr(input_media_audio, WIDTH):
assert not hasattr(input_media_document, WIDTH) raise AssertionError
assert not hasattr(input_media_photo, WIDTH) if hasattr(input_media_document, WIDTH):
raise AssertionError
if hasattr(input_media_photo, WIDTH):
raise AssertionError
assert hasattr(input_media_animation, WIDTH) if not hasattr(input_media_animation, WIDTH):
assert hasattr(input_media_video, WIDTH) raise AssertionError
if not hasattr(input_media_video, WIDTH):
raise AssertionError
def test_field_height(): def test_field_height():
""" """
https://core.telegram.org/bots/api#inputmedia https://core.telegram.org/bots/api#inputmedia
""" """
assert not hasattr(input_media_audio, HEIGHT) if hasattr(input_media_audio, HEIGHT):
assert not hasattr(input_media_document, HEIGHT) raise AssertionError
assert not hasattr(input_media_photo, HEIGHT) if hasattr(input_media_document, HEIGHT):
raise AssertionError
if hasattr(input_media_photo, HEIGHT):
raise AssertionError
assert hasattr(input_media_animation, HEIGHT) if not hasattr(input_media_animation, HEIGHT):
assert hasattr(input_media_video, HEIGHT) raise AssertionError
if not hasattr(input_media_video, HEIGHT):
raise AssertionError

View file

@ -9,32 +9,45 @@ message = types.Message(**MESSAGE)
def test_export(): def test_export():
exported_chat = message.to_python() exported_chat = message.to_python()
assert isinstance(exported_chat, dict) if not isinstance(exported_chat, dict):
assert exported_chat == MESSAGE raise AssertionError
if exported_chat != MESSAGE:
raise AssertionError
def test_message_id(): def test_message_id():
# assert hash(message) == MESSAGE['message_id'] # assert hash(message) == MESSAGE['message_id']
assert message.message_id == MESSAGE['message_id'] if message.message_id != MESSAGE['message_id']:
assert message['message_id'] == MESSAGE['message_id'] raise AssertionError
if message['message_id'] != MESSAGE['message_id']:
raise AssertionError
def test_from(): def test_from():
assert isinstance(message.from_user, types.User) if not isinstance(message.from_user, types.User):
assert message.from_user == message['from'] raise AssertionError
if message.from_user != message['from']:
raise AssertionError
def test_chat(): def test_chat():
assert isinstance(message.chat, types.Chat) if not isinstance(message.chat, types.Chat):
assert message.chat == message['chat'] raise AssertionError
if message.chat != message['chat']:
raise AssertionError
def test_date(): def test_date():
assert isinstance(message.date, datetime.datetime) if not isinstance(message.date, datetime.datetime):
assert int(message.date.timestamp()) == MESSAGE['date'] raise AssertionError
assert message.date == message['date'] if int(message.date.timestamp()) != MESSAGE['date']:
raise AssertionError
if message.date != message['date']:
raise AssertionError
def test_text(): def test_text():
assert message.text == MESSAGE['text'] if message.text != MESSAGE['text']:
assert message['text'] == MESSAGE['text'] raise AssertionError
if message['text'] != MESSAGE['text']:
raise AssertionError

View file

@ -7,22 +7,32 @@ photo = types.PhotoSize(**PHOTO)
def test_export(): def test_export():
exported = photo.to_python() exported = photo.to_python()
assert isinstance(exported, dict) if not isinstance(exported, dict):
assert exported == PHOTO raise AssertionError
if exported != PHOTO:
raise AssertionError
def test_file_id(): def test_file_id():
assert isinstance(photo.file_id, str) if not isinstance(photo.file_id, str):
assert photo.file_id == PHOTO['file_id'] raise AssertionError
if photo.file_id != PHOTO['file_id']:
raise AssertionError
def test_file_size(): def test_file_size():
assert isinstance(photo.file_size, int) if not isinstance(photo.file_size, int):
assert photo.file_size == PHOTO['file_size'] raise AssertionError
if photo.file_size != PHOTO['file_size']:
raise AssertionError
def test_size(): def test_size():
assert isinstance(photo.width, int) if not isinstance(photo.width, int):
assert isinstance(photo.height, int) raise AssertionError
assert photo.width == PHOTO['width'] if not isinstance(photo.height, int):
assert photo.height == PHOTO['height'] raise AssertionError
if photo.width != PHOTO['width']:
raise AssertionError
if photo.height != PHOTO['height']:
raise AssertionError

View file

@ -6,8 +6,10 @@ reply_keyboard = types.ReplyKeyboardMarkup(**REPLY_KEYBOARD_MARKUP)
def test_serialize(): def test_serialize():
assert reply_keyboard.to_python() == REPLY_KEYBOARD_MARKUP if reply_keyboard.to_python() != REPLY_KEYBOARD_MARKUP:
raise AssertionError
def test_deserialize(): def test_deserialize():
assert reply_keyboard.to_object(reply_keyboard.to_python()) == reply_keyboard if reply_keyboard.to_object(reply_keyboard.to_python()) != reply_keyboard:
raise AssertionError

View file

@ -7,15 +7,20 @@ update = types.Update(**UPDATE)
def test_export(): def test_export():
exported = update.to_python() exported = update.to_python()
assert isinstance(exported, dict) if not isinstance(exported, dict):
assert exported == UPDATE raise AssertionError
if exported != UPDATE:
raise AssertionError
def test_update_id(): def test_update_id():
assert isinstance(update.update_id, int) if not isinstance(update.update_id, int):
raise AssertionError
# assert hash(update) == UPDATE['update_id'] # assert hash(update) == UPDATE['update_id']
assert update.update_id == UPDATE['update_id'] if update.update_id != UPDATE['update_id']:
raise AssertionError
def test_message(): def test_message():
assert isinstance(update.message, types.Message) if not isinstance(update.message, types.Message):
raise AssertionError

View file

@ -9,41 +9,57 @@ user = types.User(**USER)
def test_export(): def test_export():
exported = user.to_python() exported = user.to_python()
assert isinstance(exported, dict) if not isinstance(exported, dict):
assert exported == USER raise AssertionError
if exported != USER:
raise AssertionError
def test_id(): def test_id():
assert isinstance(user.id, int) if not isinstance(user.id, int):
assert user.id == USER['id'] raise AssertionError
if user.id != USER['id']:
raise AssertionError
# assert hash(user) == USER['id'] # assert hash(user) == USER['id']
def test_bot(): def test_bot():
assert isinstance(user.is_bot, bool) if not isinstance(user.is_bot, bool):
assert user.is_bot == USER['is_bot'] raise AssertionError
if user.is_bot != USER['is_bot']:
raise AssertionError
def test_name(): def test_name():
assert user.first_name == USER['first_name'] if user.first_name != USER['first_name']:
assert user.last_name == USER['last_name'] raise AssertionError
assert user.username == USER['username'] if user.last_name != USER['last_name']:
raise AssertionError
if user.username != USER['username']:
raise AssertionError
def test_language_code(): def test_language_code():
assert user.language_code == USER['language_code'] if user.language_code != USER['language_code']:
assert user.locale == Locale.parse(USER['language_code'], sep='-') raise AssertionError
if user.locale != Locale.parse(USER['language_code'], sep='-'):
raise AssertionError
def test_full_name(): def test_full_name():
assert user.full_name == f"{USER['first_name']} {USER['last_name']}" if user.full_name != f"{USER['first_name']} {USER['last_name']}":
raise AssertionError
def test_mention(): def test_mention():
assert user.mention == f"@{USER['username']}" if user.mention != f"@{USER['username']}":
assert user.get_mention('foo', as_html=False) == f"[foo](tg://user?id={USER['id']})" raise AssertionError
assert user.get_mention('foo', as_html=True) == f"<a href=\"tg://user?id={USER['id']}\">foo</a>" if user.get_mention('foo', as_html=False) != f"[foo](tg://user?id={USER['id']})":
raise AssertionError
if user.get_mention('foo', as_html=True) != f"<a href=\"tg://user?id={USER['id']}\">foo</a>":
raise AssertionError
def test_url(): def test_url():
assert user.url == f"tg://user?id={USER['id']}" if user.url != f"tg://user?id={USER['id']}":
raise AssertionError