Added code samples for AI-Agents

This commit is contained in:
2025-12-17 20:22:46 +03:00
parent d66aed35d6
commit 0885618b25
29 changed files with 2007 additions and 0 deletions

View File

@@ -0,0 +1,89 @@
"""Тесты для генератора расписаний."""
import pytest
from unittest.mock import AsyncMock
from agents.gigachat_client import GigaChatClient
from agents.schedule_generator import ScheduleGenerator
from models.gigachat_types import GigaChatMessage, GigaChatResponse, GigaChatUsage, GigaChatChoice
from services.token_manager import TokenManager
@pytest.fixture
def mock_gigachat():
"""Фикстура для мокового GigaChat клиента."""
client = AsyncMock(spec=GigaChatClient)
return client
@pytest.fixture
def schedule_generator(mock_gigachat):
"""Фикстура для ScheduleGenerator."""
return ScheduleGenerator(gigachat=mock_gigachat)
@pytest.mark.asyncio
async def test_generate_schedule(schedule_generator, mock_gigachat):
"""Тест генерации расписания."""
mock_response_json = """
{
"title": "Расписание на 2025-12-16",
"tasks": [
{
"title": "Утренняя зарядка",
"description": "Сделай зарядку",
"duration_minutes": 15,
"category": "утренняя_рутина"
},
{
"title": "Завтрак",
"description": "Позавтракай",
"duration_minutes": 20,
"category": "утренняя_рутина"
}
]
}
"""
mock_gigachat.chat.return_value = mock_response_json
schedule = await schedule_generator.generate(
child_age=7,
preferences=["рисование", "прогулка"],
date="2025-12-16",
)
assert schedule.title == "Расписание на 2025-12-16"
assert len(schedule.tasks) == 2
assert schedule.tasks[0].title == "Утренняя зарядка"
assert schedule.tasks[0].duration_minutes == 15
@pytest.mark.asyncio
async def test_generate_schedule_with_markdown(schedule_generator, mock_gigachat):
"""Тест генерации с markdown в ответе."""
mock_response_json = """
```json
{
"title": "Тестовое расписание",
"tasks": [
{
"title": "Тест",
"duration_minutes": 10,
"category": "обучение"
}
]
}
```
"""
mock_gigachat.chat.return_value = mock_response_json
schedule = await schedule_generator.generate(
child_age=5,
preferences=[],
date="2025-12-17",
)
assert schedule.title == "Тестовое расписание"
assert len(schedule.tasks) == 1