From b8fbb89faecf26101a2441f9f5358506cb7f2130 Mon Sep 17 00:00:00 2001 From: Bibo-Joshi <22366557+Bibo-Joshi@users.noreply.github.com> Date: Tue, 27 Dec 2022 19:02:50 +0100 Subject: [PATCH] Add Log Decorator to `Bot.get_webhook_info` (#3442) --- telegram/_bot.py | 1 + tests/test_bot.py | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/telegram/_bot.py b/telegram/_bot.py index 95a9b23a022..35dc629bdb3 100644 --- a/telegram/_bot.py +++ b/telegram/_bot.py @@ -3929,6 +3929,7 @@ async def delete_chat_sticker_set( ) return result + @_log async def get_webhook_info( self, *, diff --git a/tests/test_bot.py b/tests/test_bot.py index f8489bbd03c..cbbb0696c29 100644 --- a/tests/test_bot.py +++ b/tests/test_bot.py @@ -22,6 +22,7 @@ import inspect import logging import pickle +import re import socket import sys import time @@ -320,6 +321,18 @@ async def test_log_decorator(self, bot, caplog): assert caplog.records[0].getMessage().startswith("Entering: get_me") assert caplog.records[-1].getMessage().startswith("Exiting: get_me") + @bot_methods(ext_bot=False) + def test_api_methods_have_log_decorator(self, bot_class, bot_method_name, bot_method): + """Check that all bot methods have the log decorator ...""" + # not islower() skips the camelcase aliases + if not bot_method_name.islower(): + return + source = inspect.getsource(bot_method) + assert ( + # Use re.match to only match at *the beginning* of the string + re.match(rf"\s*\@\_log\s*async def {bot_method_name}", source) + ), f"{bot_method_name} is missing the @_log decorator" + @pytest.mark.parametrize( "acd_in,maxsize", [(True, 1024), (False, 1024), (0, 0), (None, None)],