Skip to content

Remove global config from tests #3052

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions tests/test_fileops.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,36 @@

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')
Expand All @@ -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'
)
55 changes: 23 additions & 32 deletions tests/unit/test_ipython.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

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
Expand Down Expand Up @@ -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()