mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-11-21 14:46:29 +01:00
One-Time Code Formatting Improvement via --preview
Flag of black
(#3882)
This commit is contained in:
parent
5b0f1697f1
commit
ab90cd7359
19 changed files with 220 additions and 159 deletions
|
@ -194,7 +194,7 @@ class AdmonitionInserter:
|
|||
)
|
||||
except NotImplementedError as e:
|
||||
raise NotImplementedError(
|
||||
f"Error generating Sphinx 'Available in' admonition "
|
||||
"Error generating Sphinx 'Available in' admonition "
|
||||
f"(admonition_inserter.py). Class {name_of_class_in_attr} present in "
|
||||
f"attribute {target_attr} of class {name_of_inspected_class_in_docstr}"
|
||||
f" could not be resolved. {str(e)}"
|
||||
|
@ -237,7 +237,7 @@ class AdmonitionInserter:
|
|||
)
|
||||
except NotImplementedError as e:
|
||||
raise NotImplementedError(
|
||||
f"Error generating Sphinx 'Available in' admonition "
|
||||
"Error generating Sphinx 'Available in' admonition "
|
||||
f"(admonition_inserter.py). Class {name_of_class_in_prop} present in "
|
||||
f"property {prop_name} of class {name_of_inspected_class_in_docstr}"
|
||||
f" could not be resolved. {str(e)}"
|
||||
|
@ -269,7 +269,7 @@ class AdmonitionInserter:
|
|||
)
|
||||
except NotImplementedError as e:
|
||||
raise NotImplementedError(
|
||||
f"Error generating Sphinx 'Returned in' admonition "
|
||||
"Error generating Sphinx 'Returned in' admonition "
|
||||
f"(admonition_inserter.py). {cls}, method {method_name}. "
|
||||
f"Couldn't resolve type hint in return annotation {ret_annot}. {str(e)}"
|
||||
)
|
||||
|
@ -342,7 +342,7 @@ class AdmonitionInserter:
|
|||
)
|
||||
except NotImplementedError as e:
|
||||
raise NotImplementedError(
|
||||
f"Error generating Sphinx 'Use in' admonition "
|
||||
"Error generating Sphinx 'Use in' admonition "
|
||||
f"(admonition_inserter.py). {cls}, method {method_name}, parameter "
|
||||
f"{param}: Couldn't resolve type hint {param.annotation}. {str(e)}"
|
||||
)
|
||||
|
|
|
@ -18,25 +18,41 @@
|
|||
import inspect
|
||||
|
||||
keyword_args = [
|
||||
(
|
||||
":keyword _sphinx_paramlinks_telegram.Bot.{method}.read_timeout: Value to pass to "
|
||||
":paramref:`telegram.request.BaseRequest.post.read_timeout`. Defaults to {read_timeout}.",
|
||||
":paramref:`telegram.request.BaseRequest.post.read_timeout`. Defaults to {read_timeout}."
|
||||
),
|
||||
":kwtype _sphinx_paramlinks_telegram.Bot.{method}.read_timeout: {read_timeout_type}, optional",
|
||||
(
|
||||
":keyword _sphinx_paramlinks_telegram.Bot.{method}.write_timeout: Value to pass to "
|
||||
":paramref:`telegram.request.BaseRequest.post.write_timeout`. Defaults to {write_timeout}.",
|
||||
":kwtype _sphinx_paramlinks_telegram.Bot.{method}.write_timeout: :obj:`float` | :obj:`None`, "
|
||||
"optional",
|
||||
":paramref:`telegram.request.BaseRequest.post.write_timeout`. Defaults to {write_timeout}."
|
||||
),
|
||||
(
|
||||
":kwtype _sphinx_paramlinks_telegram.Bot.{method}.write_timeout: :obj:`float` |"
|
||||
" :obj:`None`, optional"
|
||||
),
|
||||
(
|
||||
":keyword _sphinx_paramlinks_telegram.Bot.{method}.connect_timeout: Value to pass to "
|
||||
":paramref:`telegram.request.BaseRequest.post.connect_timeout`. Defaults to "
|
||||
":attr:`~telegram.request.BaseRequest.DEFAULT_NONE`.",
|
||||
":attr:`~telegram.request.BaseRequest.DEFAULT_NONE`."
|
||||
),
|
||||
(
|
||||
":kwtype _sphinx_paramlinks_telegram.Bot.{method}.connect_timeout: :obj:`float` | "
|
||||
":obj:`None`, optional",
|
||||
":obj:`None`, optional"
|
||||
),
|
||||
(
|
||||
":keyword _sphinx_paramlinks_telegram.Bot.{method}.pool_timeout: Value to pass to "
|
||||
":paramref:`telegram.request.BaseRequest.post.pool_timeout`. Defaults to "
|
||||
":attr:`~telegram.request.BaseRequest.DEFAULT_NONE`.",
|
||||
":kwtype _sphinx_paramlinks_telegram.Bot.{method}.pool_timeout: :obj:`float` | :obj:`None`, "
|
||||
"optional",
|
||||
":keyword _sphinx_paramlinks_telegram.Bot.{method}.api_kwargs: Arbitrary keyword arguments "
|
||||
"to be passed to the Telegram API.",
|
||||
":attr:`~telegram.request.BaseRequest.DEFAULT_NONE`."
|
||||
),
|
||||
(
|
||||
":kwtype _sphinx_paramlinks_telegram.Bot.{method}.pool_timeout: :obj:`float` |"
|
||||
" :obj:`None`, optional"
|
||||
),
|
||||
(
|
||||
":keyword _sphinx_paramlinks_telegram.Bot.{method}.api_kwargs: Arbitrary keyword arguments"
|
||||
" to be passed to the Telegram API."
|
||||
),
|
||||
":kwtype _sphinx_paramlinks_telegram.Bot.{method}.api_kwargs: :obj:`dict`, optional",
|
||||
"",
|
||||
]
|
||||
|
|
|
@ -96,7 +96,9 @@ linkcheck_ignore = [
|
|||
]
|
||||
linkcheck_allowed_redirects = {
|
||||
# Redirects to the default version are okay
|
||||
r"https://docs\.python-telegram-bot\.org/.*": r"https://docs\.python-telegram-bot\.org/en/[\w\d\.]+/.*",
|
||||
r"https://docs\.python-telegram-bot\.org/.*": (
|
||||
r"https://docs\.python-telegram-bot\.org/en/[\w\d\.]+/.*"
|
||||
),
|
||||
# pre-commit.ci always redirects to the latest run
|
||||
re.escape(
|
||||
"https://results.pre-commit.ci/latest/github/python-telegram-bot/python-telegram-bot/master"
|
||||
|
@ -131,17 +133,20 @@ html_theme_options = {
|
|||
"admonition-title-font-size": "0.95rem",
|
||||
"admonition-font-size": "0.92rem",
|
||||
},
|
||||
"announcement": "PTB has undergone significant changes in v20. Please read the documentation "
|
||||
"announcement": (
|
||||
"PTB has undergone significant changes in v20. Please read the documentation "
|
||||
"carefully and also check out the transition guide in the "
|
||||
'<a href="https://github.com/python-telegram-bot/python-telegram-bot/wiki/'
|
||||
'Transition-guide-to-Version-20.0">wiki</a>.',
|
||||
'Transition-guide-to-Version-20.0">wiki</a>.'
|
||||
),
|
||||
"footer_icons": [
|
||||
{
|
||||
# Telegram channel logo
|
||||
"name": "Telegram Channel",
|
||||
"url": "https://t.me/pythontelegrambotchannel/",
|
||||
# Following svg is from https://react-icons.github.io/react-icons/search?q=telegram
|
||||
"html": '<svg stroke="currentColor" fill="currentColor" stroke-width="0" '
|
||||
"html": (
|
||||
'<svg stroke="currentColor" fill="currentColor" stroke-width="0" '
|
||||
'viewBox="0 0 16 16" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg">'
|
||||
'<path d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zM8.287 5.906c-.778.324-2.334.994'
|
||||
"-4.666 2.01-.378.15-.577.298-.595.442-.03.243.275.339.69.47l.175.055c.408.133."
|
||||
|
@ -151,13 +156,15 @@ html_theme_options = {
|
|||
"8.327.216.589.393.85.571.284.194.568.387.936.629.093.06.183.125.27.187.331.23"
|
||||
"6.63.448.997.414.214-.02.435-.22.547-.82.265-1.417.786-4.486.906-5.751a1.426 "
|
||||
"1.426 0 0 0-.013-.315.337.337 0 0 0-.114-.217.526.526 0 0 0-.31-.093c-.3.005-.7"
|
||||
'63.166-2.984 1.09z"></path></svg>',
|
||||
'63.166-2.984 1.09z"></path></svg>'
|
||||
),
|
||||
"class": "",
|
||||
},
|
||||
{ # Github logo
|
||||
"name": "GitHub",
|
||||
"url": "https://github.com/python-telegram-bot/python-telegram-bot/",
|
||||
"html": '<svg stroke="currentColor" fill="currentColor" stroke-width="0" '
|
||||
"html": (
|
||||
'<svg stroke="currentColor" fill="currentColor" stroke-width="0" '
|
||||
'viewBox="0 0 16 16"><path fill-rule="evenodd" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 '
|
||||
"2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.4"
|
||||
"9-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23"
|
||||
|
@ -166,13 +173,15 @@ html_theme_options = {
|
|||
"7 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.5"
|
||||
"1.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 "
|
||||
'1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0 0 16 8c0-4.42-3.58-8-8-8z">'
|
||||
"</path></svg>",
|
||||
"</path></svg>"
|
||||
),
|
||||
"class": "",
|
||||
},
|
||||
{ # PTB website logo - globe
|
||||
"name": "python-telegram-bot website",
|
||||
"url": "https://python-telegram-bot.org/",
|
||||
"html": '<svg stroke="currentColor" fill="currentColor" stroke-width="0" '
|
||||
"html": (
|
||||
'<svg stroke="currentColor" fill="currentColor" stroke-width="0" '
|
||||
'viewBox="0 0 16 16" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg">'
|
||||
'<path d="M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8zm7.5-6.923c-.67.204-1.335.82-1.887 '
|
||||
"1.855-.143.268-.276.56-.395.872.705.157 1.472.257 2.282.287V1.077zM4.249 3.53"
|
||||
|
@ -195,7 +204,8 @@ html_theme_options = {
|
|||
"8-.995.482-1.565.667.248.92.4 1.938.437 3.008h2.49zM11.27 2.461c.177.334.339.6"
|
||||
"94.482 1.078a8.368 8.368 0 0 0 1.196-.49 7.01 7.01 0 0 0-2.275-1.52c.218.283.4"
|
||||
"18.597.597.932zm-.488 1.343a7.765 7.765 0 0 0-.395-.872C9.835 1.897 9.17 1.282 "
|
||||
'8.5 1.077V4.09c.81-.03 1.577-.13 2.282-.287z"></path></svg>',
|
||||
'8.5 1.077V4.09c.81-.03 1.577-.13 2.282-.287z"></path></svg>'
|
||||
),
|
||||
"class": "",
|
||||
},
|
||||
],
|
||||
|
|
|
@ -115,8 +115,7 @@ async def count_click(update: Update, context: CustomContext) -> None:
|
|||
async def print_users(update: Update, context: CustomContext) -> None:
|
||||
"""Show which users have been using this bot."""
|
||||
await update.message.reply_text(
|
||||
"The following user IDs have used this bot: "
|
||||
f'{", ".join(map(str, context.bot_user_ids))}'
|
||||
f"The following user IDs have used this bot: {', '.join(map(str, context.bot_user_ids))}"
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -57,8 +57,7 @@ async def deep_linked_level_1(update: Update, context: ContextTypes.DEFAULT_TYPE
|
|||
bot = context.bot
|
||||
url = helpers.create_deep_linked_url(bot.username, SO_COOL)
|
||||
text = (
|
||||
"Awesome, you just accessed hidden functionality! "
|
||||
"Now let's get back to the private chat."
|
||||
"Awesome, you just accessed hidden functionality! Now let's get back to the private chat."
|
||||
)
|
||||
keyboard = InlineKeyboardMarkup.from_button(
|
||||
InlineKeyboardButton(text="Continue here!", url=url)
|
||||
|
|
|
@ -40,7 +40,7 @@ async def error_handler(update: object, context: ContextTypes.DEFAULT_TYPE) -> N
|
|||
# You might need to add some logic to deal with messages longer than the 4096 character limit.
|
||||
update_str = update.to_dict() if isinstance(update, Update) else str(update)
|
||||
message = (
|
||||
f"An exception was raised while handling an update\n"
|
||||
"An exception was raised while handling an update\n"
|
||||
f"<pre>update = {html.escape(json.dumps(update_str, indent=2, ensure_ascii=False))}"
|
||||
"</pre>\n\n"
|
||||
f"<pre>context.chat_data = {html.escape(str(context.chat_data))}</pre>\n\n"
|
||||
|
|
|
@ -59,7 +59,7 @@ async def start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int:
|
|||
if context.user_data:
|
||||
reply_text += (
|
||||
f" You already told me your {', '.join(context.user_data.keys())}. Why don't you "
|
||||
f"tell me something more about yourself? Or change anything I already know."
|
||||
"tell me something more about yourself? Or change anything I already know."
|
||||
)
|
||||
else:
|
||||
reply_text += (
|
||||
|
|
|
@ -45,8 +45,10 @@ async def web_app_data(update: Update, context: ContextTypes.DEFAULT_TYPE) -> No
|
|||
# (see webappbot.html)
|
||||
data = json.loads(update.effective_message.web_app_data.data)
|
||||
await update.message.reply_html(
|
||||
text=f"You selected the color with the HEX value <code>{data['hex']}</code>. The "
|
||||
f"corresponding RGB value is <code>{tuple(data['rgb'].values())}</code>.",
|
||||
text=(
|
||||
f"You selected the color with the HEX value <code>{data['hex']}</code>. The "
|
||||
f"corresponding RGB value is <code>{tuple(data['rgb'].values())}</code>."
|
||||
),
|
||||
reply_markup=ReplyKeyboardRemove(),
|
||||
)
|
||||
|
||||
|
|
|
@ -291,8 +291,8 @@ class Bot(TelegramObject, AsyncContextManager["Bot"]):
|
|||
if warning_string:
|
||||
self._warn(
|
||||
f"You set the HTTP version for the {warning_string} HTTPXRequest instance to "
|
||||
f"HTTP/2. The self hosted bot api instances only support HTTP/1.1. You should "
|
||||
f"either run a HTTP proxy in front of it which supports HTTP/2 or use HTTP/1.1.",
|
||||
"HTTP/2. The self hosted bot api instances only support HTTP/1.1. You should "
|
||||
"either run a HTTP proxy in front of it which supports HTTP/2 or use HTTP/1.1.",
|
||||
PTBUserWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
|
|
|
@ -948,7 +948,7 @@ class Application(Generic[BT, CCT, UD, CD, BD, JQ], AsyncContextManager["Applica
|
|||
warn(
|
||||
f"Could not add signal handlers for the stop signals {stop_signals} due to "
|
||||
f"exception `{exc!r}`. If your event loop does not implement `add_signal_handler`,"
|
||||
f" please pass `stop_signals=None`.",
|
||||
" please pass `stop_signals=None`.",
|
||||
stacklevel=3,
|
||||
)
|
||||
|
||||
|
@ -1080,8 +1080,7 @@ class Application(Generic[BT, CCT, UD, CD, BD, JQ], AsyncContextManager["Applica
|
|||
except Exception as exception:
|
||||
if isinstance(exception, ApplicationHandlerStop):
|
||||
warn(
|
||||
"ApplicationHandlerStop is not supported with handlers "
|
||||
"running non-blocking.",
|
||||
"ApplicationHandlerStop is not supported with handlers running non-blocking.",
|
||||
stacklevel=1,
|
||||
)
|
||||
|
||||
|
@ -1186,8 +1185,10 @@ class Application(Generic[BT, CCT, UD, CD, BD, JQ], AsyncContextManager["Applica
|
|||
self.create_task(
|
||||
coroutine,
|
||||
update=update,
|
||||
name=f"Application:{self.bot.id}:process_update_non_blocking"
|
||||
f":{handler}",
|
||||
name=(
|
||||
f"Application:{self.bot.id}:process_update_non_blocking"
|
||||
f":{handler}"
|
||||
),
|
||||
)
|
||||
else:
|
||||
any_blocking = True
|
||||
|
@ -1256,7 +1257,7 @@ class Application(Generic[BT, CCT, UD, CD, BD, JQ], AsyncContextManager["Applica
|
|||
if not self.persistence:
|
||||
raise ValueError(
|
||||
f"ConversationHandler {handler.name} "
|
||||
f"can not be persistent if application has no persistence"
|
||||
"can not be persistent if application has no persistence"
|
||||
)
|
||||
if self._initialized:
|
||||
self.create_task(
|
||||
|
|
|
@ -227,6 +227,7 @@ class CallbackDataCache:
|
|||
# Built a new nested list of buttons by replacing the callback data if needed
|
||||
buttons = [
|
||||
[
|
||||
(
|
||||
# We create a new button instead of replacing callback_data in case the
|
||||
# same object is used elsewhere
|
||||
InlineKeyboardButton(
|
||||
|
@ -235,6 +236,7 @@ class CallbackDataCache:
|
|||
)
|
||||
if btn.callback_data
|
||||
else btn
|
||||
)
|
||||
for btn in column
|
||||
]
|
||||
for column in reply_markup.inline_keyboard
|
||||
|
|
|
@ -414,7 +414,7 @@ class ConversationHandler(BaseHandler[Update, CCT]):
|
|||
):
|
||||
warn(
|
||||
f"Updates handled by {handler.__class__.__name__} only have information about "
|
||||
f"the user, so this handler won't ever be triggered if `per_chat=True`."
|
||||
"the user, so this handler won't ever be triggered if `per_chat=True`."
|
||||
f"{per_faq_link}",
|
||||
stacklevel=2,
|
||||
)
|
||||
|
|
|
@ -763,7 +763,7 @@ class _ChatUserBaseFilter(MessageFilter, ABC):
|
|||
def name(self) -> str:
|
||||
return (
|
||||
f"filters.{self.__class__.__name__}("
|
||||
f'{", ".join(str(s) for s in (self.usernames or self.chat_ids))})'
|
||||
f"{', '.join(str(s) for s in (self.usernames or self.chat_ids))})"
|
||||
)
|
||||
|
||||
@name.setter
|
||||
|
|
|
@ -468,7 +468,11 @@ class TestPassportWithoutRequest(TestPassportBase):
|
|||
assert passport_data.decrypted_data
|
||||
|
||||
async def test_wrong_key(self, bot):
|
||||
short_key = b"-----BEGIN RSA PRIVATE KEY-----\r\nMIIBOQIBAAJBAKU+OZ2jJm7sCA/ec4gngNZhXYPu+DZ/TAwSMl0W7vAPXAsLplBk\r\nO8l6IBHx8N0ZC4Bc65mO3b2G8YAzqndyqH8CAwEAAQJAWOx3jQFzeVXDsOaBPdAk\r\nYTncXVeIc6tlfUl9mOLyinSbRNCy1XicOiOZFgH1rRKOGIC1235QmqxFvdecySoY\r\nwQIhAOFeGgeX9CrEPuSsd9+kqUcA2avCwqdQgSdy2qggRFyJAiEAu7QHT8JQSkHU\r\nDELfzrzc24AhjyG0z1DpGZArM8COascCIDK42SboXj3Z2UXiQ0CEcMzYNiVgOisq\r\nBUd5pBi+2mPxAiAM5Z7G/Sv1HjbKrOGh29o0/sXPhtpckEuj5QMC6E0gywIgFY6S\r\nNjwrAA+cMmsgY0O2fAzEKkDc5YiFsiXaGaSS4eA=\r\n-----END RSA PRIVATE KEY-----"
|
||||
short_key = (
|
||||
b"-----BEGIN RSA PRIVATE"
|
||||
b" KEY-----\r\nMIIBOQIBAAJBAKU+OZ2jJm7sCA/ec4gngNZhXYPu+DZ/TAwSMl0W7vAPXAsLplBk\r\nO8l6IBHx8N0ZC4Bc65mO3b2G8YAzqndyqH8CAwEAAQJAWOx3jQFzeVXDsOaBPdAk\r\nYTncXVeIc6tlfUl9mOLyinSbRNCy1XicOiOZFgH1rRKOGIC1235QmqxFvdecySoY\r\nwQIhAOFeGgeX9CrEPuSsd9+kqUcA2avCwqdQgSdy2qggRFyJAiEAu7QHT8JQSkHU\r\nDELfzrzc24AhjyG0z1DpGZArM8COascCIDK42SboXj3Z2UXiQ0CEcMzYNiVgOisq\r\nBUd5pBi+2mPxAiAM5Z7G/Sv1HjbKrOGh29o0/sXPhtpckEuj5QMC6E0gywIgFY6S\r\nNjwrAA+cMmsgY0O2fAzEKkDc5YiFsiXaGaSS4eA=\r\n-----END"
|
||||
b" RSA PRIVATE KEY-----"
|
||||
)
|
||||
async with make_bot(token=bot.token, private_key=short_key) as b:
|
||||
passport_data = PassportData.de_json(RAW_PASSPORT_DATA, bot=b)
|
||||
with pytest.raises(PassportDecryptionError):
|
||||
|
|
|
@ -301,8 +301,10 @@ class TestInvoiceWithRequest(TestInvoiceBase):
|
|||
suggested_tip_amounts=self.suggested_tip_amounts,
|
||||
start_parameter=self.start_parameter,
|
||||
provider_data=self.provider_data,
|
||||
photo_url="https://raw.githubusercontent.com/"
|
||||
"python-telegram-bot/logos/master/logo/png/ptb-logo_240.png",
|
||||
photo_url=(
|
||||
"https://raw.githubusercontent.com/"
|
||||
"python-telegram-bot/logos/master/logo/png/ptb-logo_240.png"
|
||||
),
|
||||
photo_size=240,
|
||||
photo_width=240,
|
||||
photo_height=240,
|
||||
|
|
|
@ -382,9 +382,11 @@ class TestBasePersistence:
|
|||
methods.sort()
|
||||
with pytest.raises(
|
||||
TypeError,
|
||||
match=", ".join(methods)
|
||||
match=(
|
||||
", ".join(methods)
|
||||
if sys.version_info < (3, 12)
|
||||
else ", ".join(f"'{i}'" for i in methods),
|
||||
else ", ".join(f"'{i}'" for i in methods)
|
||||
),
|
||||
):
|
||||
BasePersistence()
|
||||
|
||||
|
@ -1256,7 +1258,7 @@ class TestBasePersistence:
|
|||
await papp.update_persistence()
|
||||
await asyncio.sleep(0.01)
|
||||
# Conversation should have been updated with the current state, i.e. None
|
||||
assert papp.persistence.updated_conversations == {"conv": ({(1, 1): 1})}
|
||||
assert papp.persistence.updated_conversations == {"conv": {(1, 1): 1}}
|
||||
assert papp.persistence.conversations == {"conv": {(1, 1): None}}
|
||||
|
||||
# Ensure that we warn the user about this!
|
||||
|
@ -1326,7 +1328,7 @@ class TestBasePersistence:
|
|||
|
||||
await papp.update_persistence()
|
||||
await asyncio.sleep(0.05)
|
||||
assert papp.persistence.updated_conversations == {"conv": ({(1, 1): 1})}
|
||||
assert papp.persistence.updated_conversations == {"conv": {(1, 1): 1}}
|
||||
# The result of the pending state wasn't retrieved by the CH yet, so we must be in
|
||||
# state `None`
|
||||
assert papp.persistence.conversations == {"conv": {(1, 1): None}}
|
||||
|
@ -1436,7 +1438,7 @@ class TestBasePersistence:
|
|||
assert papp.persistence.updated_conversations == {}
|
||||
|
||||
await papp.update_persistence()
|
||||
assert papp.persistence.updated_conversations == {"conv_1": ({(1, 1): 1})}
|
||||
assert papp.persistence.updated_conversations == {"conv_1": {(1, 1): 1}}
|
||||
# This is the important part: the persistence is updated with `None` when the conv ends
|
||||
assert papp.persistence.conversations == {"conv_1": {(1, 1): None}}
|
||||
|
||||
|
@ -1468,7 +1470,7 @@ class TestBasePersistence:
|
|||
)
|
||||
assert papp.persistence.updated_conversations == {}
|
||||
await papp.update_persistence()
|
||||
assert papp.persistence.updated_conversations == {"conv": ({(1, 1): 1})}
|
||||
assert papp.persistence.updated_conversations == {"conv": {(1, 1): 1}}
|
||||
assert papp.persistence.conversations == {"conv": {(1, 1): HandlerStates.STATE_1}}
|
||||
|
||||
papp.persistence.reset_tracking()
|
||||
|
|
|
@ -431,21 +431,25 @@ class TestConversationHandler:
|
|||
assert len(recwarn) == 13
|
||||
# now we test the messages, they are raised in the order they are inserted
|
||||
# into the conversation handler
|
||||
assert str(recwarn[0].message) == (
|
||||
"The `ConversationHandler` only handles updates of type `telegram.Update`. "
|
||||
assert (
|
||||
str(recwarn[0].message)
|
||||
== "The `ConversationHandler` only handles updates of type `telegram.Update`. "
|
||||
"StringCommandHandler handles updates of type `str`."
|
||||
)
|
||||
assert str(recwarn[1].message) == (
|
||||
"The `ConversationHandler` only handles updates of type `telegram.Update`. "
|
||||
assert (
|
||||
str(recwarn[1].message)
|
||||
== "The `ConversationHandler` only handles updates of type `telegram.Update`. "
|
||||
"StringRegexHandler handles updates of type `str`."
|
||||
)
|
||||
assert str(recwarn[2].message) == (
|
||||
"PollHandler will never trigger in a conversation since it has no information "
|
||||
assert (
|
||||
str(recwarn[2].message)
|
||||
== "PollHandler will never trigger in a conversation since it has no information "
|
||||
"about the chat or the user who voted in it. Do you mean the "
|
||||
"`PollAnswerHandler`?"
|
||||
)
|
||||
assert str(recwarn[3].message) == (
|
||||
"The `ConversationHandler` only handles updates of type `telegram.Update`. "
|
||||
assert (
|
||||
str(recwarn[3].message)
|
||||
== "The `ConversationHandler` only handles updates of type `telegram.Update`. "
|
||||
"The TypeHandler is set to handle NotUpdate."
|
||||
)
|
||||
|
||||
|
@ -481,17 +485,19 @@ class TestConversationHandler:
|
|||
+ per_faq_link
|
||||
)
|
||||
assert str(recwarn[10].message) == (
|
||||
"If 'per_message=False', 'CallbackQueryHandler' will not be tracked for "
|
||||
"every message." + per_faq_link
|
||||
"If 'per_message=False', 'CallbackQueryHandler' will not be tracked for every message."
|
||||
+ per_faq_link
|
||||
)
|
||||
assert str(recwarn[11].message) == (
|
||||
"Using `conversation_timeout` with nested conversations is currently not "
|
||||
assert (
|
||||
str(recwarn[11].message)
|
||||
== "Using `conversation_timeout` with nested conversations is currently not "
|
||||
"supported. You can still try to use it, but it will likely behave differently"
|
||||
" from what you expect."
|
||||
)
|
||||
|
||||
assert str(recwarn[12].message) == (
|
||||
"If 'per_message=True' is used, 'per_chat=True' should also be used, "
|
||||
assert (
|
||||
str(recwarn[12].message)
|
||||
== "If 'per_message=True' is used, 'per_chat=True' should also be used, "
|
||||
"since message IDs are not globally unique."
|
||||
)
|
||||
|
||||
|
@ -721,8 +727,9 @@ class TestConversationHandler:
|
|||
Path(recwarn[0].filename)
|
||||
== PROJECT_ROOT_PATH / "telegram" / "ext" / "_conversationhandler.py"
|
||||
), "wrong stacklevel!"
|
||||
assert str(recwarn[0].message) == (
|
||||
"'callback' returned state 69 which is unknown to the ConversationHandler xyz."
|
||||
assert (
|
||||
str(recwarn[0].message)
|
||||
== "'callback' returned state 69 which is unknown to the ConversationHandler xyz."
|
||||
)
|
||||
|
||||
async def test_conversation_handler_per_chat(self, app, bot, user1, user2):
|
||||
|
|
|
@ -829,20 +829,22 @@ class TestFilters:
|
|||
)
|
||||
|
||||
def test_filters_file_extension_name(self):
|
||||
assert filters.Document.FileExtension("jpg").name == (
|
||||
"filters.Document.FileExtension('jpg')"
|
||||
assert (
|
||||
filters.Document.FileExtension("jpg").name == "filters.Document.FileExtension('jpg')"
|
||||
)
|
||||
assert filters.Document.FileExtension("JPG").name == (
|
||||
"filters.Document.FileExtension('jpg')"
|
||||
assert (
|
||||
filters.Document.FileExtension("JPG").name == "filters.Document.FileExtension('jpg')"
|
||||
)
|
||||
assert filters.Document.FileExtension("jpg", case_sensitive=True).name == (
|
||||
"filters.Document.FileExtension('jpg', case_sensitive=True)"
|
||||
assert (
|
||||
filters.Document.FileExtension("jpg", case_sensitive=True).name
|
||||
== "filters.Document.FileExtension('jpg', case_sensitive=True)"
|
||||
)
|
||||
assert filters.Document.FileExtension("JPG", case_sensitive=True).name == (
|
||||
"filters.Document.FileExtension('JPG', case_sensitive=True)"
|
||||
assert (
|
||||
filters.Document.FileExtension("JPG", case_sensitive=True).name
|
||||
== "filters.Document.FileExtension('JPG', case_sensitive=True)"
|
||||
)
|
||||
assert filters.Document.FileExtension(".jpg").name == (
|
||||
"filters.Document.FileExtension('.jpg')"
|
||||
assert (
|
||||
filters.Document.FileExtension(".jpg").name == "filters.Document.FileExtension('.jpg')"
|
||||
)
|
||||
assert filters.Document.FileExtension("").name == "filters.Document.FileExtension('')"
|
||||
assert filters.Document.FileExtension(None).name == "filters.Document.FileExtension(None)"
|
||||
|
@ -2015,8 +2017,7 @@ class TestFilters:
|
|||
|
||||
assert (
|
||||
str(filters.TEXT & (filters.FORWARDED | filters.Entity(MessageEntity.MENTION)))
|
||||
== "<filters.TEXT and <filters.FORWARDED or "
|
||||
"filters.Entity(mention)>>"
|
||||
== "<filters.TEXT and <filters.FORWARDED or filters.Entity(mention)>>"
|
||||
)
|
||||
|
||||
def test_xor_filters(self, update):
|
||||
|
@ -2056,8 +2057,7 @@ class TestFilters:
|
|||
|
||||
assert (
|
||||
str(filters.FORWARDED & (filters.TEXT ^ filters.User(123)))
|
||||
== "<filters.FORWARDED and <filters.TEXT xor "
|
||||
"filters.User(123)>>"
|
||||
== "<filters.FORWARDED and <filters.TEXT xor filters.User(123)>>"
|
||||
)
|
||||
|
||||
def test_xor_regex_filters(self, update):
|
||||
|
|
|
@ -136,8 +136,10 @@ BASE_GAME_SCORE = 60 # Base game score for game tests
|
|||
|
||||
xfail = pytest.mark.xfail(
|
||||
bool(GITHUB_ACTION), # This condition is only relevant for github actions game tests.
|
||||
reason="Can fail due to race conditions when multiple test suites "
|
||||
"with the same bot token are run at the same time",
|
||||
reason=(
|
||||
"Can fail due to race conditions when multiple test suites "
|
||||
"with the same bot token are run at the same time"
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
|
@ -684,8 +686,10 @@ class TestBotWithoutRequest:
|
|||
"title": "test_result",
|
||||
"id": "123",
|
||||
"type": "document",
|
||||
"document_url": "https://raw.githubusercontent.com/python-telegram-bot"
|
||||
"/logos/master/logo/png/ptb-logo_240.png",
|
||||
"document_url": (
|
||||
"https://raw.githubusercontent.com/python-telegram-bot"
|
||||
"/logos/master/logo/png/ptb-logo_240.png"
|
||||
),
|
||||
"mime_type": "image/png",
|
||||
"caption": "ptb_logo",
|
||||
"input_message_content": {"message_text": "imc"},
|
||||
|
@ -713,8 +717,10 @@ class TestBotWithoutRequest:
|
|||
InlineQueryResultArticle("12", "second", InputMessageContentDWPP("second")),
|
||||
InlineQueryResultDocument(
|
||||
id="123",
|
||||
document_url="https://raw.githubusercontent.com/python-telegram-bot/logos/master/"
|
||||
"logo/png/ptb-logo_240.png",
|
||||
document_url=(
|
||||
"https://raw.githubusercontent.com/python-telegram-bot/logos/master/"
|
||||
"logo/png/ptb-logo_240.png"
|
||||
),
|
||||
title="test_result",
|
||||
mime_type="image/png",
|
||||
caption="ptb_logo",
|
||||
|
@ -787,9 +793,11 @@ class TestBotWithoutRequest:
|
|||
"title": "test_result",
|
||||
"id": "123",
|
||||
"type": "document",
|
||||
"document_url": "https://raw.githubusercontent.com/"
|
||||
"document_url": (
|
||||
"https://raw.githubusercontent.com/"
|
||||
"python-telegram-bot/logos/master/logo/png/"
|
||||
"ptb-logo_240.png",
|
||||
"ptb-logo_240.png"
|
||||
),
|
||||
"mime_type": "image/png",
|
||||
"caption": "ptb_logo",
|
||||
"input_message_content": {"message_text": "imc"},
|
||||
|
@ -806,8 +814,10 @@ class TestBotWithoutRequest:
|
|||
InlineQueryResultArticle("12", "second", InputMessageContentDWPP("second")),
|
||||
InlineQueryResultDocument(
|
||||
id="123",
|
||||
document_url="https://raw.githubusercontent.com/python-telegram-bot/logos/master/"
|
||||
"logo/png/ptb-logo_240.png",
|
||||
document_url=(
|
||||
"https://raw.githubusercontent.com/python-telegram-bot/logos/master/"
|
||||
"logo/png/ptb-logo_240.png"
|
||||
),
|
||||
title="test_result",
|
||||
mime_type="image/png",
|
||||
caption="ptb_logo",
|
||||
|
@ -871,9 +881,11 @@ class TestBotWithoutRequest:
|
|||
"title": "test_result",
|
||||
"id": "123",
|
||||
"type": "document",
|
||||
"document_url": "https://raw.githubusercontent.com/"
|
||||
"document_url": (
|
||||
"https://raw.githubusercontent.com/"
|
||||
"python-telegram-bot/logos/master/logo/png/"
|
||||
"ptb-logo_240.png",
|
||||
"ptb-logo_240.png"
|
||||
),
|
||||
"mime_type": "image/png",
|
||||
"caption": "ptb_logo",
|
||||
"parse_mode": "Markdown",
|
||||
|
@ -895,8 +907,10 @@ class TestBotWithoutRequest:
|
|||
InlineQueryResultArticle("12", "second", InputMessageContentDWPP("second")),
|
||||
InlineQueryResultDocument(
|
||||
id="123",
|
||||
document_url="https://raw.githubusercontent.com/python-telegram-bot/logos/master/"
|
||||
"logo/png/ptb-logo_240.png",
|
||||
document_url=(
|
||||
"https://raw.githubusercontent.com/python-telegram-bot/logos/master/"
|
||||
"logo/png/ptb-logo_240.png"
|
||||
),
|
||||
title="test_result",
|
||||
mime_type="image/png",
|
||||
caption="ptb_logo",
|
||||
|
@ -1398,9 +1412,11 @@ class TestBotWithoutRequest:
|
|||
data.get("caption") == caption,
|
||||
data["parse_mode"] == ParseMode.HTML,
|
||||
data["reply_to_message_id"] == media_message.message_id,
|
||||
(
|
||||
data["reply_markup"] == keyboard.to_json()
|
||||
if json_keyboard
|
||||
else keyboard.to_dict(),
|
||||
else keyboard.to_dict()
|
||||
),
|
||||
data["disable_notification"] is True,
|
||||
data["caption_entities"]
|
||||
== [MessageEntity(MessageEntity.BOLD, 0, 4).to_dict()],
|
||||
|
@ -2244,7 +2260,7 @@ class TestBotWithRequest:
|
|||
await bot.send_chat_action(chat_id, "unknown action")
|
||||
|
||||
async def test_answer_inline_query_current_offset_error(self, bot, inline_results):
|
||||
with pytest.raises(ValueError, match=("`current_offset` and `next_offset`")):
|
||||
with pytest.raises(ValueError, match="`current_offset` and `next_offset`"):
|
||||
await bot.answer_inline_query(
|
||||
1234, results=inline_results, next_offset=42, current_offset=51
|
||||
)
|
||||
|
@ -2513,8 +2529,9 @@ class TestBotWithRequest:
|
|||
message = await bot.send_game(chat_id, game_short_name, protect_content=True)
|
||||
|
||||
assert message.game
|
||||
assert message.game.description == (
|
||||
"A no-op test game, for python-telegram-bot bot framework testing."
|
||||
assert (
|
||||
message.game.description
|
||||
== "A no-op test game, for python-telegram-bot bot framework testing."
|
||||
)
|
||||
assert message.game.animation.file_id
|
||||
# We added some test bots later and for some reason the file size is not the same for them
|
||||
|
|
Loading…
Reference in a new issue