Files
OpenHands/tests/test_fileops.py
Robert Brennan ce7c7eaae4 Refactor actions and observations (#1479)
* refactor actions and events

* remove type_key

* remove stream

* move import

* move import

* fix NullObs

* reorder imports

* fix lint

* fix dataclasses

* remove blank fields

* fix nullobs

* fix sidebar labels

* fix test compilation

* switch to asdict

* lint

* fix whitespace

* fix executable

* delint

* fix run

* remove NotImplementeds

* fix path prefix

* remove null files

* add debug

* add more debug info

* fix dataclass on null

* remove debug

* revert sandbox

* fix merge issues

* fix tyeps

* Update opendevin/events/action/browse.py
2024-05-02 15:44:54 +00:00

29 lines
1.5 KiB
Python

from pathlib import Path
import pytest
from opendevin import config
from opendevin.events.action import files
from opendevin.schema import ConfigType
SANDBOX_PATH_PREFIX = '/workspace'
def test_resolve_path():
assert files.resolve_path('test.txt', '/workspace') == Path(config.get(ConfigType.WORKSPACE_BASE)) / 'test.txt'
assert files.resolve_path('subdir/test.txt', '/workspace') == \
Path(config.get(ConfigType.WORKSPACE_BASE)) / 'subdir' / 'test.txt'
assert files.resolve_path(Path(SANDBOX_PATH_PREFIX) / 'test.txt', '/workspace') == \
Path(config.get(ConfigType.WORKSPACE_BASE)) / 'test.txt'
assert files.resolve_path(Path(SANDBOX_PATH_PREFIX) / 'subdir' / 'test.txt',
'/workspace') == Path(config.get(ConfigType.WORKSPACE_BASE)) / 'subdir' / 'test.txt'
assert files.resolve_path(Path(SANDBOX_PATH_PREFIX) / 'subdir' / '..' / 'test.txt',
'/workspace') == Path(config.get(ConfigType.WORKSPACE_BASE)) / 'test.txt'
with pytest.raises(PermissionError):
files.resolve_path(Path(SANDBOX_PATH_PREFIX) / '..' / 'test.txt', '/workspace')
with pytest.raises(PermissionError):
files.resolve_path(Path('..') / 'test.txt', '/workspace')
with pytest.raises(PermissionError):
files.resolve_path(Path('/') / 'test.txt', '/workspace')
assert files.resolve_path('test.txt', '/workspace/test') == \
Path(config.get(ConfigType.WORKSPACE_BASE)) / 'test' / 'test.txt'