mirror of
https://github.com/All-Hands-AI/OpenHands.git
synced 2026-01-09 23:08:04 -05:00
Remove global config from tests (#3052)
This commit is contained in:
@@ -2,36 +2,36 @@ from pathlib import Path
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from opendevin.core.config import config
|
|
||||||
from opendevin.runtime.server import files
|
from opendevin.runtime.server import files
|
||||||
|
|
||||||
SANDBOX_PATH_PREFIX = '/workspace'
|
SANDBOX_PATH_PREFIX = '/workspace'
|
||||||
|
WORKSPACE_BASE = 'workspace'
|
||||||
|
|
||||||
|
|
||||||
def test_resolve_path():
|
def test_resolve_path():
|
||||||
assert (
|
assert (
|
||||||
files.resolve_path('test.txt', '/workspace')
|
files.resolve_path('test.txt', '/workspace')
|
||||||
== Path(config.workspace_base) / 'test.txt'
|
== Path(WORKSPACE_BASE) / 'test.txt'
|
||||||
)
|
)
|
||||||
assert (
|
assert (
|
||||||
files.resolve_path('subdir/test.txt', '/workspace')
|
files.resolve_path('subdir/test.txt', '/workspace')
|
||||||
== Path(config.workspace_base) / 'subdir' / 'test.txt'
|
== Path(WORKSPACE_BASE) / 'subdir' / 'test.txt'
|
||||||
)
|
)
|
||||||
assert (
|
assert (
|
||||||
files.resolve_path(Path(SANDBOX_PATH_PREFIX) / 'test.txt', '/workspace')
|
files.resolve_path(Path(SANDBOX_PATH_PREFIX) / 'test.txt', '/workspace')
|
||||||
== Path(config.workspace_base) / 'test.txt'
|
== Path(WORKSPACE_BASE) / 'test.txt'
|
||||||
)
|
)
|
||||||
assert (
|
assert (
|
||||||
files.resolve_path(
|
files.resolve_path(
|
||||||
Path(SANDBOX_PATH_PREFIX) / 'subdir' / 'test.txt', '/workspace'
|
Path(SANDBOX_PATH_PREFIX) / 'subdir' / 'test.txt', '/workspace'
|
||||||
)
|
)
|
||||||
== Path(config.workspace_base) / 'subdir' / 'test.txt'
|
== Path(WORKSPACE_BASE) / 'subdir' / 'test.txt'
|
||||||
)
|
)
|
||||||
assert (
|
assert (
|
||||||
files.resolve_path(
|
files.resolve_path(
|
||||||
Path(SANDBOX_PATH_PREFIX) / 'subdir' / '..' / 'test.txt', '/workspace'
|
Path(SANDBOX_PATH_PREFIX) / 'subdir' / '..' / 'test.txt', '/workspace'
|
||||||
)
|
)
|
||||||
== Path(config.workspace_base) / 'test.txt'
|
== Path(WORKSPACE_BASE) / 'test.txt'
|
||||||
)
|
)
|
||||||
with pytest.raises(PermissionError):
|
with pytest.raises(PermissionError):
|
||||||
files.resolve_path(Path(SANDBOX_PATH_PREFIX) / '..' / 'test.txt', '/workspace')
|
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')
|
files.resolve_path(Path('/') / 'test.txt', '/workspace')
|
||||||
assert (
|
assert (
|
||||||
files.resolve_path('test.txt', '/workspace/test')
|
files.resolve_path('test.txt', '/workspace/test')
|
||||||
== Path(config.workspace_base) / 'test' / 'test.txt'
|
== Path(WORKSPACE_BASE) / 'test' / 'test.txt'
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ from unittest.mock import MagicMock, call, patch
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from opendevin.core.config import SandboxConfig, config
|
from opendevin.core.config import SandboxConfig
|
||||||
from opendevin.events.action import IPythonRunCellAction
|
from opendevin.events.action import IPythonRunCellAction
|
||||||
from opendevin.events.observation import IPythonRunCellObservation
|
from opendevin.events.observation import IPythonRunCellObservation
|
||||||
from opendevin.runtime.docker.ssh_box import DockerSSHBox
|
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):
|
def test_sandbox_jupyter_plugin_backticks(temp_dir):
|
||||||
# get a temporary directory
|
box = DockerSSHBox(
|
||||||
with patch.object(config, 'workspace_base', new=temp_dir), patch.object(
|
config=SandboxConfig(),
|
||||||
config, 'workspace_mount_path', new=temp_dir
|
persist_sandbox=False,
|
||||||
), patch.object(config, 'run_as_devin', new='true'), patch.object(
|
workspace_mount_path=temp_dir,
|
||||||
config.sandbox, 'box_type', new='ssh'
|
sandbox_workspace_dir='/workspace',
|
||||||
):
|
cache_dir='/tmp/cache',
|
||||||
box = DockerSSHBox(
|
run_as_devin=True,
|
||||||
config=config.sandbox,
|
)
|
||||||
persist_sandbox=config.persist_sandbox,
|
box.init_plugins([JupyterRequirement])
|
||||||
workspace_mount_path=config.workspace_mount_path,
|
test_code = "print('Hello, `World`!')"
|
||||||
sandbox_workspace_dir=config.workspace_mount_path_in_sandbox,
|
expected_write_command = (
|
||||||
cache_dir=config.cache_dir,
|
"cat > /tmp/opendevin_jupyter_temp.py <<'EOL'\n" f'{test_code}\n' 'EOL'
|
||||||
run_as_devin=config.run_as_devin,
|
)
|
||||||
ssh_hostname=config.ssh_hostname,
|
expected_execute_command = 'cat /tmp/opendevin_jupyter_temp.py | execute_cli'
|
||||||
ssh_password=config.ssh_password,
|
exit_code, output = box.execute(expected_write_command)
|
||||||
ssh_port=config.ssh_port,
|
exit_code, output = box.execute(expected_execute_command)
|
||||||
)
|
print(output)
|
||||||
box.init_plugins([JupyterRequirement])
|
assert exit_code == 0, 'The exit code should be 0 for ' + box.__class__.__name__
|
||||||
test_code = "print('Hello, `World`!')"
|
assert output.strip() == 'Hello, `World`!', (
|
||||||
expected_write_command = (
|
'The output should be the same as the input for ' + box.__class__.__name__
|
||||||
"cat > /tmp/opendevin_jupyter_temp.py <<'EOL'\n" f'{test_code}\n' 'EOL'
|
)
|
||||||
)
|
box.close()
|
||||||
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()
|
|
||||||
|
|||||||
Reference in New Issue
Block a user