Skip to content

Commit 02e1e30

Browse files
committed
updated version and tests
1 parent ac0c0b0 commit 02e1e30

File tree

5 files changed

+33
-26
lines changed

5 files changed

+33
-26
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "chuk-tool-processor"
7-
version = "0.6.13"
7+
version = "0.6.14"
88
description = "Async-native framework for registering, discovering, and executing tools referenced in LLM responses"
99
readme = "README.md"
1010
requires-python = ">=3.11"

tests/registry/test_decorators.py

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ class TestEnsureRegistrations:
504504
@pytest.mark.asyncio
505505
async def test_ensure_registrations_empty(self):
506506
"""Test ensure_registrations with no pending tools."""
507-
with patch("chuk_tool_processor.registry.decorators._pending_registrations", []):
507+
with patch("chuk_tool_processor.registry.decorators._PENDING_REGISTRATIONS", []):
508508
await ensure_registrations()
509509
# Should complete without error
510510

@@ -514,14 +514,17 @@ async def test_ensure_registrations_with_pending(self):
514514
mock_registry = AsyncMock()
515515
mock_registry.register_tool = AsyncMock()
516516

517-
# Create pending registrations
518-
pending = [
519-
("tool1", ValidatedTool, {"namespace": "default"}),
520-
("tool2", ValidatedTool, {"namespace": "custom"}),
521-
]
517+
# Create async registration functions
518+
async def reg1():
519+
await mock_registry.register_tool(ValidatedTool, name="tool1", namespace="default", metadata={})
520+
521+
async def reg2():
522+
await mock_registry.register_tool(ValidatedTool, name="tool2", namespace="custom", metadata={})
523+
524+
pending = [reg1, reg2]
522525

523526
with (
524-
patch("chuk_tool_processor.registry.decorators._pending_registrations", pending),
527+
patch("chuk_tool_processor.registry.decorators._PENDING_REGISTRATIONS", pending),
525528
patch(
526529
"chuk_tool_processor.registry.provider.ToolRegistryProvider.get_registry", return_value=mock_registry
527530
),
@@ -537,10 +540,14 @@ async def test_ensure_registrations_clears_pending(self):
537540
mock_registry = AsyncMock()
538541
mock_registry.register_tool = AsyncMock()
539542

540-
pending = [("tool1", ValidatedTool, {})]
543+
# Create async registration function
544+
async def reg1():
545+
await mock_registry.register_tool(ValidatedTool, name="tool1", namespace="default", metadata={})
546+
547+
pending = [reg1]
541548

542549
with (
543-
patch("chuk_tool_processor.registry.decorators._pending_registrations", pending) as pending_list,
550+
patch("chuk_tool_processor.registry.decorators._PENDING_REGISTRATIONS", pending) as pending_list,
544551
patch(
545552
"chuk_tool_processor.registry.provider.ToolRegistryProvider.get_registry", return_value=mock_registry
546553
),
@@ -692,21 +699,17 @@ class Arguments(BaseModel):
692699
async def _execute(self, value: str, count: int):
693700
return {"result": value * count}
694701

702+
# Process pending registrations
703+
await ensure_registrations()
704+
695705
# Tool should be registered
696706
mock_registry.register_tool.assert_called()
697707

698-
# Should be in decorated tools
699-
with patch("chuk_tool_processor.registry.decorators._decorated_tools", []) as decorated:
700-
701-
@register_tool(name="another")
702-
class AnotherTool(ValidatedTool):
703-
class Arguments(BaseModel):
704-
x: int
705-
706-
async def _execute(self, x: int):
707-
return {"result": x}
708-
709-
assert len(decorated) == 1
708+
# Verify the tool was registered with correct parameters
709+
call_args = mock_registry.register_tool.call_args
710+
assert call_args is not None
711+
assert call_args.kwargs["name"] == "integration_tool"
712+
assert call_args.kwargs["namespace"] == "test"
710713

711714
def test_function_to_tool_conversion(self):
712715
"""Test converting function to tool via decorator."""

tests/registry/test_registry_init.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,6 @@ async def execute(self, x: int) -> int:
6565
# Check if the tool was registered
6666
tool = await registry.get_tool("test_init_tool_unique", namespace="test_init_ns")
6767
assert tool is not None
68+
# Check if the tool is a class or has __name__ attribute
69+
assert hasattr(tool, "__name__"), f"Tool should have __name__, got {type(tool)}: {tool}"
6870
assert tool.__name__ == "TestInitTool"

tests/registry/test_tool_export_simple.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,11 @@ async def test_tool_by_openai_name(self):
9292
tool = await tool_by_openai_name("MockTool")
9393
assert tool == MockTool
9494

95-
# Unknown tool returns None
96-
tool = await tool_by_openai_name("UnknownTool")
97-
assert tool is None
95+
# Unknown tool raises KeyError
96+
import pytest
97+
98+
with pytest.raises(KeyError, match="No tool registered for OpenAI name 'UnknownTool'"):
99+
await tool_by_openai_name("UnknownTool")
98100

99101
@pytest.mark.asyncio
100102
async def test_openai_functions(self):

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)