From c9b8176492f3f91ee2e8ecb58fafc9edb36e0c1d Mon Sep 17 00:00:00 2001 From: Hinrich Mahler <22366557+Bibo-Joshi@users.noreply.github.com> Date: Mon, 26 Dec 2022 12:20:41 +0100 Subject: [PATCH 1/2] Add log decorator to `get_webhook_info` and add test that ensure that all API methods have that decorator --- 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..6f92d3e4b24 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 = "".join(inspect.getsourcelines(bot_method)[0]) + 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)], From 6ef7808036f7b77f470b8d4e468a9d23c5bb0b5c Mon Sep 17 00:00:00 2001 From: Hinrich Mahler <22366557+Bibo-Joshi@users.noreply.github.com> Date: Mon, 26 Dec 2022 22:47:17 +0100 Subject: [PATCH 2/2] review --- tests/test_bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_bot.py b/tests/test_bot.py index 6f92d3e4b24..cbbb0696c29 100644 --- a/tests/test_bot.py +++ b/tests/test_bot.py @@ -327,7 +327,7 @@ def test_api_methods_have_log_decorator(self, bot_class, bot_method_name, bot_me # not islower() skips the camelcase aliases if not bot_method_name.islower(): return - source = "".join(inspect.getsourcelines(bot_method)[0]) + 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)