refactor: enforce BasedPyright strict type checking (#5158)
This commit is contained in:
1 parent
e703481755
commit
757ad9c764
166 files changed
+4728
-2621
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import asyncio
|
||||
from datetime import timedelta
|
||||
from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import AsyncMock
|
||||
@@ -1911,6 +1912,36 @@ async def test_on_message_location_with_text() -> None:
|
||||
# Tests for retry amplification fix (issue #3050)
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_call_with_retry_accepts_timedelta_retry_after(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
from telegram.error import RetryAfter
|
||||
|
||||
channel = TelegramChannel(
|
||||
TelegramConfig(enabled=True, token="123:abc", allow_from=["*"]),
|
||||
MessageBus(),
|
||||
)
|
||||
attempts = 0
|
||||
|
||||
async def retry_once() -> str:
|
||||
nonlocal attempts
|
||||
attempts += 1
|
||||
if attempts == 1:
|
||||
raise RetryAfter(timedelta(seconds=1.5))
|
||||
return "ok"
|
||||
|
||||
sleep = AsyncMock()
|
||||
monkeypatch.setenv("PTB_TIMEDELTA", "1")
|
||||
monkeypatch.setattr(
|
||||
"nanobot.channels.telegram.runtime.asyncio.sleep",
|
||||
sleep,
|
||||
)
|
||||
|
||||
assert await channel._call_with_retry(retry_once) == "ok"
|
||||
sleep.assert_awaited_once_with(1.5)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_send_text_does_not_fallback_on_network_timeout() -> None:
|
||||
"""TimedOut should propagate immediately, NOT trigger plain-text fallback.
|
||||
@@ -2318,7 +2349,7 @@ async def test_callback_query_ignores_unauthorized_user_before_side_effects() ->
|
||||
data="Yes",
|
||||
answer=AsyncMock(),
|
||||
message=SimpleNamespace(
|
||||
chat_id=123,
|
||||
chat=SimpleNamespace(id=123),
|
||||
edit_reply_markup=AsyncMock(),
|
||||
),
|
||||
)
|
||||
@@ -2332,3 +2363,35 @@ async def test_callback_query_ignores_unauthorized_user_before_side_effects() ->
|
||||
query.answer.assert_not_awaited()
|
||||
query.message.edit_reply_markup.assert_not_awaited()
|
||||
channel._handle_message.assert_not_awaited()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_callback_query_handles_inaccessible_message() -> None:
|
||||
from telegram import Chat, InaccessibleMessage
|
||||
|
||||
channel = TelegramChannel(
|
||||
TelegramConfig(enabled=True, token="123:abc", allow_from=["*"], inline_keyboards=True),
|
||||
MessageBus(),
|
||||
)
|
||||
channel._handle_message = AsyncMock()
|
||||
channel._start_typing = lambda _chat_id: None
|
||||
|
||||
query = SimpleNamespace(
|
||||
id="cb_inaccessible",
|
||||
data="Yes",
|
||||
answer=AsyncMock(),
|
||||
message=InaccessibleMessage(
|
||||
chat=Chat(id=123, type="private"),
|
||||
message_id=456,
|
||||
),
|
||||
)
|
||||
update = SimpleNamespace(
|
||||
callback_query=query,
|
||||
effective_user=SimpleNamespace(id=12345, username="alice", first_name="Alice"),
|
||||
)
|
||||
|
||||
await channel._on_callback_query(update, None)
|
||||
|
||||
query.answer.assert_awaited_once()
|
||||
channel._handle_message.assert_awaited_once()
|
||||
assert channel._handle_message.await_args.kwargs["chat_id"] == "123"
|
||||
Reference in new issue
Block a user