Skip to content
Merged
Prev Previous commit
Next Next commit
Added check for invalid.
  • Loading branch information
TomAugspurger committed Sep 19, 2024
commit c8535af7c989693df705300d7c3008eb609223fa
7 changes: 7 additions & 0 deletions src/zarr/store/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ async def make_store_path(
) -> StorePath:
from zarr.store.remote import RemoteStore # circular import

used_storage_options = False

if isinstance(store_like, StorePath):
if mode is not None:
assert AccessMode.from_literal(mode) == store_like.store.mode
Expand All @@ -103,6 +105,7 @@ async def make_store_path(
storage_options = storage_options or {}

if _is_fsspec_uri(store_like):
used_storage_options = True
result = StorePath(
RemoteStore.from_url(store_like, storage_options=storage_options, mode=mode or "r")
)
Expand All @@ -115,6 +118,10 @@ async def make_store_path(
else:
raise TypeError

if storage_options and not used_storage_options:
msg = "'storage_options' was provided but unused. 'storage_options' is only used for fsspec filesystem stores."
raise TypeError(msg)

return result


Expand Down
19 changes: 18 additions & 1 deletion tests/v3/test_store/test_core.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import tempfile
from pathlib import Path

import pytest

from zarr.store.common import make_store_path
from zarr.store.common import StoreLike, StorePath, make_store_path
from zarr.store.local import LocalStore
from zarr.store.memory import MemoryStore
from zarr.store.remote import RemoteStore
Expand Down Expand Up @@ -43,3 +44,19 @@ async def test_make_store_path_fsspec(monkeypatch) -> None:
monkeypatch.setattr(fsspec.implementations.memory.MemoryFileSystem, "async_impl", True)
store_path = await make_store_path("memory://")
assert isinstance(store_path.store, RemoteStore)


@pytest.mark.parametrize(
"store_like",
[
None,
str(tempfile.TemporaryDirectory()),
Path(tempfile.TemporaryDirectory().name),
StorePath(store=MemoryStore(store_dict={}, mode="w"), path="/"),
MemoryStore(store_dict={}, mode="w"),
{},
],
)
async def test_make_store_path_storage_options_raises(store_like: StoreLike) -> None:
with pytest.raises(TypeError, match="storage_options"):
await make_store_path(store_like, storage_options={"foo": "bar"}, mode="w")