Spaces:
Running
Running
File size: 2,004 Bytes
de37bdf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
import os
import pytest
from unittest.mock import patch
from surf_spot_finder.agents.smolagents import run_smolagent
# TODO I'd rather not use openai
INTEGRATION_MODEL = "openai/gpt-3.5-turbo"
API_KEY_VAR = "OPENAI_API_KEY"
@pytest.mark.skipif(
"INTEGRATION_TESTS" not in os.environ,
reason="Integration tests require INTEGRATION_TESTS env var",
)
def test_smolagent_integration():
"""
Full integration test of the smolagent functionality.
Requires:
- Docker to be running
- OPENAI_API_KEY in environment variables
- INTEGRATION_TESTS env var to be set
"""
with patch("smolagents.CodeAgent") as MockCodeAgent:
# Create a mock agent that returns itself from run()
mock_agent = MockCodeAgent.return_value
mock_agent.run.return_value = mock_agent
# Run the agent
result = run_smolagent(
INTEGRATION_MODEL,
"Find popular surf spots in California",
api_key_var=API_KEY_VAR,
)
# Verify the agent was created and run
MockCodeAgent.assert_called_once()
mock_agent.run.assert_called_once_with("Find popular surf spots in California")
assert result is mock_agent
@pytest.mark.skipif(
"INTEGRATION_TESTS" not in os.environ,
reason="Full integration tests require INTEGRATION_TESTS env var",
)
def test_smolagent_real_execution():
"""
Tests the actual execution of the agent against real APIs.
WARNING: This will make actual API calls and incur costs.
Only run when explicitly needed for full system testing.
Requires:
- Docker to be running
- OPENAI_API_KEY in environment variables
- INTEGRATION_TESTS env var to be set
"""
# Run with a simple, inexpensive request
agent = run_smolagent(
INTEGRATION_MODEL,
"What are three popular surf spots in California?",
api_key_var=API_KEY_VAR,
)
# Basic verification that we got an agent back
assert agent is not None
|