forked from OpenHands/OpenHands
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_storage.py
More file actions
65 lines (51 loc) · 2.2 KB
/
test_storage.py
File metadata and controls
65 lines (51 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import os
import shutil
import pytest
from opendevin.storage.local import LocalFileStore
from opendevin.storage.memory import InMemoryFileStore
@pytest.fixture
def setup_env():
os.makedirs('./_test_files_tmp', exist_ok=True)
yield
shutil.rmtree('./_test_files_tmp')
def test_basic_fileops(setup_env):
filename = 'test.txt'
for store in [LocalFileStore('./_test_files_tmp'), InMemoryFileStore()]:
store.write(filename, 'Hello, world!')
assert store.read(filename) == 'Hello, world!'
assert store.list('') == [filename]
store.delete(filename)
with pytest.raises(FileNotFoundError):
store.read(filename)
def test_complex_path_fileops(setup_env):
filenames = ['foo.bar.baz', './foo/bar/baz', 'foo/bar/baz', '/foo/bar/baz']
for store in [LocalFileStore('./_test_files_tmp'), InMemoryFileStore()]:
for filename in filenames:
store.write(filename, 'Hello, world!')
assert store.read(filename) == 'Hello, world!'
store.delete(filename)
with pytest.raises(FileNotFoundError):
store.read(filename)
def test_list(setup_env):
for store in [LocalFileStore('./_test_files_tmp'), InMemoryFileStore()]:
store.write('foo.txt', 'Hello, world!')
store.write('bar.txt', 'Hello, world!')
store.write('baz.txt', 'Hello, world!')
assert store.list('').sort() == ['foo.txt', 'bar.txt', 'baz.txt'].sort()
store.delete('foo.txt')
store.delete('bar.txt')
store.delete('baz.txt')
def test_deep_list(setup_env):
for store in [LocalFileStore('./_test_files_tmp'), InMemoryFileStore()]:
store.write('foo/bar/baz.txt', 'Hello, world!')
store.write('foo/bar/qux.txt', 'Hello, world!')
store.write('foo/bar/quux.txt', 'Hello, world!')
assert store.list('') == ['foo/'], f'for class {store.__class__}'
assert store.list('foo') == ['foo/bar/']
assert (
store.list('foo/bar').sort()
== ['foo/bar/baz.txt', 'foo/bar/qux.txt', 'foo/bar/quux.txt'].sort()
)
store.delete('foo/bar/baz.txt')
store.delete('foo/bar/qux.txt')
store.delete('foo/bar/quux.txt')