Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
raise if MemoryStore is pickled
  • Loading branch information
jhamman committed Jul 2, 2024
commit 275d6faf66d5a69b3566a5d3706de740f3ec5ded
10 changes: 2 additions & 8 deletions src/zarr/store/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,10 @@ def __eq__(self, other: object) -> bool:
)

def __setstate__(self, state: tuple[MutableMapping[str, Buffer], OpenMode]) -> None:
# warnings.warn(
# f"unpickling {type(self)} may produce unexpected behavior and should only be used for testing and/or debugging"
# )
self._store_dict, self._mode = state
raise NotImplementedError(f"{type(self)} cannot be pickled")

def __getstate__(self) -> tuple[MutableMapping[str, Buffer], OpenMode]:
# warnings.warn(
# f"pickling {type(self)} may produce unexpected behavior and should only be used for testing and/or debugging"
# )
return self._store_dict, self._mode
raise NotImplementedError(f"{type(self)} cannot be pickled")

async def get(
self,
Expand Down
4 changes: 2 additions & 2 deletions tests/v3/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_array_name_properties_with_group(
assert spam.basename == "spam"


@pytest.mark.parametrize("store", ("memory", "local"), indirect=["store"])
@pytest.mark.parametrize("store", ("local",), indirect=["store"])
@pytest.mark.parametrize("zarr_format", (2, 3))
async def test_serizalizable_async_array(
store: LocalStore | MemoryStore, zarr_format: ZarrFormat
Expand All @@ -57,7 +57,7 @@ async def test_serizalizable_async_array(
# TODO: uncomment the parts of this test that will be impacted by the config/prototype changes in flight


@pytest.mark.parametrize("store", ("memory", "local"), indirect=["store"])
@pytest.mark.parametrize("store", ("local",), indirect=["store"])
@pytest.mark.parametrize("zarr_format", (2, 3))
def test_serizalizable_sync_array(store: LocalStore | MemoryStore, zarr_format: ZarrFormat) -> None:
expected = Array.create(
Expand Down
4 changes: 2 additions & 2 deletions tests/v3/test_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ def test_group_name_properties(store: LocalStore | MemoryStore, zarr_format: Zar
assert bar.basename == "bar"


@pytest.mark.parametrize("store", ("memory", "local"), indirect=["store"])
@pytest.mark.parametrize("store", ("local",), indirect=["store"])
@pytest.mark.parametrize("zarr_format", (2, 3))
async def test_serizalizable_async_group(
store: LocalStore | MemoryStore, zarr_format: ZarrFormat
Expand All @@ -407,7 +407,7 @@ async def test_serizalizable_async_group(
assert actual == expected


@pytest.mark.parametrize("store", ("memory", "local"), indirect=["store"])
@pytest.mark.parametrize("store", ("local",), indirect=["store"])
@pytest.mark.parametrize("zarr_format", (2, 3))
def test_serizalizable_sync_group(store: LocalStore | MemoryStore, zarr_format: ZarrFormat) -> None:
expected = Group.create(store=store, attributes={"foo": 999}, zarr_format=zarr_format)
Expand Down
12 changes: 12 additions & 0 deletions tests/v3/test_store/test_memory.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

import pickle

import pytest

from zarr.buffer import Buffer
Expand Down Expand Up @@ -38,3 +40,13 @@ def test_store_supports_partial_writes(self, store: MemoryStore) -> None:

def test_list_prefix(self, store: MemoryStore) -> None:
assert True

def test_serizalizable_store(self, store: MemoryStore) -> None:
with pytest.raises(NotImplementedError):
store.__getstate__()

with pytest.raises(NotImplementedError):
store.__setstate__({})

with pytest.raises(NotImplementedError):
pickle.dumps(store)