|
1 | 1 | # ruff: noqa: E402 |
| 2 | +import pickle |
| 3 | +from typing import Any |
| 4 | + |
2 | 5 | import pytest |
3 | 6 |
|
4 | 7 | obstore = pytest.importorskip("obstore") |
5 | | - |
6 | | -import pickle |
7 | | -import re |
| 8 | +from obstore.store import LocalStore |
8 | 9 |
|
9 | 10 | from zarr.core.buffer import Buffer, cpu |
10 | 11 | from zarr.storage import ObjectStore |
11 | 12 | from zarr.testing.store import StoreTests |
12 | 13 |
|
13 | | -PATTERN = r'LocalStore\("([^"]+)"\)' |
14 | | - |
15 | 14 |
|
16 | 15 | class TestObjectStore(StoreTests[ObjectStore, cpu.Buffer]): |
17 | 16 | store_cls = ObjectStore |
18 | 17 | buffer_cls = cpu.Buffer |
19 | 18 |
|
20 | 19 | @pytest.fixture |
21 | | - def store_kwargs(self, tmpdir) -> dict[str, str | bool]: |
22 | | - store = obstore.store.LocalStore(prefix=tmpdir) |
| 20 | + def store_kwargs(self, tmpdir) -> dict[str, Any]: |
| 21 | + store = LocalStore(prefix=tmpdir) |
23 | 22 | return {"store": store, "read_only": False} |
24 | 23 |
|
25 | 24 | @pytest.fixture |
26 | 25 | def store(self, store_kwargs: dict[str, str | bool]) -> ObjectStore: |
27 | 26 | return self.store_cls(**store_kwargs) |
28 | 27 |
|
29 | 28 | async def get(self, store: ObjectStore, key: str) -> Buffer: |
30 | | - # TODO: Use new store.prefix in obstore 0.4.0 |
31 | | - store_path = re.search(PATTERN, str(store)).group(1) |
32 | | - new_local_store = obstore.store.LocalStore(prefix=store_path) |
| 29 | + assert isinstance(store.store, LocalStore) |
| 30 | + new_local_store = LocalStore(prefix=store.store.prefix) |
33 | 31 | return self.buffer_cls.from_bytes(obstore.get(new_local_store, key).bytes()) |
34 | 32 |
|
35 | 33 | async def set(self, store: ObjectStore, key: str, value: Buffer) -> None: |
36 | | - # TODO: Use new store.prefix in obstore 0.4.0 |
37 | | - store_path = re.search(PATTERN, str(store)).group(1) |
38 | | - new_local_store = obstore.store.LocalStore(prefix=store_path) |
| 34 | + assert isinstance(store.store, LocalStore) |
| 35 | + new_local_store = LocalStore(prefix=store.store.prefix) |
39 | 36 | obstore.put(new_local_store, key, value.to_bytes()) |
40 | 37 |
|
41 | 38 | def test_store_repr(self, store: ObjectStore) -> None: |
|
0 commit comments