Files
NaliiaBot/tests/conftest.py
2026-02-24 23:13:09 -05:00

69 lines
1.6 KiB
Python

import pytest
from unittest.mock import Mock
from src.naliiabot.bot.agent.agent import Agent, AgentConfig
from src.naliiabot.bot.factories.llm_factory import LLMFactory
from httpx import ASGITransport, AsyncClient
from naliiabotapi.main import app
@pytest.fixture(scope="function")
async def async_client():
"""Fixture para un cliente HTTP asíncrono."""
async with AsyncClient(
transport=ASGITransport(app=app),
base_url="http://localhost:8010") as client:
yield client
@pytest.fixture
def mock_tool():
"""Mock de herramienta."""
tool = Mock()
tool.name = "calculator"
tool.invoke = Mock(return_value="42")
return tool
@pytest.fixture
def mock_model():
"""Mock de modelo LLM con interfaz completa."""
model = Mock()
model.bind_tools = Mock(return_value=model)
return model
@pytest.fixture
def default_config():
"""Configuración de test predecible."""
return AgentConfig(
system_prompt="Test prompt",
max_iterations=5,
timeout_seconds=10.0
)
@pytest.fixture
def agent(mock_model, default_config):
"""Agente básico sin herramientas."""
return Agent(model=mock_model, config=default_config)
@pytest.fixture
def agent_with_tool(mock_model, default_config, mock_tool):
"""Agente con una herramienta mock."""
return Agent(
model=mock_model,
config=default_config,
tools=[mock_tool]
)
@pytest.fixture
def anthropic_model():
llmFactory = LLMFactory("anthropic")
anthropic_model = llmFactory.get_model()
return anthropic_model