File size: 1,827 Bytes
891fe52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Tests for ToolAdapter."""

import pytest
from unittest.mock import AsyncMock

from polyhedra.agent.tool_adapter import ToolAdapter


class TestToolAdapter:
    """Test suite for ToolAdapter."""
    
    def test_initialization(self):
        """Test adapter initialization."""
        tools = {''tool1'': AsyncMock(), ''tool2'': AsyncMock()}
        adapter = ToolAdapter(tools)
        assert adapter.tools == tools
    
    def test_get_tool_exists(self):
        """Test getting existing tool."""
        tool = AsyncMock()
        adapter = ToolAdapter({''test_tool'': tool})
        result = adapter.get_tool(''test_tool'')
        assert result is tool
    
    def test_get_tool_not_found(self):
        """Test getting non-existent tool raises KeyError."""
        adapter = ToolAdapter({})
        with pytest.raises(KeyError, match="not found"):
            adapter.get_tool(''nonexistent'')
    
    def test_list_tools(self):
        """Test listing all tools."""
        tools = {''tool1'': AsyncMock(), ''tool2'': AsyncMock(), ''tool3'': AsyncMock()}
        adapter = ToolAdapter(tools)
        tool_list = adapter.list_tools()
        assert set(tool_list) == {''tool1'', ''tool2'', ''tool3''}
    
    def test_has_tool_exists(self):
        """Test has_tool returns True for existing tool."""
        adapter = ToolAdapter({''test_tool'': AsyncMock()})
        assert adapter.has_tool(''test_tool'') is True
    
    def test_has_tool_not_exists(self):
        """Test has_tool returns False for non-existent tool."""
        adapter = ToolAdapter({''test_tool'': AsyncMock()})
        assert adapter.has_tool(''other_tool'') is False
    
    def test_list_tools_empty(self):
        """Test listing tools when none exist."""
        adapter = ToolAdapter({})
        assert adapter.list_tools() == []