Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle Path in make_store_path #1992

Merged
merged 3 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/zarr/store/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ def make_store_path(store_like: StoreLike | None, *, mode: OpenMode | None = Non
if mode is None:
mode = "w" # exception to the default mode = 'r'
return StorePath(MemoryStore(mode=mode))
elif isinstance(store_like, Path):
return StorePath(LocalStore(store_like, mode=mode or "r"))
elif isinstance(store_like, str):
return StorePath(LocalStore(Path(store_like), mode=mode or "r"))
raise TypeError
36 changes: 36 additions & 0 deletions tests/v3/test_store/test_core.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from pathlib import Path

import pytest

from zarr.store.core import make_store_path
from zarr.store.local import LocalStore
from zarr.store.memory import MemoryStore


def test_make_store_path(tmpdir) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in a later PR we can parametrize these tests

# None
store_path = make_store_path(None)
assert isinstance(store_path.store, MemoryStore)

# str
store_path = make_store_path(str(tmpdir))
assert isinstance(store_path.store, LocalStore)
assert Path(store_path.store.root) == Path(tmpdir)

# Path
store_path = make_store_path(Path(tmpdir))
assert isinstance(store_path.store, LocalStore)
assert Path(store_path.store.root) == Path(tmpdir)

# Store
store_path = make_store_path(store_path.store)
assert isinstance(store_path.store, LocalStore)
assert Path(store_path.store.root) == Path(tmpdir)

# StorePath
store_path = make_store_path(store_path)
assert isinstance(store_path.store, LocalStore)
assert Path(store_path.store.root) == Path(tmpdir)

with pytest.raises(TypeError):
make_store_path(1)