mirror of
https://github.com/tiennm99/serena.git
synced 2026-10-13 00:15:05 +00:00
Fixed appending of "." to docstring and mock in test...
We should get rid of mocks eventually
This commit is contained in:
1 parent
46967fa3cb
commit
eb0f44cb79
2 files changed
+17
-11
No files matched your search
+3
-2
@@ -68,8 +68,7 @@ class SerenaMCPFactory:
|
||||
|
||||
# Mount the tool description as a combination of the docstring description and
|
||||
# the return value description, if it exists.
|
||||
agent = cast(SerenaAgent, tool.agent)
|
||||
overridden_description = agent.get_context().tool_description_overrides.get(func_name, None)
|
||||
overridden_description = tool.agent.get_context().tool_description_overrides.get(func_name, None)
|
||||
|
||||
if overridden_description is not None:
|
||||
func_doc = overridden_description
|
||||
@@ -78,6 +77,8 @@ class SerenaMCPFactory:
|
||||
else:
|
||||
func_doc = ""
|
||||
func_doc = func_doc.strip().strip(".")
|
||||
if func_doc:
|
||||
func_doc += "."
|
||||
if docstring.returns and (docstring_returns_descr := docstring.returns.description):
|
||||
# Only add a space before "Returns" if func_doc is not empty
|
||||
prefix = " " if func_doc else ""
|
||||
|
||||
+14
-9
@@ -4,16 +4,28 @@ import pytest
|
||||
from mcp.server.fastmcp.tools.base import Tool as MCPTool
|
||||
|
||||
from serena.agent import Tool, ToolRegistry
|
||||
from serena.config.context_mode import SerenaAgentContext
|
||||
from serena.mcp import SerenaMCPFactory
|
||||
|
||||
make_tool = SerenaMCPFactory.make_mcp_tool
|
||||
|
||||
|
||||
# Create a mock agent for tool initialization
|
||||
class MockAgent:
|
||||
def __init__(self):
|
||||
self.project_config = None
|
||||
self.serena_config = None
|
||||
|
||||
@staticmethod
|
||||
def get_context() -> SerenaAgentContext:
|
||||
return SerenaAgentContext.load_default()
|
||||
|
||||
|
||||
class BaseMockTool(Tool):
|
||||
"""A mock Tool class for testing."""
|
||||
|
||||
def __init__(self) -> None:
|
||||
pass
|
||||
def __init__(self):
|
||||
super().__init__(MockAgent())
|
||||
|
||||
|
||||
class BasicTool(BaseMockTool):
|
||||
@@ -274,13 +286,6 @@ def is_test_mock_class(tool_class: type) -> bool:
|
||||
@pytest.mark.parametrize("tool_class", ToolRegistry().get_all_tool_classes())
|
||||
def test_make_tool_all_tools(tool_class) -> None:
|
||||
"""Test that make_tool works for all tools in the codebase."""
|
||||
|
||||
# Create a mock agent for tool initialization
|
||||
class MockAgent:
|
||||
def __init__(self):
|
||||
self.project_config = None
|
||||
self.serena_config = None
|
||||
|
||||
# Create an instance of the tool
|
||||
tool_instance = tool_class(MockAgent())
|
||||
|
||||
|
||||
Reference in new issue
Block a user