From 04de3eff7a7b6d1581673f8ec6496d34bd8df5f8 Mon Sep 17 00:00:00 2001 From: Hinrich Mahler <22366557+Bibo-Joshi@users.noreply.github.com> Date: Sun, 29 Dec 2024 22:00:38 +0100 Subject: [PATCH] Get a Number of Tests passing --- telegram/_utils/argumentparsing.py | 2 ++ tests/_files/test_animation.py | 5 +++- tests/_files/test_audio.py | 5 +++- tests/_files/test_document.py | 5 +++- tests/_files/test_photo.py | 5 +++- tests/_files/test_sticker.py | 6 +++- tests/_files/test_video.py | 5 +++- tests/_files/test_videonote.py | 3 +- tests/_files/test_voice.py | 5 +++- tests/_games/test_gamehighscore.py | 2 -- tests/_inline/test_inlinekeyboardbutton.py | 3 -- .../test_inputinvoicemessagecontent.py | 1 - tests/_payment/stars/test_affiliateinfo.py | 3 -- .../stars/test_revenuewithdrawelstate.py | 9 ------ tests/_payment/stars/test_startransactions.py | 4 --- .../_payment/stars/test_transactionpartner.py | 17 ----------- tests/conftest.py | 12 +++++++- tests/test_bot.py | 29 +++++++++++++++++-- tests/test_botcommand.py | 2 -- tests/test_botcommandscope.py | 2 -- tests/test_chatbackground.py | 2 -- tests/test_chatboost.py | 2 -- tests/test_chatmember.py | 1 - tests/test_copytextbutton.py | 1 - tests/test_dice.py | 1 - tests/test_forum.py | 4 --- tests/test_gifts.py | 4 --- tests/test_giveaway.py | 8 ----- tests/test_inlinequeryresultsbutton.py | 2 -- tests/test_keyboardbutton.py | 3 -- tests/test_keyboardbuttonrequest.py | 3 -- tests/test_menubutton.py | 3 -- tests/test_messageorigin.py | 1 - tests/test_paidmedia.py | 7 ----- tests/test_poll.py | 3 +- tests/test_reaction.py | 4 --- tests/test_reply.py | 6 ---- tests/test_shared.py | 4 --- tests/test_story.py | 1 - tests/test_telegramobject.py | 2 +- tests/test_update.py | 5 ---- tests/test_videochat.py | 1 - tests/test_webhookinfo.py | 3 -- 43 files changed, 72 insertions(+), 124 deletions(-) diff --git a/telegram/_utils/argumentparsing.py b/telegram/_utils/argumentparsing.py index 97a129fc7..262aa8bb8 100644 --- a/telegram/_utils/argumentparsing.py +++ b/telegram/_utils/argumentparsing.py @@ -71,6 +71,8 @@ TeleCrypto_co = TypeVar("TeleCrypto_co", bound="HasDecryptMethod", covariant=Tru class HasDecryptMethod(Protocol): + __slots__ = () + @classmethod def de_json_decrypted( cls: type[TeleCrypto_co], diff --git a/tests/_files/test_animation.py b/tests/_files/test_animation.py index 0f581259d..3ae775e3c 100644 --- a/tests/_files/test_animation.py +++ b/tests/_files/test_animation.py @@ -138,7 +138,9 @@ class TestAnimationWithoutRequest(AnimationTestBase): ) @pytest.mark.parametrize("local_mode", [True, False]) - async def test_send_animation_local_files(self, monkeypatch, offline_bot, chat_id, local_mode): + async def test_send_animation_local_files( + self, monkeypatch, offline_bot, chat_id, local_mode, dummy_message_dict + ): try: offline_bot._local_mode = local_mode # For just test that the correct paths are passed as we have no local Bot API set up @@ -156,6 +158,7 @@ class TestAnimationWithoutRequest(AnimationTestBase): test_flag = isinstance(data.get("animation"), InputFile) and isinstance( data.get("thumbnail"), InputFile ) + return dummy_message_dict monkeypatch.setattr(offline_bot, "_post", make_assertion) await offline_bot.send_animation(chat_id, file, thumbnail=file) diff --git a/tests/_files/test_audio.py b/tests/_files/test_audio.py index 08e598cb2..39c1de11c 100644 --- a/tests/_files/test_audio.py +++ b/tests/_files/test_audio.py @@ -150,7 +150,9 @@ class TestAudioWithoutRequest(AudioTestBase): assert await offline_bot.send_audio(chat_id, audio_file, filename="custom_filename") @pytest.mark.parametrize("local_mode", [True, False]) - async def test_send_audio_local_files(self, monkeypatch, offline_bot, chat_id, local_mode): + async def test_send_audio_local_files( + self, dummy_message_dict, monkeypatch, offline_bot, chat_id, local_mode + ): try: offline_bot._local_mode = local_mode # For just test that the correct paths are passed as we have no local Bot API set up @@ -166,6 +168,7 @@ class TestAudioWithoutRequest(AudioTestBase): test_flag = isinstance(data.get("audio"), InputFile) and isinstance( data.get("thumbnail"), InputFile ) + return dummy_message_dict monkeypatch.setattr(offline_bot, "_post", make_assertion) await offline_bot.send_audio(chat_id, file, thumbnail=file) diff --git a/tests/_files/test_document.py b/tests/_files/test_document.py index e60374034..521e3a753 100644 --- a/tests/_files/test_document.py +++ b/tests/_files/test_document.py @@ -169,7 +169,9 @@ class TestDocumentWithoutRequest(DocumentTestBase): ) @pytest.mark.parametrize("local_mode", [True, False]) - async def test_send_document_local_files(self, monkeypatch, offline_bot, chat_id, local_mode): + async def test_send_document_local_files( + self, dummy_message_dict, monkeypatch, offline_bot, chat_id, local_mode + ): try: offline_bot._local_mode = local_mode # For just test that the correct paths are passed as we have no local Bot API set up @@ -187,6 +189,7 @@ class TestDocumentWithoutRequest(DocumentTestBase): test_flag = isinstance(data.get("document"), InputFile) and isinstance( data.get("thumbnail"), InputFile ) + return dummy_message_dict monkeypatch.setattr(offline_bot, "_post", make_assertion) await offline_bot.send_document(chat_id, file, thumbnail=file) diff --git a/tests/_files/test_photo.py b/tests/_files/test_photo.py index bdf34f72b..e83afe579 100644 --- a/tests/_files/test_photo.py +++ b/tests/_files/test_photo.py @@ -144,7 +144,9 @@ class TestPhotoWithoutRequest(PhotoTestBase): assert await offline_bot.send_photo(chat_id, photo_file, filename="custom_filename") @pytest.mark.parametrize("local_mode", [True, False]) - async def test_send_photo_local_files(self, monkeypatch, offline_bot, chat_id, local_mode): + async def test_send_photo_local_files( + self, dummy_message_dict, monkeypatch, offline_bot, chat_id, local_mode + ): try: offline_bot._local_mode = local_mode # For just test that the correct paths are passed as we have no local Bot API set up @@ -158,6 +160,7 @@ class TestPhotoWithoutRequest(PhotoTestBase): test_flag = data.get("photo") == expected else: test_flag = isinstance(data.get("photo"), InputFile) + return dummy_message_dict monkeypatch.setattr(offline_bot, "_post", make_assertion) await offline_bot.send_photo(chat_id, file) diff --git a/tests/_files/test_sticker.py b/tests/_files/test_sticker.py index 07cf2e932..a7a532308 100644 --- a/tests/_files/test_sticker.py +++ b/tests/_files/test_sticker.py @@ -256,7 +256,9 @@ class TestStickerWithoutRequest(StickerTestBase): assert await offline_bot.send_sticker(sticker=sticker, chat_id=chat_id) @pytest.mark.parametrize("local_mode", [True, False]) - async def test_send_sticker_local_files(self, monkeypatch, offline_bot, chat_id, local_mode): + async def test_send_sticker_local_files( + self, dummy_message_dict, monkeypatch, offline_bot, chat_id, local_mode + ): try: offline_bot._local_mode = local_mode # For just test that the correct paths are passed as we have no local Bot API set up @@ -270,6 +272,7 @@ class TestStickerWithoutRequest(StickerTestBase): test_flag = data.get("sticker") == expected else: test_flag = isinstance(data.get("sticker"), InputFile) + return dummy_message_dict monkeypatch.setattr(offline_bot, "_post", make_assertion) await offline_bot.send_sticker(chat_id, file) @@ -581,6 +584,7 @@ class TestStickerSetWithoutRequest(StickerSetTestBase): if local_mode else isinstance(data.get("sticker"), InputFile) ) + return File(file_id="file_id", file_unique_id="file_unique_id").to_dict() monkeypatch.setattr(offline_bot, "_post", make_assertion) await offline_bot.upload_sticker_file( diff --git a/tests/_files/test_video.py b/tests/_files/test_video.py index 66230389f..d13483ee6 100644 --- a/tests/_files/test_video.py +++ b/tests/_files/test_video.py @@ -157,7 +157,9 @@ class TestVideoWithoutRequest(VideoTestBase): assert await offline_bot.send_video(chat_id, video_file, filename="custom_filename") @pytest.mark.parametrize("local_mode", [True, False]) - async def test_send_video_local_files(self, monkeypatch, offline_bot, chat_id, local_mode): + async def test_send_video_local_files( + self, dummy_message_dict, monkeypatch, offline_bot, chat_id, local_mode + ): try: offline_bot._local_mode = local_mode # For just test that the correct paths are passed as we have no local Bot API set up @@ -173,6 +175,7 @@ class TestVideoWithoutRequest(VideoTestBase): test_flag = isinstance(data.get("video"), InputFile) and isinstance( data.get("thumbnail"), InputFile ) + return dummy_message_dict monkeypatch.setattr(offline_bot, "_post", make_assertion) await offline_bot.send_video(chat_id, file, thumbnail=file) diff --git a/tests/_files/test_videonote.py b/tests/_files/test_videonote.py index ce69fa8f8..9f2ef7a35 100644 --- a/tests/_files/test_videonote.py +++ b/tests/_files/test_videonote.py @@ -157,7 +157,7 @@ class TestVideoNoteWithoutRequest(VideoNoteTestBase): @pytest.mark.parametrize("local_mode", [True, False]) async def test_send_video_note_local_files( - self, monkeypatch, offline_bot, chat_id, local_mode + self, monkeypatch, offline_bot, chat_id, local_mode, dummy_message_dict ): try: offline_bot._local_mode = local_mode @@ -176,6 +176,7 @@ class TestVideoNoteWithoutRequest(VideoNoteTestBase): test_flag = isinstance(data.get("video_note"), InputFile) and isinstance( data.get("thumbnail"), InputFile ) + return dummy_message_dict monkeypatch.setattr(offline_bot, "_post", make_assertion) await offline_bot.send_video_note(chat_id, file, thumbnail=file) diff --git a/tests/_files/test_voice.py b/tests/_files/test_voice.py index e32bb195c..7516e0f9b 100644 --- a/tests/_files/test_voice.py +++ b/tests/_files/test_voice.py @@ -145,7 +145,9 @@ class TestVoiceWithoutRequest(VoiceTestBase): assert await offline_bot.send_voice(chat_id, voice=voice) @pytest.mark.parametrize("local_mode", [True, False]) - async def test_send_voice_local_files(self, monkeypatch, offline_bot, chat_id, local_mode): + async def test_send_voice_local_files( + self, dummy_message_dict, monkeypatch, offline_bot, chat_id, local_mode + ): try: offline_bot._local_mode = local_mode # For just test that the correct paths are passed as we have no local Bot API set up @@ -159,6 +161,7 @@ class TestVoiceWithoutRequest(VoiceTestBase): test_flag = data.get("voice") == expected else: test_flag = isinstance(data.get("voice"), InputFile) + return dummy_message_dict monkeypatch.setattr(offline_bot, "_post", make_assertion) await offline_bot.send_voice(chat_id, file) diff --git a/tests/_games/test_gamehighscore.py b/tests/_games/test_gamehighscore.py index c07488c80..488f1b3fe 100644 --- a/tests/_games/test_gamehighscore.py +++ b/tests/_games/test_gamehighscore.py @@ -55,8 +55,6 @@ class TestGameHighScoreWithoutRequest(GameHighScoreTestBase): assert highscore.user == self.user assert highscore.score == self.score - assert GameHighScore.de_json(None, offline_bot) is None - def test_to_dict(self, game_highscore): game_highscore_dict = game_highscore.to_dict() diff --git a/tests/_inline/test_inlinekeyboardbutton.py b/tests/_inline/test_inlinekeyboardbutton.py index a71e77489..bb2e004ad 100644 --- a/tests/_inline/test_inlinekeyboardbutton.py +++ b/tests/_inline/test_inlinekeyboardbutton.py @@ -159,9 +159,6 @@ class TestInlineKeyboardButtonWithoutRequest(InlineKeyboardButtonTestBase): ) assert inline_keyboard_button.copy_text == self.copy_text - none = InlineKeyboardButton.de_json({}, offline_bot) - assert none is None - def test_equality(self): a = InlineKeyboardButton("text", callback_data="data") b = InlineKeyboardButton("text", callback_data="data") diff --git a/tests/_inline/test_inputinvoicemessagecontent.py b/tests/_inline/test_inputinvoicemessagecontent.py index 4e35e9f6f..52fc8882c 100644 --- a/tests/_inline/test_inputinvoicemessagecontent.py +++ b/tests/_inline/test_inputinvoicemessagecontent.py @@ -204,7 +204,6 @@ class TestInputInvoiceMessageContentWithoutRequest(InputInvoiceMessageContentTes ) def test_de_json(self, offline_bot): - assert InputInvoiceMessageContent.de_json({}, bot=offline_bot) is None json_dict = { "title": self.title, diff --git a/tests/_payment/stars/test_affiliateinfo.py b/tests/_payment/stars/test_affiliateinfo.py index 9a199b694..33da23378 100644 --- a/tests/_payment/stars/test_affiliateinfo.py +++ b/tests/_payment/stars/test_affiliateinfo.py @@ -64,9 +64,6 @@ class TestAffiliateInfoWithoutRequest(AffiliateInfoTestBase): assert ai.amount == self.amount assert ai.nanostar_amount == self.nanostar_amount - assert AffiliateInfo.de_json(None, offline_bot) is None - assert AffiliateInfo.de_json({}, offline_bot) is None - def test_to_dict(self, affiliate_info): ai_dict = affiliate_info.to_dict() diff --git a/tests/_payment/stars/test_revenuewithdrawelstate.py b/tests/_payment/stars/test_revenuewithdrawelstate.py index 5ff8fddc2..b4a0d0375 100644 --- a/tests/_payment/stars/test_revenuewithdrawelstate.py +++ b/tests/_payment/stars/test_revenuewithdrawelstate.py @@ -77,9 +77,6 @@ class TestRevenueWithdrawalStateWithoutRequest(RevenueWithdrawalStateTestBase): assert rws.api_kwargs == {} assert rws.type == "unknown" - assert RevenueWithdrawalState.de_json(None, offline_bot) is None - assert RevenueWithdrawalState.de_json({}, offline_bot) is None - @pytest.mark.parametrize( ("state", "subclass"), [ @@ -129,8 +126,6 @@ class TestRevenueWithdrawalStatePendingWithoutRequest(RevenueWithdrawalStateTest assert rws.api_kwargs == {} assert rws.type == "pending" - assert RevenueWithdrawalStatePending.de_json(None, offline_bot) is None - def test_to_dict(self, revenue_withdrawal_state_pending): json_dict = revenue_withdrawal_state_pending.to_dict() assert json_dict == {"type": "pending"} @@ -168,8 +163,6 @@ class TestRevenueWithdrawalStateSucceededWithoutRequest(RevenueWithdrawalStateTe assert rws.date == self.date assert rws.url == self.url - assert RevenueWithdrawalStateSucceeded.de_json(None, offline_bot) is None - def test_to_dict(self, revenue_withdrawal_state_succeeded): json_dict = revenue_withdrawal_state_succeeded.to_dict() assert json_dict["type"] == "succeeded" @@ -213,8 +206,6 @@ class TestRevenueWithdrawalStateFailedWithoutRequest(RevenueWithdrawalStateTestB assert rws.api_kwargs == {} assert rws.type == "failed" - assert RevenueWithdrawalStateFailed.de_json(None, offline_bot) is None - def test_to_dict(self, revenue_withdrawal_state_failed): json_dict = revenue_withdrawal_state_failed.to_dict() assert json_dict == {"type": "failed"} diff --git a/tests/_payment/stars/test_startransactions.py b/tests/_payment/stars/test_startransactions.py index 71d706b86..0f91e9023 100644 --- a/tests/_payment/stars/test_startransactions.py +++ b/tests/_payment/stars/test_startransactions.py @@ -89,7 +89,6 @@ class TestStarTransactionWithoutRequest(StarTransactionTestBase): "receiver": self.receiver.to_dict(), } st = StarTransaction.de_json(json_dict, offline_bot) - st_none = StarTransaction.de_json(None, offline_bot) assert st.api_kwargs == {} assert st.id == self.id assert st.amount == self.amount @@ -97,7 +96,6 @@ class TestStarTransactionWithoutRequest(StarTransactionTestBase): assert st.date == from_timestamp(self.date) assert st.source == self.source assert st.receiver == self.receiver - assert st_none is None def test_de_json_star_transaction_localization( self, tz_bot, offline_bot, raw_bot, star_transaction @@ -178,10 +176,8 @@ class TestStarTransactionsWithoutRequest(StarTransactionsTestBase): "transactions": [t.to_dict() for t in self.transactions], } st = StarTransactions.de_json(json_dict, offline_bot) - st_none = StarTransactions.de_json(None, offline_bot) assert st.api_kwargs == {} assert st.transactions == tuple(self.transactions) - assert st_none is None def test_to_dict(self, star_transactions): expected_dict = { diff --git a/tests/_payment/stars/test_transactionpartner.py b/tests/_payment/stars/test_transactionpartner.py index 0982700cf..511ad87a0 100644 --- a/tests/_payment/stars/test_transactionpartner.py +++ b/tests/_payment/stars/test_transactionpartner.py @@ -114,9 +114,6 @@ class TestTransactionPartnerWithoutRequest(TransactionPartnerTestBase): assert transaction_partner.api_kwargs == {} assert transaction_partner.type == "unknown" - assert TransactionPartner.de_json(None, offline_bot) is None - assert TransactionPartner.de_json({}, offline_bot) is None - @pytest.mark.parametrize( ("tp_type", "subclass"), [ @@ -191,9 +188,6 @@ class TestTransactionPartnerAffiliateProgramWithoutRequest(TransactionPartnerTes assert tp.commission_per_mille == self.commission_per_mille assert tp.sponsor_user == self.sponsor_user - assert TransactionPartnerAffiliateProgram.de_json(None, offline_bot) is None - assert TransactionPartnerAffiliateProgram.de_json({}, offline_bot) is None - def test_to_dict(self, transaction_partner_affiliate_program): json_dict = transaction_partner_affiliate_program.to_dict() assert json_dict["type"] == self.type @@ -243,8 +237,6 @@ class TestTransactionPartnerFragmentWithoutRequest(TransactionPartnerTestBase): assert tp.type == "fragment" assert tp.withdrawal_state == self.withdrawal_state - assert TransactionPartnerFragment.de_json(None, offline_bot) is None - def test_to_dict(self, transaction_partner_fragment): json_dict = transaction_partner_fragment.to_dict() assert json_dict["type"] == self.type @@ -303,9 +295,6 @@ class TestTransactionPartnerUserWithoutRequest(TransactionPartnerTestBase): assert tp.paid_media_payload == self.paid_media_payload assert tp.subscription_period == self.subscription_period - assert TransactionPartnerUser.de_json(None, offline_bot) is None - assert TransactionPartnerUser.de_json({}, offline_bot) is None - def test_to_dict(self, transaction_partner_user): json_dict = transaction_partner_user.to_dict() assert json_dict["type"] == self.type @@ -355,8 +344,6 @@ class TestTransactionPartnerOtherWithoutRequest(TransactionPartnerTestBase): assert tp.api_kwargs == {} assert tp.type == "other" - assert TransactionPartnerOther.de_json(None, offline_bot) is None - def test_to_dict(self, transaction_partner_other): json_dict = transaction_partner_other.to_dict() assert json_dict == {"type": self.type} @@ -397,8 +384,6 @@ class TestTransactionPartnerTelegramAdsWithoutRequest(TransactionPartnerTestBase assert tp.api_kwargs == {} assert tp.type == "telegram_ads" - assert TransactionPartnerTelegramAds.de_json(None, offline_bot) is None - def test_to_dict(self, transaction_partner_telegram_ads): json_dict = transaction_partner_telegram_ads.to_dict() assert json_dict == {"type": self.type} @@ -442,8 +427,6 @@ class TestTransactionPartnerTelegramApiWithoutRequest(TransactionPartnerTestBase assert tp.type == "telegram_api" assert tp.request_count == self.request_count - assert TransactionPartnerTelegramApi.de_json(None, offline_bot) is None - def test_to_dict(self, transaction_partner_telegram_api): json_dict = transaction_partner_telegram_api.to_dict() assert json_dict["type"] == self.type diff --git a/tests/conftest.py b/tests/conftest.py index 7147fa8f7..9f67e91db 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -37,7 +37,7 @@ from telegram import ( User, ) from telegram.ext import Defaults -from tests.auxil.build_messages import DATE +from tests.auxil.build_messages import DATE, make_message from tests.auxil.ci_bots import BOT_INFO_PROVIDER, JOB_INDEX from tests.auxil.constants import PRIVATE_KEY, TEST_TOPIC_ICON_COLOR, TEST_TOPIC_NAME from tests.auxil.envvars import GITHUB_ACTION, RUN_TEST_OFFICIAL, TEST_WITH_OPT_DEPS @@ -324,3 +324,13 @@ def timezone(tzinfo): @pytest.fixture def tmp_file(tmp_path) -> Path: return tmp_path / uuid4().hex + + +@pytest.fixture(scope="session") +def dummy_message(): + return make_message("dummy_message") + + +@pytest.fixture(scope="session") +def dummy_message_dict(dummy_message): + return dummy_message.to_dict() diff --git a/tests/test_bot.py b/tests/test_bot.py index 7977efec3..e3ddf7e6f 100644 --- a/tests/test_bot.py +++ b/tests/test_bot.py @@ -43,6 +43,7 @@ from telegram import ( Chat, ChatAdministratorRights, ChatFullInfo, + ChatInviteLink, ChatPermissions, Dice, InlineKeyboardButton, @@ -1432,7 +1433,9 @@ class TestBotWithoutRequest: ) @pytest.mark.parametrize("local_mode", [True, False]) - async def test_set_chat_photo_local_files(self, monkeypatch, offline_bot, chat_id, local_mode): + async def test_set_chat_photo_local_files( + self, dummy_message_dict, monkeypatch, offline_bot, chat_id, local_mode + ): try: offline_bot._local_mode = local_mode # For just test that the correct paths are passed as we have no local Bot API set up @@ -2228,14 +2231,31 @@ class TestBotWithoutRequest: api_kwargs={"chat_id": 2, "user_id": 32, "until_date": until_timestamp}, ) - async def test_business_connection_id_argument(self, offline_bot, monkeypatch): + async def test_business_connection_id_argument( + self, offline_bot, monkeypatch, dummy_message_dict + ): """We can't connect to a business acc, so we just test that the correct data is passed. We also can't test every single method easily, so we just test a few. Our linting will catch any unused args with the others.""" + return_values = asyncio.Queue() + await return_values.put(dummy_message_dict) + await return_values.put( + Poll( + id="42", + question="question", + options=[PollOption("option", 0)], + total_voter_count=5, + is_closed=True, + is_anonymous=True, + type="regular", + ).to_dict() + ) + await return_values.put(True) + await return_values.put(True) async def make_assertion(url, request_data: RequestData, *args, **kwargs): assert request_data.parameters.get("business_connection_id") == 42 - return {} + return await return_values.get() monkeypatch.setattr(offline_bot.request, "post", make_assertion) @@ -2348,6 +2368,9 @@ class TestBotWithoutRequest: async def make_assertion(url, request_data: RequestData, *args, **kwargs): assert request_data.parameters.get("subscription_period") == 2592000 assert request_data.parameters.get("subscription_price") == 6 + return ChatInviteLink( + "https://t.me/joinchat/invite_link", User(1, "first", False), False, False, False + ).to_dict() monkeypatch.setattr(offline_bot.request, "post", make_assertion) diff --git a/tests/test_botcommand.py b/tests/test_botcommand.py index f38abb320..9c63471cd 100644 --- a/tests/test_botcommand.py +++ b/tests/test_botcommand.py @@ -45,8 +45,6 @@ class TestBotCommandWithoutRequest: assert bot_command.command == self.command assert bot_command.description == self.description - assert BotCommand.de_json(None, offline_bot) is None - def test_to_dict(self, bot_command): bot_command_dict = bot_command.to_dict() diff --git a/tests/test_botcommandscope.py b/tests/test_botcommandscope.py index a4bddfc8f..46141eeeb 100644 --- a/tests/test_botcommandscope.py +++ b/tests/test_botcommandscope.py @@ -129,8 +129,6 @@ class TestBotCommandScopeWithoutRequest: cls = scope_class_and_type[0] type_ = scope_class_and_type[1] - assert cls.de_json({}, offline_bot) is None - json_dict = {"type": type_, "chat_id": chat_id, "user_id": 42} bot_command_scope = BotCommandScope.de_json(json_dict, offline_bot) assert set(bot_command_scope.api_kwargs.keys()) == {"chat_id", "user_id"} - set( diff --git a/tests/test_chatbackground.py b/tests/test_chatbackground.py index ccf90d411..39a1b4d1f 100644 --- a/tests/test_chatbackground.py +++ b/tests/test_chatbackground.py @@ -170,7 +170,6 @@ class TestBackgroundTypeWithoutRequest: def test_de_json_required_args(self, offline_bot, background_type): cls = background_type.__class__ - assert cls.de_json({}, offline_bot) is None json_dict = make_json_dict(background_type) const_background_type = BackgroundType.de_json(json_dict, offline_bot) @@ -277,7 +276,6 @@ class TestBackgroundFillWithoutRequest: def test_de_json_required_args(self, offline_bot, background_fill): cls = background_fill.__class__ - assert cls.de_json({}, offline_bot) is None json_dict = make_json_dict(background_fill) const_background_fill = BackgroundFill.de_json(json_dict, offline_bot) diff --git a/tests/test_chatboost.py b/tests/test_chatboost.py index 1f1d71ad5..d83769702 100644 --- a/tests/test_chatboost.py +++ b/tests/test_chatboost.py @@ -174,8 +174,6 @@ class TestChatBoostSourceTypesWithoutRequest: def test_de_json_required_args(self, offline_bot, chat_boost_source): cls = chat_boost_source.__class__ - assert cls.de_json({}, offline_bot) is None - assert ChatBoost.de_json({}, offline_bot) is None json_dict = make_json_dict(chat_boost_source) const_boost_source = ChatBoostSource.de_json(json_dict, offline_bot) diff --git a/tests/test_chatmember.py b/tests/test_chatmember.py index a9f3ebabe..9df27235e 100644 --- a/tests/test_chatmember.py +++ b/tests/test_chatmember.py @@ -207,7 +207,6 @@ class TestChatMemberTypesWithoutRequest: def test_de_json_required_args(self, offline_bot, chat_member_type): cls = chat_member_type.__class__ - assert cls.de_json({}, offline_bot) is None json_dict = make_json_dict(chat_member_type) const_chat_member = ChatMember.de_json(json_dict, offline_bot) diff --git a/tests/test_copytextbutton.py b/tests/test_copytextbutton.py index 7092456d4..8bdf879c1 100644 --- a/tests/test_copytextbutton.py +++ b/tests/test_copytextbutton.py @@ -46,7 +46,6 @@ class TestCopyTextButtonWithoutRequest(CopyTextButtonTestBase): assert copy_text_button.api_kwargs == {} assert copy_text_button.text == self.text - assert CopyTextButton.de_json(None, offline_bot) is None def test_to_dict(self, copy_text_button): copy_text_button_dict = copy_text_button.to_dict() diff --git a/tests/test_dice.py b/tests/test_dice.py index de82d29ae..95b000e7e 100644 --- a/tests/test_dice.py +++ b/tests/test_dice.py @@ -46,7 +46,6 @@ class TestDiceWithoutRequest(DiceTestBase): assert dice.value == self.value assert dice.emoji == emoji - assert Dice.de_json(None, offline_bot) is None def test_to_dict(self, dice): dice_dict = dice.to_dict() diff --git a/tests/test_forum.py b/tests/test_forum.py index 2237742a4..ef9c9f38b 100644 --- a/tests/test_forum.py +++ b/tests/test_forum.py @@ -60,7 +60,6 @@ class TestForumTopicWithoutRequest: assert forum_topic_object.icon_custom_emoji_id == emoji_id def test_de_json(self, offline_bot, emoji_id, forum_group_id): - assert ForumTopic.de_json(None, bot=offline_bot) is None json_dict = { "message_thread_id": forum_group_id, @@ -307,7 +306,6 @@ class TestForumTopicCreatedWithoutRequest: assert topic_created.name == TEST_TOPIC_NAME def test_de_json(self, offline_bot): - assert ForumTopicCreated.de_json(None, bot=offline_bot) is None json_dict = {"icon_color": TEST_TOPIC_ICON_COLOR, "name": TEST_TOPIC_NAME} action = ForumTopicCreated.de_json(json_dict, offline_bot) @@ -395,8 +393,6 @@ class TestForumTopicEdited: assert topic_edited.icon_custom_emoji_id == emoji_id def test_de_json(self, bot, emoji_id): - assert ForumTopicEdited.de_json(None, bot=bot) is None - json_dict = {"name": TEST_TOPIC_NAME, "icon_custom_emoji_id": emoji_id} action = ForumTopicEdited.de_json(json_dict, bot) assert action.api_kwargs == {} diff --git a/tests/test_gifts.py b/tests/test_gifts.py index e7e13c75c..b7300e091 100644 --- a/tests/test_gifts.py +++ b/tests/test_gifts.py @@ -76,8 +76,6 @@ class TestGiftWithoutRequest(GiftTestBase): assert gift.total_count == self.total_count assert gift.remaining_count == self.remaining_count - assert Gift.de_json(None, offline_bot) is None - def test_to_dict(self, gift): gift_dict = gift.to_dict() @@ -237,8 +235,6 @@ class TestGiftsWithoutRequest(GiftsTestBase): assert de_json_gift.total_count == original_gift.total_count assert de_json_gift.remaining_count == original_gift.remaining_count - assert Gifts.de_json(None, offline_bot) is None - def test_to_dict(self, gifts): gifts_dict = gifts.to_dict() diff --git a/tests/test_giveaway.py b/tests/test_giveaway.py index 3ef8bb7a1..35228d5e5 100644 --- a/tests/test_giveaway.py +++ b/tests/test_giveaway.py @@ -94,8 +94,6 @@ class TestGiveawayWithoutRequest: assert giveaway.premium_subscription_month_count == self.premium_subscription_month_count assert giveaway.prize_star_count == self.prize_star_count - assert Giveaway.de_json(None, offline_bot) is None - def test_de_json_localization(self, tz_bot, offline_bot, raw_bot): json_dict = { "chats": [chat.to_dict() for chat in self.chats], @@ -196,8 +194,6 @@ class TestGiveawayCreatedWithoutRequest: assert gac.api_kwargs == {} assert gac.prize_star_count == self.prize_star_count - assert Giveaway.de_json(None, bot) is None - def test_to_dict(self, giveaway_created): gac_dict = giveaway_created.to_dict() @@ -281,8 +277,6 @@ class TestGiveawayWinnersWithoutRequest: assert giveaway_winners.prize_description == self.prize_description assert giveaway_winners.prize_star_count == self.prize_star_count - assert GiveawayWinners.de_json(None, offline_bot) is None - def test_de_json_localization(self, tz_bot, offline_bot, raw_bot): json_dict = { "chat": self.chat.to_dict(), @@ -411,8 +405,6 @@ class TestGiveawayCompletedWithoutRequest: assert giveaway_completed.giveaway_message == self.giveaway_message assert giveaway_completed.is_star_giveaway == self.is_star_giveaway - assert GiveawayCompleted.de_json(None, offline_bot) is None - def test_to_dict(self, giveaway_completed): giveaway_completed_dict = giveaway_completed.to_dict() diff --git a/tests/test_inlinequeryresultsbutton.py b/tests/test_inlinequeryresultsbutton.py index 1ec59573a..521afab13 100644 --- a/tests/test_inlinequeryresultsbutton.py +++ b/tests/test_inlinequeryresultsbutton.py @@ -52,8 +52,6 @@ class TestInlineQueryResultsButtonWithoutRequest(InlineQueryResultsButtonTestBas assert inline_query_results_button_dict["web_app"] == self.web_app.to_dict() def test_de_json(self, offline_bot): - assert InlineQueryResultsButton.de_json(None, offline_bot) is None - assert InlineQueryResultsButton.de_json({}, offline_bot) is None json_dict = { "text": self.text, diff --git a/tests/test_keyboardbutton.py b/tests/test_keyboardbutton.py index 91f5ccab7..42fdfeee8 100644 --- a/tests/test_keyboardbutton.py +++ b/tests/test_keyboardbutton.py @@ -108,9 +108,6 @@ class TestKeyboardButtonWithoutRequest(KeyboardButtonTestBase): assert keyboard_button.request_chat == self.request_chat assert keyboard_button.request_users == self.request_users - none = KeyboardButton.de_json({}, None) - assert none is None - def test_equality(self): a = KeyboardButton("test", request_contact=True) b = KeyboardButton("test", request_contact=True) diff --git a/tests/test_keyboardbuttonrequest.py b/tests/test_keyboardbuttonrequest.py index 9d9a02952..f0484ea20 100644 --- a/tests/test_keyboardbuttonrequest.py +++ b/tests/test_keyboardbuttonrequest.py @@ -179,9 +179,6 @@ class TestKeyboardButtonRequestChatWithoutRequest(KeyboardButtonRequestChatTestB assert request_chat.bot_administrator_rights == self.bot_administrator_rights assert request_chat.bot_is_member == self.bot_is_member - empty_chat = KeyboardButtonRequestChat.de_json({}, offline_bot) - assert empty_chat is None - def test_equality(self): a = KeyboardButtonRequestChat(self.request_id, True) b = KeyboardButtonRequestChat(self.request_id, True) diff --git a/tests/test_menubutton.py b/tests/test_menubutton.py index d9ae7c1ef..e03405066 100644 --- a/tests/test_menubutton.py +++ b/tests/test_menubutton.py @@ -119,9 +119,6 @@ class TestMenuButtonWithoutRequest(MenuButtonTestBase): if "text" in cls.__slots__: assert menu_button.text == self.text - assert cls.de_json(None, offline_bot) is None - assert MenuButton.de_json({}, offline_bot) is None - def test_de_json_invalid_type(self, offline_bot): json_dict = {"type": "invalid", "text": self.text, "web_app": self.web_app.to_dict()} menu_button = MenuButton.de_json(json_dict, offline_bot) diff --git a/tests/test_messageorigin.py b/tests/test_messageorigin.py index be85d73b3..048079529 100644 --- a/tests/test_messageorigin.py +++ b/tests/test_messageorigin.py @@ -138,7 +138,6 @@ class TestMessageOriginTypesWithoutRequest: def test_de_json_required_args(self, offline_bot, message_origin_type): cls = message_origin_type.__class__ - assert cls.de_json({}, offline_bot) is None json_dict = make_json_dict(message_origin_type) const_message_origin = MessageOrigin.de_json(json_dict, offline_bot) diff --git a/tests/test_paidmedia.py b/tests/test_paidmedia.py index ee2ea9f96..77e91efcf 100644 --- a/tests/test_paidmedia.py +++ b/tests/test_paidmedia.py @@ -193,9 +193,6 @@ class TestPaidMediaWithoutRequest(PaidMediaTestBase): if "photo" in cls.__slots__: assert pm.photo == self.photo - assert cls.de_json(None, offline_bot) is None - assert PaidMedia.de_json({}, offline_bot) is None - def test_de_json_invalid_type(self, offline_bot): json_dict = { "type": "invalid", @@ -308,10 +305,8 @@ class TestPaidMediaInfoWithoutRequest(PaidMediaInfoTestBase): "paid_media": [t.to_dict() for t in self.paid_media], } pmi = PaidMediaInfo.de_json(json_dict, offline_bot) - pmi_none = PaidMediaInfo.de_json(None, offline_bot) assert pmi.paid_media == tuple(self.paid_media) assert pmi.star_count == self.star_count - assert pmi_none is None def test_to_dict(self, paid_media_info): assert paid_media_info.to_dict() == { @@ -353,11 +348,9 @@ class TestPaidMediaPurchasedWithoutRequest(PaidMediaPurchasedTestBase): "paid_media_payload": self.paid_media_payload, } pmp = PaidMediaPurchased.de_json(json_dict, bot) - pmp_none = PaidMediaPurchased.de_json(None, bot) assert pmp.from_user == self.from_user assert pmp.paid_media_payload == self.paid_media_payload assert pmp.api_kwargs == {} - assert pmp_none is None def test_to_dict(self, paid_media_purchased): assert paid_media_purchased.to_dict() == { diff --git a/tests/test_poll.py b/tests/test_poll.py index 4d5304fdc..134f0429c 100644 --- a/tests/test_poll.py +++ b/tests/test_poll.py @@ -54,7 +54,6 @@ class TestInputPollOptionWithoutRequest(InputPollOptionTestBase): ), "duplicate slot" def test_de_json(self): - assert InputPollOption.de_json({}, None) is None json_dict = { "text": self.text, @@ -144,7 +143,7 @@ class TestPollOptionWithoutRequest(PollOptionTestBase): "text_entities": [e.to_dict() for e in self.text_entities], } poll_option = PollOption.de_json(json_dict, None) - assert PollOption.de_json(None, None) is None + assert poll_option.api_kwargs == {} assert poll_option.text == self.text diff --git a/tests/test_reaction.py b/tests/test_reaction.py index 79f3e2c40..fad9d2bb9 100644 --- a/tests/test_reaction.py +++ b/tests/test_reaction.py @@ -117,8 +117,6 @@ class TestReactionTypesWithoutRequest: def test_de_json_required_args(self, offline_bot, reaction_type): cls = reaction_type.__class__ - assert cls.de_json(None, offline_bot) is None - assert ReactionType.de_json({}, offline_bot) is None json_dict = make_json_dict(reaction_type) const_reaction_type = ReactionType.de_json(json_dict, offline_bot) @@ -252,8 +250,6 @@ class TestReactionCountWithoutRequest: assert reaction_count.type.emoji == self.type.emoji assert reaction_count.total_count == self.total_count - assert ReactionCount.de_json(None, offline_bot) is None - def test_to_dict(self, reaction_count): reaction_count_dict = reaction_count.to_dict() diff --git a/tests/test_reply.py b/tests/test_reply.py index a450a721d..2030f9a6c 100644 --- a/tests/test_reply.py +++ b/tests/test_reply.py @@ -93,8 +93,6 @@ class TestExternalReplyInfoWithoutRequest(ExternalReplyInfoTestBase): assert external_reply_info.giveaway == self.giveaway assert external_reply_info.paid_media == self.paid_media - assert ExternalReplyInfo.de_json(None, offline_bot) is None - def test_to_dict(self, external_reply_info): ext_reply_info_dict = external_reply_info.to_dict() @@ -167,8 +165,6 @@ class TestTextQuoteWithoutRequest(TextQuoteTestBase): assert text_quote.entities == tuple(self.entities) assert text_quote.is_manual == self.is_manual - assert TextQuote.de_json(None, offline_bot) is None - def test_to_dict(self, text_quote): text_quote_dict = text_quote.to_dict() @@ -255,8 +251,6 @@ class TestReplyParametersWithoutRequest(ReplyParametersTestBase): assert reply_parameters.quote_entities == tuple(self.quote_entities) assert reply_parameters.quote_position == self.quote_position - assert ReplyParameters.de_json(None, offline_bot) is None - def test_to_dict(self, reply_parameters): reply_parameters_dict = reply_parameters.to_dict() diff --git a/tests/test_shared.py b/tests/test_shared.py index 9cc8d4bca..aa565d666 100644 --- a/tests/test_shared.py +++ b/tests/test_shared.py @@ -59,8 +59,6 @@ class TestUsersSharedWithoutRequest(UsersSharedTestBase): assert users_shared.request_id == self.request_id assert users_shared.users == self.users - assert UsersShared.de_json({}, offline_bot) is None - def test_equality(self): a = UsersShared(self.request_id, users=self.users) b = UsersShared(self.request_id, users=self.users) @@ -209,8 +207,6 @@ class TestSharedUserWithoutRequest(SharedUserTestBase): assert shared_user.username == self.username assert shared_user.photo == self.photo - assert SharedUser.de_json({}, offline_bot) is None - def test_equality(self, chat_shared): a = SharedUser( self.user_id, diff --git a/tests/test_story.py b/tests/test_story.py index 190c4ec13..51df3a7fc 100644 --- a/tests/test_story.py +++ b/tests/test_story.py @@ -45,7 +45,6 @@ class TestStoryWithoutRequest(StoryTestBase): assert story.chat == self.chat assert story.id == self.id assert isinstance(story, Story) - assert Story.de_json(None, offline_bot) is None def test_to_dict(self, story): story_dict = story.to_dict() diff --git a/tests/test_telegramobject.py b/tests/test_telegramobject.py index 73d1e62e5..18fb9672b 100644 --- a/tests/test_telegramobject.py +++ b/tests/test_telegramobject.py @@ -103,7 +103,7 @@ class TestTelegramObject: self._id_attrs = (self.arg,) - assert SubClass.de_list([{"arg": 1}, None, {"arg": 2}, None], bot) == ( + assert SubClass.de_list([{"arg": 1}, {"arg": 2}], bot) == ( SubClass(1), SubClass(2), ) diff --git a/tests/test_update.py b/tests/test_update.py index 0e91efcc9..baeff8b74 100644 --- a/tests/test_update.py +++ b/tests/test_update.py @@ -252,11 +252,6 @@ class TestUpdateWithoutRequest(UpdateTestBase): assert getattr(update, _type) == paramdict[_type] assert i == 1 - def test_update_de_json_empty(self, offline_bot): - update = Update.de_json(None, offline_bot) - - assert update is None - def test_to_dict(self, update): update_dict = update.to_dict() diff --git a/tests/test_videochat.py b/tests/test_videochat.py index e5de669c6..6e527181f 100644 --- a/tests/test_videochat.py +++ b/tests/test_videochat.py @@ -162,7 +162,6 @@ class TestVideoChatScheduledWithoutRequest: assert VideoChatScheduled(self.start_date).start_date == self.start_date def test_de_json(self, offline_bot): - assert VideoChatScheduled.de_json({}, bot=offline_bot) is None json_dict = {"start_date": to_timestamp(self.start_date)} video_chat_scheduled = VideoChatScheduled.de_json(json_dict, offline_bot) diff --git a/tests/test_webhookinfo.py b/tests/test_webhookinfo.py index 4b6ab2ebb..c010ad619 100644 --- a/tests/test_webhookinfo.py +++ b/tests/test_webhookinfo.py @@ -99,9 +99,6 @@ class TestWebhookInfoWithoutRequest(WebhookInfoTestBase): self.last_synchronization_error_date ) - none = WebhookInfo.de_json(None, offline_bot) - assert none is None - def test_de_json_localization(self, offline_bot, raw_bot, tz_bot): json_dict = { "url": self.url,