mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-26 08:38:15 +00:00
fixed code interpreter tests
This commit is contained in:
@@ -7,30 +7,30 @@ from crewai_tools.tools.code_interpreter_tool.code_interpreter_tool import (
|
|||||||
|
|
||||||
|
|
||||||
class TestCodeInterpreterTool(unittest.TestCase):
|
class TestCodeInterpreterTool(unittest.TestCase):
|
||||||
@patch("crewai_tools.tools.code_interpreter_tool.code_interpreter_tool.docker")
|
@patch("crewai_tools.tools.code_interpreter_tool.code_interpreter_tool.docker_from_env")
|
||||||
def test_run_code_in_docker(self, docker_mock):
|
def test_run_code_in_docker(self, docker_mock):
|
||||||
tool = CodeInterpreterTool()
|
tool = CodeInterpreterTool()
|
||||||
code = "print('Hello, World!')"
|
code = "print('Hello, World!')"
|
||||||
libraries_used = "numpy,pandas"
|
libraries_used = ["numpy", "pandas"]
|
||||||
expected_output = "Hello, World!\n"
|
expected_output = "Hello, World!\n"
|
||||||
|
|
||||||
docker_mock.from_env().containers.run().exec_run().exit_code = 0
|
docker_mock().containers.run().exec_run().exit_code = 0
|
||||||
docker_mock.from_env().containers.run().exec_run().output = (
|
docker_mock().containers.run().exec_run().output = (
|
||||||
expected_output.encode()
|
expected_output.encode()
|
||||||
)
|
)
|
||||||
result = tool.run_code_in_docker(code, libraries_used)
|
result = tool.run_code_in_docker(code, libraries_used)
|
||||||
|
|
||||||
self.assertEqual(result, expected_output)
|
self.assertEqual(result, expected_output)
|
||||||
|
|
||||||
@patch("crewai_tools.tools.code_interpreter_tool.code_interpreter_tool.docker")
|
@patch("crewai_tools.tools.code_interpreter_tool.code_interpreter_tool.docker_from_env")
|
||||||
def test_run_code_in_docker_with_error(self, docker_mock):
|
def test_run_code_in_docker_with_error(self, docker_mock):
|
||||||
tool = CodeInterpreterTool()
|
tool = CodeInterpreterTool()
|
||||||
code = "print(1/0)"
|
code = "print(1/0)"
|
||||||
libraries_used = "numpy,pandas"
|
libraries_used = ["numpy", "pandas"]
|
||||||
expected_output = "Something went wrong while running the code: \nZeroDivisionError: division by zero\n"
|
expected_output = "Something went wrong while running the code: \nZeroDivisionError: division by zero\n"
|
||||||
|
|
||||||
docker_mock.from_env().containers.run().exec_run().exit_code = 1
|
docker_mock().containers.run().exec_run().exit_code = 1
|
||||||
docker_mock.from_env().containers.run().exec_run().output = (
|
docker_mock().containers.run().exec_run().output = (
|
||||||
b"ZeroDivisionError: division by zero\n"
|
b"ZeroDivisionError: division by zero\n"
|
||||||
)
|
)
|
||||||
result = tool.run_code_in_docker(code, libraries_used)
|
result = tool.run_code_in_docker(code, libraries_used)
|
||||||
|
|||||||
Reference in New Issue
Block a user