🐫 CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org
Python agentai-societiesartificial-intelligencecommunicative-aicooperative-aideep-learninglarge-language-modelsmulti-agent-systemsnatural-language-processing
fix: microsandbox test (#3104)
Wendong-Fan2ce16ad45994
diff --git a/test/interpreters/test_microsandbox_interpreter.py b/test/interpreters/test_microsandbox_interpreter.pyindex 16688060f..736c7cea3 100644--- a/test/interpreters/test_microsandbox_interpreter.py+++ b/test/interpreters/test_microsandbox_interpreter.py@@ -12,6 +12,8 @@# limitations under the License.# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========+from unittest.mock import patch+import pytestfrom camel.interpreters import InterpreterError, MicrosandboxInterpreter@@ -23,149 +25,55 @@ MICROSANDBOX_SERVER = "http://192.168.122.56:5555"@pytest.fixturedef interpreter():"""Create a MicrosandboxInterpreter for testing."""- return MicrosandboxInterpreter(- require_confirm=False,- server_url=MICROSANDBOX_SERVER,- namespace="test",- timeout=30,- )+ with (+ patch('microsandbox.PythonSandbox'),+ patch('microsandbox.NodeSandbox'),+ ):+ return MicrosandboxInterpreter(+ require_confirm=False,+ server_url=MICROSANDBOX_SERVER,+ namespace="test",+ timeout=30,+ )def test_initialization():"""Test basic initialization."""- interpreter = MicrosandboxInterpreter(- require_confirm=False,- server_url=MICROSANDBOX_SERVER,- namespace="test-init",- timeout=60,- )-- assert interpreter.require_confirm is False- assert interpreter.server_url == MICROSANDBOX_SERVER- assert interpreter.namespace == "test-init"- assert interpreter.timeout == 60+ with (+ patch('microsandbox.PythonSandbox'),+ patch('microsandbox.NodeSandbox'),+ ):+ interpreter = MicrosandboxInterpreter(+ require_confirm=False,+ server_url=MICROSANDBOX_SERVER,+ namespace="test-init",+ timeout=60,+ )++ assert interpreter.require_confirm is False+ assert interpreter.server_url == MICROSANDBOX_SERVER+ assert interpreter.namespace == "test-init"+ assert interpreter.timeout == 60def test_supported_code_types():"""Test supported code types."""- interpreter = MicrosandboxInterpreter(require_confirm=False)- supported_types = interpreter.supported_code_types()-- # Check basic types are supported- assert "python" in supported_types- assert "javascript" in supported_types- assert "bash" in supported_types---def test_python_execution(interpreter):- """Test Python code execution."""- code = "print('Hello Python')"- result = interpreter.run(code, "python")-- assert "Hello Python" in result---def test_python_math(interpreter):- """Test Python math operations."""- code = """-x = 10 + 5-print(f"Result: {x}")-"""- result = interpreter.run(code, "python")-- assert "Result: 15" in result---def test_javascript_execution(interpreter):- """Test JavaScript code execution."""- code = "console.log('Hello JavaScript');"- result = interpreter.run(code, "javascript")-- assert "Hello JavaScript" in result---def test_shell_execution(interpreter):- """Test shell command execution."""- result = interpreter.run("echo 'Hello Shell'", "bash")-- assert "Hello Shell" in result+ with (+ patch('microsandbox.PythonSandbox'),+ patch('microsandbox.NodeSandbox'),+ ):+ interpreter = MicrosandboxInterpreter(require_confirm=False)+ supported_types = interpreter.supported_code_types()--def test_execute_command(interpreter):- """Test execute_command method."""- result = interpreter.execute_command("echo test")-- # Should return something (either output or success message)- assert result is not None- assert len(result) > 0- # Accept both successful execution and actual output- assert "executed successfully" in result or "test" in result+ # Check basic types are supported+ assert "python" in supported_types+ assert "javascript" in supported_types+ assert "bash" in supported_typesdef test_unsupported_language(interpreter):"""Test unsupported language raises error."""- with pytest.raises(InterpreterError):+ with pytest.raises(InterpreterError) as exc_info:interpreter.run("test", "unsupported_language")--def test_python_error_handling(interpreter):- """Test Python error handling."""- code = "x = 1 / 0" # Division by zero- result = interpreter.run(code, "python")-- # Should contain error information- assert any(- keyword in result- for keyword in ["Error", "Exception", "ZeroDivisionError"]- )---def test_variable_persistence(interpreter):- """Test variables within single execution."""- # Set and use variable in same execution- code = """-x = 100-print(f'x = {x}')-"""- result = interpreter.run(code, "python")- assert "x = 100" in result---if __name__ == "__main__":- # Simple manual test- print("Testing MicrosandboxInterpreter...")-- interp = MicrosandboxInterpreter(- require_confirm=False,- server_url=MICROSANDBOX_SERVER,- namespace="manual-test",- )-- # Test Python- result = interp.run("print('Manual test works!')", "python")- print(f"Python test: {result}")-- print("Manual test completed!")--"""-================================== test session starts ===================================-platform linux -- Python 3.11.7, pytest-8.4.1, pluggy-1.6.0 -- /home/lyz/Camel/camel/.camel/bin/python3-cachedir: .pytest_cache-rootdir: /home/lyz/Camel/camel-configfile: pyproject.toml-plugins: anyio-4.10.0-collected 10 items--test/interpreters/test_microsandbox_interpreter.py::test_initialization PASSED [ 10%]-test/interpreters/test_microsandbox_interpreter.py::test_supported_code_types PASSED [ 20%]-test/interpreters/test_microsandbox_interpreter.py::test_python_execution PASSED [ 30%]-test/interpreters/test_microsandbox_interpreter.py::test_python_math PASSED [ 40%]-test/interpreters/test_microsandbox_interpreter.py::test_javascript_execution PASSED [ 50%]-test/interpreters/test_microsandbox_interpreter.py::test_shell_execution PASSED [ 60%]-test/interpreters/test_microsandbox_interpreter.py::test_execute_command PASSED [ 70%]-test/interpreters/test_microsandbox_interpreter.py::test_unsupported_language PASSED [ 80%]-test/interpreters/test_microsandbox_interpreter.py::test_python_error_handling PASSED [ 90%]-test/interpreters/test_microsandbox_interpreter.py::test_variable_persistence PASSED [100%]--================================== 10 passed in 33.76s ===================================-""" # noqa: E501+ assert "Unsupported code type" in str(exc_info.value)diff --git a/test/runtimes/test_daytona_runtime.py b/test/runtimes/test_daytona_runtime.pyindex ab00df377..4565d45ec 100644--- a/test/runtimes/test_daytona_runtime.py+++ b/test/runtimes/test_daytona_runtime.py@@ -68,7 +68,7 @@ def test_init_with_env_vars(mock_config, mock_daytona):)-@patch('daytona_sdk.CreateSandboxParams')+@patch('daytona_sdk.CreateSandboxBaseParams')@patch('daytona_sdk.Daytona')@patch('daytona_sdk.DaytonaConfig')def test_build_success(mock_config, mock_daytona, mock_params):@@ -89,7 +89,7 @@ def test_build_success(mock_config, mock_daytona, mock_params):assert result == runtime # Should return self-@patch('daytona_sdk.CreateSandboxParams')+@patch('daytona_sdk.CreateSandboxBaseParams')@patch('daytona_sdk.Daytona')@patch('daytona_sdk.DaytonaConfig')def test_build_failure(mock_config, mock_daytona, mock_params):@@ -123,8 +123,8 @@ def test_stop(mock_config, mock_daytona):# Stop sandboxresult = runtime.stop()- # Assert sandbox was removed- mock_daytona_instance.remove.assert_called_once_with(mock_sandbox)+ # Assert sandbox was deleted+ mock_daytona_instance.delete.assert_called_once_with(mock_sandbox)assert runtime.sandbox is Noneassert result == runtime # Should return self@@ -172,8 +172,8 @@ def test_reset(mock_config, mock_daytona):# Reset sandboxresult = runtime.reset()- # Assert sandbox was removed and rebuilt- mock_daytona_instance.remove.assert_called_once_with(mock_sandbox)+ # Assert sandbox was deleted and rebuilt+ mock_daytona_instance.delete.assert_called_once_with(mock_sandbox)assert runtime.build.calledassert result == runtime # Should return self