File size: 7,219 Bytes
225a75e |
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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
#!/usr/bin/env python3
"""
Integration test for all GAIA Agent tools
Tests Wikipedia, Web Search, Calculator, and File Processor tools
"""
import os
import sys
import time
import tempfile
from pathlib import Path
# Add src to path for imports
sys.path.insert(0, str(Path(__file__).parent))
from tools.wikipedia_tool import WikipediaTool
from tools.web_search_tool import WebSearchTool
from tools.calculator import CalculatorTool
from tools.file_processor import FileProcessorTool
def test_all_tools():
"""Comprehensive test of all GAIA agent tools"""
print("๐งช GAIA Agent Tools Integration Test")
print("=" * 50)
results = []
start_time = time.time()
# Test 1: Wikipedia Tool
print("\n๐ Testing Wikipedia Tool...")
wikipedia_tool = WikipediaTool()
test_cases = [
"Albert Einstein",
{"query": "Machine Learning", "action": "summary"}
]
for i, test_case in enumerate(test_cases, 1):
result = wikipedia_tool.execute(test_case)
success = result.success and result.result.get('found', False)
results.append(('Wikipedia', f'Test {i}', success, result.execution_time))
status = "โ
PASS" if success else "โ FAIL"
print(f" Test {i}: {status} ({result.execution_time:.2f}s)")
# Test 2: Web Search Tool
print("\n๐ Testing Web Search Tool...")
web_search_tool = WebSearchTool()
test_cases = [
"Python programming",
{"query": "https://www.python.org", "action": "extract"}
]
for i, test_case in enumerate(test_cases, 1):
result = web_search_tool.execute(test_case)
success = result.success and result.result.get('found', False)
results.append(('Web Search', f'Test {i}', success, result.execution_time))
status = "โ
PASS" if success else "โ FAIL"
print(f" Test {i}: {status} ({result.execution_time:.2f}s)")
# Test 3: Calculator Tool
print("\n๐งฎ Testing Calculator Tool...")
calculator_tool = CalculatorTool()
test_cases = [
"2 + 3 * 4",
{"operation": "statistics", "data": [1, 2, 3, 4, 5]},
{"operation": "convert", "value": 100, "from_unit": "cm", "to_unit": "m"}
]
for i, test_case in enumerate(test_cases, 1):
result = calculator_tool.execute(test_case)
success = result.success and result.result.get('success', False)
results.append(('Calculator', f'Test {i}', success, result.execution_time))
status = "โ
PASS" if success else "โ FAIL"
print(f" Test {i}: {status} ({result.execution_time:.3f}s)")
# Test 4: File Processor Tool
print("\n๐ Testing File Processor Tool...")
file_processor_tool = FileProcessorTool()
# Create test files
with tempfile.TemporaryDirectory() as temp_dir:
# Create CSV test file
csv_path = os.path.join(temp_dir, "test.csv")
with open(csv_path, 'w') as f:
f.write("name,value\nTest,42\nData,100")
# Create Python test file
py_path = os.path.join(temp_dir, "test.py")
with open(py_path, 'w') as f:
f.write("def test_function():\n return 'Hello, World!'")
test_files = [csv_path, py_path]
for i, file_path in enumerate(test_files, 1):
result = file_processor_tool.execute(file_path)
success = result.success and result.result.get('success', False)
results.append(('File Processor', f'Test {i}', success, result.execution_time))
status = "โ
PASS" if success else "โ FAIL"
file_type = os.path.splitext(file_path)[1]
print(f" Test {i} ({file_type}): {status} ({result.execution_time:.3f}s)")
# Summary
total_time = time.time() - start_time
passed_tests = sum(1 for _, _, success, _ in results if success)
total_tests = len(results)
print("\n" + "=" * 50)
print("๐ INTEGRATION TEST RESULTS")
print("=" * 50)
# Results by tool
tools = {}
for tool, test, success, exec_time in results:
if tool not in tools:
tools[tool] = {'passed': 0, 'total': 0, 'time': 0}
tools[tool]['total'] += 1
tools[tool]['time'] += exec_time
if success:
tools[tool]['passed'] += 1
for tool, stats in tools.items():
pass_rate = (stats['passed'] / stats['total']) * 100
avg_time = stats['time'] / stats['total']
status = "โ
" if pass_rate == 100 else "โ ๏ธ" if pass_rate >= 80 else "โ"
print(f"{status} {tool:15}: {stats['passed']}/{stats['total']} ({pass_rate:5.1f}%) - Avg: {avg_time:.3f}s")
# Overall results
overall_pass_rate = (passed_tests / total_tests) * 100
print(f"\n๐ฏ OVERALL: {passed_tests}/{total_tests} tests passed ({overall_pass_rate:.1f}%)")
print(f"โฑ๏ธ TOTAL TIME: {total_time:.2f} seconds")
# Success criteria
if overall_pass_rate >= 90:
print("๐ EXCELLENT! All tools working correctly - Ready for agent integration!")
return True
elif overall_pass_rate >= 80:
print("โ
GOOD! Most tools working - Minor issues to address")
return True
else:
print("โ ๏ธ NEEDS WORK! Significant issues found - Check individual tool failures")
return False
def test_tool_coordination():
"""Test how tools can work together in a coordinated workflow"""
print("\n๐ค Testing Tool Coordination...")
print("-" * 30)
# Scenario: Research Python programming, then calculate some metrics
try:
# Step 1: Get information about Python
wiki_tool = WikipediaTool()
wiki_result = wiki_tool.execute("Python (programming language)")
if wiki_result.success:
print("โ
Step 1: Wikipedia lookup successful")
# Step 2: Get additional web information
web_tool = WebSearchTool()
web_result = web_tool.execute("Python programming language features")
if web_result.success:
print("โ
Step 2: Web search successful")
# Step 3: Calculate some metrics
calc_tool = CalculatorTool()
search_count = len(web_result.result.get('results', []))
calc_result = calc_tool.execute(f"sqrt({search_count}) * 10")
if calc_result.success:
print("โ
Step 3: Calculation successful")
print(f" Coordinated result: Found {search_count} web results, computed metric: {calc_result.result['calculation']['result']}")
return True
except Exception as e:
print(f"โ Coordination test failed: {e}")
return False
if __name__ == "__main__":
success = test_all_tools()
coordination_success = test_tool_coordination()
if success and coordination_success:
print("\n๐ ALL TESTS PASSED! Tools are ready for agent integration!")
sys.exit(0)
else:
print("\nโ ๏ธ Some tests failed. Check output above.")
sys.exit(1) |