self = <tests.test_callbackquery.TestCallbackQueryWithoutRequest object at 0x0000022AA3095AE0>
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x0000022AA306B3F0>
callback_query = CallbackQuery(chat_instance='chat_instance', data='data', from_user=User(first_name='test_user', id=1, is_bot=False), ...ser=User(first_name='bot', id=5, is_bot=False), group_chat_created=False, message_id=3, supergroup_chat_created=False))
async def test_copy_message(self, monkeypatch, callback_query):
if isinstance(callback_query.message, InaccessibleMessage):
with pytest.raises(TypeError, match="inaccessible message"):
await callback_query.copy_message(1)
return
if callback_query.inline_message_id:
pytest.skip("Can't copy inline messages")
async def make_assertion(*args, **kwargs):
id_ = kwargs["from_chat_id"] == callback_query.message.chat_id
chat_id = kwargs["chat_id"] == 1
message = kwargs["message_id"] == callback_query.message.message_id
return id_ and message and chat_id
> assert check_shortcut_signature(
CallbackQuery.copy_message,
Bot.copy_message,
["message_id", "from_chat_id"],
[],
)
tests\test_callbackquery.py:527:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
shortcut = <function CallbackQuery.copy_message at 0x0000022AA018DA80>
bot_method = <function Bot.copy_message at 0x0000022AA01E1D00>
shortcut_kwargs = ['message_id', 'from_chat_id'], additional_kwargs = []
annotation_overrides = {}
def check_shortcut_signature(
shortcut: Callable,
bot_method: Callable,
shortcut_kwargs: list[str],
additional_kwargs: list[str],
annotation_overrides: Optional[dict[str, tuple[Any, Any]]] = None,
) -> bool:
"""
Checks that the signature of a shortcut matches the signature of the underlying bot method.
Args:
shortcut: The shortcut, e.g. :meth:`telegram.Message.reply_text`
bot_method: The bot method, e.g. :meth:`telegram.Bot.send_message`
shortcut_kwargs: The kwargs passed by the shortcut directly, e.g. ``chat_id``
additional_kwargs: Additional kwargs of the shortcut that the bot method doesn't have, e.g.
``quote``.
annotation_overrides: A dictionary of exceptions for the annotation comparison. The key is
the name of the argument, the value is a tuple of the expected annotation and
the default value. E.g. ``{'parse_mode': (str, 'None')}``.
Returns:
:obj:`bool`: Whether or not the signature matches.
"""
annotation_overrides = annotation_overrides or {}
def resolve_class(class_name: str) -> Optional[type]:
"""Attempts to resolve a PTB class (telegram module only) from a ForwardRef.
E.g. resolves <class 'telegram._files.sticker.StickerSet'> from "StickerSet".
Returns a class on success, :obj:`None` if nothing could be resolved.
"""
for module in telegram, telegram.request:
cls = getattr(module, class_name, None)
if cls is not None:
return cls
return None # for ruff
shortcut_sig = inspect.signature(shortcut)
effective_shortcut_args = set(shortcut_sig.parameters.keys()).difference(additional_kwargs)
effective_shortcut_args.discard("self")
bot_sig = inspect.signature(bot_method)
expected_args = set(bot_sig.parameters.keys()).difference(shortcut_kwargs)
expected_args.discard("self")
len_expected = len(expected_args)
len_effective = len(effective_shortcut_args)
if len_expected > len_effective:
> raise Exception(
f"Shortcut signature is missing {len_expected - len_effective} arguments "
f"of the underlying Bot method: {expected_args - effective_shortcut_args}"
)
E Exception: Shortcut signature is missing 1 arguments of the underlying Bot method: {'allow_paid_broadcast'}
tests\auxil\bot_method_checks.py:107: Exception