Skip to content

Commit

Permalink
Add Log Decorator to Bot.get_webhook_info (#3442)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bibo-Joshi committed Dec 27, 2022
1 parent f365036 commit b8fbb89
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions telegram/_bot.py
Expand Up @@ -3929,6 +3929,7 @@ async def delete_chat_sticker_set(
)
return result

@_log
async def get_webhook_info(
self,
*,
Expand Down
13 changes: 13 additions & 0 deletions tests/test_bot.py
Expand Up @@ -22,6 +22,7 @@
import inspect
import logging
import pickle
import re
import socket
import sys
import time
Expand Down Expand Up @@ -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)],
Expand Down

0 comments on commit b8fbb89

Please sign in to comment.