Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add log decorator to get_webhook_info and add test #3442

Merged
merged 3 commits into from Dec 27, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 = "".join(inspect.getsourcelines(bot_method)[0])
Bibo-Joshi marked this conversation as resolved.
Show resolved Hide resolved
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