Skip to content

Commit 4b31b3c

Browse files
committed
Add get and set methods to test class
1 parent 247432f commit 4b31b3c

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/zarr/testing/store.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ class StoreTests(Generic[S, B]):
2323
async def set(self, store: S, key: str, value: Buffer) -> None:
2424
"""
2525
Insert a value into a storage backend, with a specific key.
26-
This should not not use any store methods. Bypassing the store methods allows them to be
26+
This should not use any store methods. Bypassing the store methods allows them to be
2727
tested.
2828
"""
2929
raise NotImplementedError
3030

3131
async def get(self, store: S, key: str) -> Buffer:
3232
"""
3333
Retrieve a value from a storage backend, by key.
34-
This should not not use any store methods. Bypassing the store methods allows them to be
34+
This should not use any store methods. Bypassing the store methods allows them to be
3535
tested.
3636
"""
3737

tests/test_store/test_object.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33

44
obstore = pytest.importorskip("obstore")
55

6-
from zarr.core.buffer import cpu
6+
import re
7+
8+
from zarr.core.buffer import Buffer, cpu
79
from zarr.storage.object_store import ObjectStore
810
from zarr.testing.store import StoreTests
911

12+
PATTERN = r"file://(/[\w/.-]+)"
13+
1014

1115
class TestObjectStore(StoreTests[ObjectStore, cpu.Buffer]):
1216
store_cls = ObjectStore
@@ -21,6 +25,18 @@ def store_kwargs(self, tmpdir) -> dict[str, str | bool]:
2125
def store(self, store_kwargs: dict[str, str | bool]) -> ObjectStore:
2226
return self.store_cls(**store_kwargs)
2327

28+
async def get(self, store: ObjectStore, key: str) -> Buffer:
29+
# TODO: There must be a better way to get the path to the store
30+
store_path = re.search(PATTERN, str(store)).group(1)
31+
new_local_store = obstore.store.LocalStore(prefix=store_path)
32+
return self.buffer_cls.from_bytes(obstore.get(new_local_store, key))
33+
34+
async def set(self, store: ObjectStore, key: str, value: Buffer) -> None:
35+
# TODO: There must be a better way to get the path to the store
36+
store_path = re.search(PATTERN, str(store)).group(1)
37+
new_local_store = obstore.store.LocalStore(prefix=store_path)
38+
obstore.put(new_local_store, key, value.to_bytes())
39+
2440
def test_store_repr(self, store: ObjectStore) -> None:
2541
from fnmatch import fnmatch
2642

0 commit comments

Comments
 (0)