Skip to content

Commit 7e75042

Browse files
committed
fix(storage): accept pytest tmp_dir as valid store_like paths
1 parent 38a2417 commit 7e75042

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/zarr/storage/_common.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,8 @@ async def make_store_path(
297297
store = await MemoryStore.open(read_only=_read_only)
298298
elif isinstance(store_like, Path):
299299
store = await LocalStore.open(root=store_like, read_only=_read_only)
300+
elif _is_pytest_legacy_path(store_like):
301+
store = await LocalStore.open(root=Path(str(store_like)), read_only=_read_only)
300302
elif isinstance(store_like, str):
301303
storage_options = storage_options or {}
302304

@@ -340,6 +342,15 @@ def _is_fsspec_uri(uri: str) -> bool:
340342
return "://" in uri or ("::" in uri and "local://" not in uri)
341343

342344

345+
def _is_pytest_legacy_path(path: Any) -> bool:
346+
# https://docs.pytest.org/en/stable/how-to/tmp_path.html#tmp-path
347+
try:
348+
from _pytest.compat import LEGACY_PATH
349+
except ImportError:
350+
return False
351+
return isinstance(path, LEGACY_PATH)
352+
353+
343354
async def ensure_no_existing_node(store_path: StorePath, zarr_format: ZarrFormat) -> None:
344355
"""
345356
Check if a store_path is safe for array / group creation.

tests/test_store/test_core.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,22 @@ async def test_make_store_path_none(path: str) -> None:
6464

6565

6666
@pytest.mark.parametrize("path", [None, "", "bar"])
67-
@pytest.mark.parametrize("store_type", [str, Path])
67+
@pytest.mark.parametrize("store_type", [str, Path, LEGACY_PATH])
6868
@pytest.mark.parametrize("mode", ["r", "w"])
6969
async def test_make_store_path_local(
7070
tmpdir: LEGACY_PATH,
71-
store_type: type[str] | type[Path] | type[LocalStore],
71+
store_type: type[str] | type[Path] | type[LEGACY_PATH],
7272
path: str,
7373
mode: AccessModeLiteral,
7474
) -> None:
7575
"""
7676
Test the various ways of invoking make_store_path that create a LocalStore
7777
"""
78-
store_like = store_type(str(tmpdir))
78+
79+
if store_type is LEGACY_PATH:
80+
store_like = tmpdir
81+
else:
82+
store_like = store_type(tmpdir)
7983
store_path = await make_store_path(store_like, path=path, mode=mode)
8084
assert isinstance(store_path.store, LocalStore)
8185
assert Path(store_path.store.root) == Path(tmpdir)

0 commit comments

Comments
 (0)