33
44obstore = pytest .importorskip ("obstore" )
55
6- from zarr .core .buffer import cpu
6+ import re
7+
8+ from zarr .core .buffer import Buffer , cpu
79from zarr .storage .object_store import ObjectStore
810from zarr .testing .store import StoreTests
911
12+ PATTERN = r"file://(/[\w/.-]+)"
13+
1014
1115class 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