diff --git a/tests/test_fileops.py b/tests/test_fileops.py index 61518646c7..3b296f13de 100644 --- a/tests/test_fileops.py +++ b/tests/test_fileops.py @@ -2,36 +2,36 @@ from pathlib import Path import pytest -from opendevin.core.config import config from opendevin.runtime.server import files SANDBOX_PATH_PREFIX = '/workspace' +WORKSPACE_BASE = 'workspace' def test_resolve_path(): assert ( files.resolve_path('test.txt', '/workspace') - == Path(config.workspace_base) / 'test.txt' + == Path(WORKSPACE_BASE) / 'test.txt' ) assert ( files.resolve_path('subdir/test.txt', '/workspace') - == Path(config.workspace_base) / 'subdir' / 'test.txt' + == Path(WORKSPACE_BASE) / 'subdir' / 'test.txt' ) assert ( files.resolve_path(Path(SANDBOX_PATH_PREFIX) / 'test.txt', '/workspace') - == Path(config.workspace_base) / 'test.txt' + == Path(WORKSPACE_BASE) / 'test.txt' ) assert ( files.resolve_path( Path(SANDBOX_PATH_PREFIX) / 'subdir' / 'test.txt', '/workspace' ) - == Path(config.workspace_base) / 'subdir' / 'test.txt' + == Path(WORKSPACE_BASE) / 'subdir' / 'test.txt' ) assert ( files.resolve_path( Path(SANDBOX_PATH_PREFIX) / 'subdir' / '..' / 'test.txt', '/workspace' ) - == Path(config.workspace_base) / 'test.txt' + == Path(WORKSPACE_BASE) / 'test.txt' ) with pytest.raises(PermissionError): files.resolve_path(Path(SANDBOX_PATH_PREFIX) / '..' / 'test.txt', '/workspace') @@ -41,5 +41,5 @@ def test_resolve_path(): files.resolve_path(Path('/') / 'test.txt', '/workspace') assert ( files.resolve_path('test.txt', '/workspace/test') - == Path(config.workspace_base) / 'test' / 'test.txt' + == Path(WORKSPACE_BASE) / 'test' / 'test.txt' ) diff --git a/tests/unit/test_ipython.py b/tests/unit/test_ipython.py index 4e52487e47..02ff726530 100644 --- a/tests/unit/test_ipython.py +++ b/tests/unit/test_ipython.py @@ -4,7 +4,7 @@ from unittest.mock import MagicMock, call, patch import pytest -from opendevin.core.config import SandboxConfig, config +from opendevin.core.config import SandboxConfig from opendevin.events.action import IPythonRunCellAction from opendevin.events.observation import IPythonRunCellObservation from opendevin.runtime.docker.ssh_box import DockerSSHBox @@ -78,34 +78,25 @@ async def test_run_python_backticks(): def test_sandbox_jupyter_plugin_backticks(temp_dir): - # get a temporary directory - with patch.object(config, 'workspace_base', new=temp_dir), patch.object( - config, 'workspace_mount_path', new=temp_dir - ), patch.object(config, 'run_as_devin', new='true'), patch.object( - config.sandbox, 'box_type', new='ssh' - ): - box = DockerSSHBox( - config=config.sandbox, - persist_sandbox=config.persist_sandbox, - workspace_mount_path=config.workspace_mount_path, - sandbox_workspace_dir=config.workspace_mount_path_in_sandbox, - cache_dir=config.cache_dir, - run_as_devin=config.run_as_devin, - ssh_hostname=config.ssh_hostname, - ssh_password=config.ssh_password, - ssh_port=config.ssh_port, - ) - box.init_plugins([JupyterRequirement]) - test_code = "print('Hello, `World`!')" - expected_write_command = ( - "cat > /tmp/opendevin_jupyter_temp.py <<'EOL'\n" f'{test_code}\n' 'EOL' - ) - expected_execute_command = 'cat /tmp/opendevin_jupyter_temp.py | execute_cli' - exit_code, output = box.execute(expected_write_command) - exit_code, output = box.execute(expected_execute_command) - print(output) - assert exit_code == 0, 'The exit code should be 0 for ' + box.__class__.__name__ - assert output.strip() == 'Hello, `World`!', ( - 'The output should be the same as the input for ' + box.__class__.__name__ - ) - box.close() + box = DockerSSHBox( + config=SandboxConfig(), + persist_sandbox=False, + workspace_mount_path=temp_dir, + sandbox_workspace_dir='/workspace', + cache_dir='/tmp/cache', + run_as_devin=True, + ) + box.init_plugins([JupyterRequirement]) + test_code = "print('Hello, `World`!')" + expected_write_command = ( + "cat > /tmp/opendevin_jupyter_temp.py <<'EOL'\n" f'{test_code}\n' 'EOL' + ) + expected_execute_command = 'cat /tmp/opendevin_jupyter_temp.py | execute_cli' + exit_code, output = box.execute(expected_write_command) + exit_code, output = box.execute(expected_execute_command) + print(output) + assert exit_code == 0, 'The exit code should be 0 for ' + box.__class__.__name__ + assert output.strip() == 'Hello, `World`!', ( + 'The output should be the same as the input for ' + box.__class__.__name__ + ) + box.close()