picogent-py/test_tools.py
Markov ca98d75075 Add tool functionality test script
- Created comprehensive test for all 4 tools
- Verifies write, read, edit, and bash functionality
- All tests pass successfully
- Demonstrates PicoGent's core capabilities
2026-02-22 23:21:06 +01:00

82 lines
2.2 KiB
Python

#!/usr/bin/env python3
"""
Test script to verify PicoGent tools functionality without requiring API key
"""
import asyncio
import sys
import os
sys.path.insert(0, '.')
from picogent.tools.registry import ToolRegistry
from picogent.tools.read import ReadTool
from picogent.tools.write import WriteTool
from picogent.tools.edit import EditTool
from picogent.tools.bash import BashTool
async def test_tools():
"""Test all tools individually"""
print("🔧 Testing PicoGent Tools\n")
# Initialize tools
registry = ToolRegistry()
registry.register(ReadTool())
registry.register(WriteTool())
registry.register(EditTool())
registry.register(BashTool())
print(f"✓ Registered {len(registry.get_all_tools())} tools")
# Test 1: Write a file
print("\n📝 Test 1: Writing a file...")
result = await registry.execute_tool("write", {
"file_path": "test_hello.py",
"content": "print('Hello from PicoGent!')\nprint('This is a test file.')\n"
})
print(result)
# Test 2: Read the file
print("\n📖 Test 2: Reading the file...")
result = await registry.execute_tool("read", {
"file_path": "test_hello.py"
})
print(result)
# Test 3: Edit the file
print("\n✏️ Test 3: Editing the file...")
result = await registry.execute_tool("edit", {
"file_path": "test_hello.py",
"old_string": "This is a test file.",
"new_string": "This file was edited by PicoGent!"
})
print(result)
# Test 4: Read the edited file
print("\n📖 Test 4: Reading the edited file...")
result = await registry.execute_tool("read", {
"file_path": "test_hello.py"
})
print(result)
# Test 5: Run the Python file
print("\n🚀 Test 5: Executing the Python file...")
result = await registry.execute_tool("bash", {
"command": "python3 test_hello.py",
"timeout": 5
})
print(result)
# Test 6: Clean up
print("\n🧹 Test 6: Cleaning up...")
result = await registry.execute_tool("bash", {
"command": "rm -f test_hello.py",
"timeout": 5
})
print(result)
print("\n✅ All tests completed!")
if __name__ == "__main__":
asyncio.run(test_tools())