fix syntax

This commit is contained in:
kandrusyak
2026-07-25 15:47:36 +03:00
parent 3f63d0305c
commit c04fb9480b
8 changed files with 56 additions and 32 deletions

View File

@@ -13,7 +13,10 @@ from assistant_bot.storage import AssistantStorage
class ReminderParserTests(unittest.TestCase):
def test_supported_relative_unit(self) -> None:
self.assertEqual(unit_to_timedelta(2, "часа").total_seconds(), 7200)
delta = unit_to_timedelta(2, "часа")
self.assertIsNotNone(delta)
assert delta is not None
self.assertEqual(delta.total_seconds(), 7200)
def test_absolute_datetime(self) -> None:
result = parse_reminder(

View File

@@ -1,6 +1,7 @@
import asyncio
import unittest
from types import SimpleNamespace
from typing import Any
from unittest.mock import patch
from assistant_bot.jobs import post_init, post_shutdown
@@ -10,11 +11,11 @@ class ReminderJobLifecycleTests(unittest.IsolatedAsyncioTestCase):
async def test_reminder_task_is_cancelled_on_shutdown(self) -> None:
started = asyncio.Event()
async def fake_reminder_loop(application) -> None:
async def fake_reminder_loop(_application) -> None:
started.set()
await asyncio.Event().wait()
application = SimpleNamespace(bot_data={})
application: Any = SimpleNamespace(bot_data={})
with patch("assistant_bot.jobs.reminder_loop", fake_reminder_loop):
await post_init(application)
await started.wait()

View File

@@ -1,6 +1,7 @@
import unittest
from pathlib import Path
from types import SimpleNamespace
from typing import Any
from unittest.mock import AsyncMock, MagicMock, patch
from assistant_bot.handlers import private_voice
@@ -15,7 +16,7 @@ class VoiceHandlerTests(unittest.IsolatedAsyncioTestCase):
voice=SimpleNamespace(duration=duration, file_id="voice-file-id"),
reply_text=AsyncMock(return_value=status_message),
)
update = SimpleNamespace(message=message)
update: Any = SimpleNamespace(message=message)
telegram_file = SimpleNamespace(download_to_drive=AsyncMock())
bot = SimpleNamespace(
get_file=AsyncMock(return_value=telegram_file),
@@ -23,7 +24,7 @@ class VoiceHandlerTests(unittest.IsolatedAsyncioTestCase):
)
recognizer = MagicMock()
recognizer.transcribe.return_value = transcript
context = SimpleNamespace(
context: Any = SimpleNamespace(
bot=bot,
application=SimpleNamespace(
bot_data={

View File

@@ -38,6 +38,15 @@ class FakeChatCompletions:
return self.completion
class FakeHTTPError(RuntimeError):
def __init__(self) -> None:
super().__init__("forbidden")
self.response = SimpleNamespace(
status_code=403,
text='{"error":{"message":"folder mismatch"}}',
)
class YandexAIClientTests(unittest.IsolatedAsyncioTestCase):
def test_multiple_system_messages_are_merged_at_the_beginning(self) -> None:
self.assertEqual(
@@ -62,11 +71,7 @@ class YandexAIClientTests(unittest.IsolatedAsyncioTestCase):
)
def test_http_error_includes_safe_response_body(self) -> None:
error = RuntimeError("forbidden")
error.response = SimpleNamespace(
status_code=403,
text='{"error":{"message":"folder mismatch"}}',
)
error = FakeHTTPError()
self.assertEqual(
describe_yandex_error(error),