mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-11 09:08:31 +00:00
refactor: renaming available_tools_classes by available_exports
This commit is contained in:
@@ -61,7 +61,7 @@ class TestPlusAPI(unittest.TestCase):
|
||||
"version": version,
|
||||
"file": encoded_file,
|
||||
"description": description,
|
||||
"available_tool_classes": None,
|
||||
"available_exports": None,
|
||||
}
|
||||
mock_make_request.assert_called_once_with(
|
||||
"POST", "/crewai_plus/api/v1/tools", json=params
|
||||
@@ -88,7 +88,7 @@ class TestPlusAPI(unittest.TestCase):
|
||||
"version": version,
|
||||
"file": encoded_file,
|
||||
"description": description,
|
||||
"available_tool_classes": None,
|
||||
"available_exports": None,
|
||||
}
|
||||
mock_make_request.assert_called_once_with(
|
||||
"POST", "/crewai_plus/api/v1/tools", json=params
|
||||
|
||||
@@ -2,6 +2,7 @@ import os
|
||||
import shutil
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from crewai.cli import utils
|
||||
@@ -113,45 +114,45 @@ def create_init_file(directory, content):
|
||||
return create_file(directory / "__init__.py", content)
|
||||
|
||||
|
||||
def test_extract_available_tools_empty_project(temp_project_dir, capsys):
|
||||
def test_extract_available_exports_empty_project(temp_project_dir, capsys):
|
||||
with pytest.raises(SystemExit):
|
||||
utils.extract_available_tools(dir_path=temp_project_dir)
|
||||
utils.extract_available_exports(dir_path=temp_project_dir)
|
||||
captured = capsys.readouterr()
|
||||
|
||||
assert "No valid tools were exposed in your __init__.py file" in captured.out
|
||||
|
||||
|
||||
def test_extract_available_tools_no_init_file(temp_project_dir, capsys):
|
||||
def test_extract_available_exports_no_init_file(temp_project_dir, capsys):
|
||||
(temp_project_dir / "some_file.py").write_text("print('hello')")
|
||||
with pytest.raises(SystemExit):
|
||||
utils.extract_available_tools(dir_path=temp_project_dir)
|
||||
utils.extract_available_exports(dir_path=temp_project_dir)
|
||||
captured = capsys.readouterr()
|
||||
|
||||
assert "No valid tools were exposed in your __init__.py file" in captured.out
|
||||
|
||||
|
||||
def test_extract_available_tools_empty_init_file(temp_project_dir, capsys):
|
||||
def test_extract_available_exports_empty_init_file(temp_project_dir, capsys):
|
||||
create_init_file(temp_project_dir, "")
|
||||
with pytest.raises(SystemExit):
|
||||
utils.extract_available_tools(dir_path=temp_project_dir)
|
||||
utils.extract_available_exports(dir_path=temp_project_dir)
|
||||
captured = capsys.readouterr()
|
||||
|
||||
assert "Warning: No __all__ defined in" in captured.out
|
||||
|
||||
|
||||
def test_extract_available_tools_no_all_variable(temp_project_dir, capsys):
|
||||
def test_extract_available_exports_no_all_variable(temp_project_dir, capsys):
|
||||
create_init_file(
|
||||
temp_project_dir,
|
||||
"from crewai.tools import BaseTool\n\nclass MyTool(BaseTool):\n pass",
|
||||
)
|
||||
with pytest.raises(SystemExit):
|
||||
utils.extract_available_tools(dir_path=temp_project_dir)
|
||||
utils.extract_available_exports(dir_path=temp_project_dir)
|
||||
captured = capsys.readouterr()
|
||||
|
||||
assert "Warning: No __all__ defined in" in captured.out
|
||||
|
||||
|
||||
def test_extract_available_tools_valid_base_tool_class(temp_project_dir):
|
||||
def test_extract_available_exports_valid_base_tool_class(temp_project_dir):
|
||||
create_init_file(
|
||||
temp_project_dir,
|
||||
"""from crewai.tools import BaseTool
|
||||
@@ -163,11 +164,11 @@ class MyTool(BaseTool):
|
||||
__all__ = ['MyTool']
|
||||
""",
|
||||
)
|
||||
tools = utils.extract_available_tools(dir_path=temp_project_dir)
|
||||
tools = utils.extract_available_exports(dir_path=temp_project_dir)
|
||||
assert ["MyTool"] == tools
|
||||
|
||||
|
||||
def test_extract_available_tools_valid_tool_decorator(temp_project_dir):
|
||||
def test_extract_available_exports_valid_tool_decorator(temp_project_dir):
|
||||
create_init_file(
|
||||
temp_project_dir,
|
||||
"""from crewai.tools import tool
|
||||
@@ -180,11 +181,11 @@ def my_tool_function(text: str) -> str:
|
||||
__all__ = ['my_tool_function']
|
||||
""",
|
||||
)
|
||||
tools = utils.extract_available_tools(dir_path=temp_project_dir)
|
||||
tools = utils.extract_available_exports(dir_path=temp_project_dir)
|
||||
assert ["my_tool_function"] == tools
|
||||
|
||||
|
||||
def test_extract_available_tools_multiple_valid_tools(temp_project_dir):
|
||||
def test_extract_available_exports_multiple_valid_tools(temp_project_dir):
|
||||
create_init_file(
|
||||
temp_project_dir,
|
||||
"""from crewai.tools import BaseTool, tool
|
||||
@@ -201,11 +202,11 @@ def my_tool_function(text: str) -> str:
|
||||
__all__ = ['MyTool', 'my_tool_function']
|
||||
""",
|
||||
)
|
||||
tools = utils.extract_available_tools(dir_path=temp_project_dir)
|
||||
tools = utils.extract_available_exports(dir_path=temp_project_dir)
|
||||
assert ["MyTool", "my_tool_function"] == tools
|
||||
|
||||
|
||||
def test_extract_available_tools_with_invalid_tool_decorator(temp_project_dir):
|
||||
def test_extract_available_exports_with_invalid_tool_decorator(temp_project_dir):
|
||||
create_init_file(
|
||||
temp_project_dir,
|
||||
"""from crewai.tools import BaseTool
|
||||
@@ -220,11 +221,11 @@ def not_a_tool():
|
||||
__all__ = ['MyTool', 'not_a_tool']
|
||||
""",
|
||||
)
|
||||
tools = utils.extract_available_tools(dir_path=temp_project_dir)
|
||||
tools = utils.extract_available_exports(dir_path=temp_project_dir)
|
||||
assert ["MyTool"] == tools
|
||||
|
||||
|
||||
def test_extract_available_tools_import_error(temp_project_dir, capsys):
|
||||
def test_extract_available_exports_import_error(temp_project_dir, capsys):
|
||||
create_init_file(
|
||||
temp_project_dir,
|
||||
"""from nonexistent_module import something
|
||||
@@ -236,13 +237,13 @@ __all__ = ['MyTool']
|
||||
""",
|
||||
)
|
||||
with pytest.raises(SystemExit):
|
||||
utils.extract_available_tools(dir_path=temp_project_dir)
|
||||
utils.extract_available_exports(dir_path=temp_project_dir)
|
||||
captured = capsys.readouterr()
|
||||
|
||||
assert "nonexistent_module" in captured.out
|
||||
|
||||
|
||||
def test_extract_available_tools_syntax_error(temp_project_dir, capsys):
|
||||
def test_extract_available_exports_syntax_error(temp_project_dir, capsys):
|
||||
create_init_file(
|
||||
temp_project_dir,
|
||||
"""from crewai.tools import BaseTool
|
||||
@@ -256,7 +257,7 @@ __all__ = ['MyTool']
|
||||
""",
|
||||
)
|
||||
with pytest.raises(SystemExit):
|
||||
utils.extract_available_tools(dir_path=temp_project_dir)
|
||||
utils.extract_available_exports(dir_path=temp_project_dir)
|
||||
captured = capsys.readouterr()
|
||||
|
||||
assert "was never closed" in captured.out
|
||||
|
||||
@@ -135,9 +135,9 @@ def test_publish_when_not_in_sync(mock_is_synced, capsys, tool_command):
|
||||
)
|
||||
@patch("crewai.cli.plus_api.PlusAPI.publish_tool")
|
||||
@patch("crewai.cli.tools.main.git.Repository.is_synced", return_value=False)
|
||||
@patch("crewai.cli.tools.main.extract_available_tools", return_value=["SampleTool"])
|
||||
@patch("crewai.cli.tools.main.available_exports", return_value=["SampleTool"])
|
||||
def test_publish_when_not_in_sync_and_force(
|
||||
mock_extract_available_tools,
|
||||
mock_available_exports,
|
||||
mock_is_synced,
|
||||
mock_publish,
|
||||
mock_open,
|
||||
@@ -170,7 +170,7 @@ def test_publish_when_not_in_sync_and_force(
|
||||
version="1.0.0",
|
||||
description="A sample tool",
|
||||
encoded_file=unittest.mock.ANY,
|
||||
available_tools=["SampleTool"],
|
||||
available_exports=["SampleTool"],
|
||||
)
|
||||
|
||||
|
||||
@@ -186,9 +186,9 @@ def test_publish_when_not_in_sync_and_force(
|
||||
)
|
||||
@patch("crewai.cli.plus_api.PlusAPI.publish_tool")
|
||||
@patch("crewai.cli.tools.main.git.Repository.is_synced", return_value=True)
|
||||
@patch("crewai.cli.tools.main.extract_available_tools", return_value=["SampleTool"])
|
||||
@patch("crewai.cli.tools.main.available_exports", return_value=["SampleTool"])
|
||||
def test_publish_success(
|
||||
mock_extract_available_tools,
|
||||
mock_available_exports,
|
||||
mock_is_synced,
|
||||
mock_publish,
|
||||
mock_open,
|
||||
@@ -221,7 +221,7 @@ def test_publish_success(
|
||||
version="1.0.0",
|
||||
description="A sample tool",
|
||||
encoded_file=unittest.mock.ANY,
|
||||
available_tools=["SampleTool"],
|
||||
available_exports=["SampleTool"],
|
||||
)
|
||||
|
||||
|
||||
@@ -236,9 +236,9 @@ def test_publish_success(
|
||||
read_data=b"sample tarball content",
|
||||
)
|
||||
@patch("crewai.cli.plus_api.PlusAPI.publish_tool")
|
||||
@patch("crewai.cli.tools.main.extract_available_tools", return_value=["SampleTool"])
|
||||
@patch("crewai.cli.tools.main.available_exports", return_value=["SampleTool"])
|
||||
def test_publish_failure(
|
||||
mock_extract_available_tools,
|
||||
mock_available_exports,
|
||||
mock_publish,
|
||||
mock_open,
|
||||
mock_listdir,
|
||||
@@ -274,9 +274,9 @@ def test_publish_failure(
|
||||
read_data=b"sample tarball content",
|
||||
)
|
||||
@patch("crewai.cli.plus_api.PlusAPI.publish_tool")
|
||||
@patch("crewai.cli.tools.main.extract_available_tools", return_value=["SampleTool"])
|
||||
@patch("crewai.cli.tools.main.available_exports", return_value=["SampleTool"])
|
||||
def test_publish_api_error(
|
||||
mock_extract_available_tools,
|
||||
mock_available_exports,
|
||||
mock_publish,
|
||||
mock_open,
|
||||
mock_listdir,
|
||||
|
||||
Reference in New Issue
Block a user