87 lines
2.5 KiB
Python
87 lines
2.5 KiB
Python
"""Tests for DocAgent."""
|
|
|
|
import pytest
|
|
from pathlib import Path
|
|
|
|
from app.agents.doc_agent import DocAgent
|
|
|
|
|
|
@pytest.fixture
|
|
def doc_agent():
|
|
return DocAgent()
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_doc_agent_initialization(doc_agent):
|
|
"""Test DocAgent initializes correctly."""
|
|
assert doc_agent.name == "doc_agent"
|
|
assert doc_agent.version == "1.0.0"
|
|
assert doc_agent.description
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_doc_agent_health_check(doc_agent):
|
|
"""Test DocAgent health check."""
|
|
result = await doc_agent.health_check()
|
|
assert isinstance(result, bool)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_doc_agent_run_without_context(doc_agent):
|
|
"""Test DocAgent run without context."""
|
|
result = await doc_agent.run()
|
|
assert hasattr(result, "success")
|
|
assert hasattr(result, "message")
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_doc_agent_run_with_context(doc_agent):
|
|
"""Test DocAgent run with context."""
|
|
context = {"action": "update_all"}
|
|
result = await doc_agent.run(context)
|
|
assert hasattr(result, "success")
|
|
assert hasattr(result, "message")
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_doc_agent_status_transitions(doc_agent):
|
|
"""Test DocAgent status transitions."""
|
|
assert doc_agent.status.value == "idle"
|
|
|
|
await doc_agent.set_running("test_task")
|
|
assert doc_agent.status.value == "running"
|
|
|
|
await doc_agent.set_idle()
|
|
assert doc_agent.status.value == "idle"
|
|
|
|
await doc_agent.set_error("test error")
|
|
assert doc_agent.status.value == "error"
|
|
|
|
await doc_agent.set_idle()
|
|
assert doc_agent.status.value == "idle"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_doc_agent_metrics(doc_agent):
|
|
"""Test DocAgent metrics retrieval."""
|
|
metrics = await doc_agent.get_metrics()
|
|
assert "agent_id" in metrics
|
|
assert "status" in metrics
|
|
assert metrics["agent_id"] == "doc_agent"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_get_file_purpose(doc_agent):
|
|
"""Test file purpose detection."""
|
|
assert "entry point" in doc_agent._get_file_purpose("main.py").lower()
|
|
assert "configuration" in doc_agent._get_file_purpose("config.py").lower()
|
|
assert "data models" in doc_agent._get_file_purpose("models.py").lower()
|
|
assert "Module file" in doc_agent._get_file_purpose("unknown.py")
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_doc_agent_invalid_action(doc_agent):
|
|
"""Test DocAgent with invalid action."""
|
|
context = {"action": "invalid_action"}
|
|
result = await doc_agent.run(context)
|
|
assert hasattr(result, "success") |