Fix telegram_bot tests for Python 3.13 (#127293)

pull/127333/head
Marc Mueller 2024-10-02 14:15:01 +02:00 committed by GitHub
parent 2fdde24024
commit ea115e0481
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 16 additions and 17 deletions

View File

@ -6,7 +6,7 @@ from typing import Any
from unittest.mock import patch
import pytest
from telegram import Chat, Message, User
from telegram import Bot, Chat, Message, User
from telegram.constants import ChatType
from homeassistant.components.telegram_bot import (
@ -89,23 +89,22 @@ def mock_external_calls() -> Generator[None]:
date=datetime.now(),
chat=Chat(id=123456, type=ChatType.PRIVATE),
)
class BotMock(Bot):
"""Mock bot class."""
__slots__ = ()
def __init__(self, *args: Any, **kwargs: Any) -> None:
"""Initialize BotMock instance."""
super().__init__(*args, **kwargs)
self._bot_user = test_user
with (
patch(
"telegram.Bot.get_me",
return_value=test_user,
),
patch(
"telegram.Bot._bot_user",
test_user,
),
patch(
"telegram.Bot.bot",
test_user,
),
patch(
"telegram.Bot.send_message",
return_value=message,
),
patch("homeassistant.components.telegram_bot.Bot", BotMock),
patch.object(BotMock, "get_me", return_value=test_user),
patch.object(BotMock, "bot", test_user),
patch.object(BotMock, "send_message", return_value=message),
patch("telegram.ext.Updater._bootstrap"),
):
yield