Skip to content

Ensure that store_dict used for empty dicts #2162

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

Merged
merged 3 commits into from
Sep 9, 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
4 changes: 3 additions & 1 deletion src/zarr/store/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ def __init__(
mode: AccessModeLiteral = "r",
):
super().__init__(mode=mode)
self._store_dict = store_dict or {}
if store_dict is None:
store_dict = {}
self._store_dict = store_dict

async def empty(self) -> bool:
return not self._store_dict
Expand Down
13 changes: 11 additions & 2 deletions tests/v3/test_store/test_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ def set(self, store: MemoryStore, key: str, value: Buffer) -> None:
def get(self, store: MemoryStore, key: str) -> Buffer:
return store._store_dict[key]

@pytest.fixture(scope="function", params=[None, {}])
@pytest.fixture(scope="function", params=[None, True])
def store_kwargs(
self, request: pytest.FixtureRequest
) -> dict[str, str | None | dict[str, Buffer]]:
return {"store_dict": request.param, "mode": "r+"}
kwargs = {"store_dict": None, "mode": "r+"}
if request.param is True:
kwargs["store_dict"] = {}
return kwargs

@pytest.fixture(scope="function")
def store(self, store_kwargs: str | None | dict[str, Buffer]) -> MemoryStore:
Expand Down Expand Up @@ -77,3 +80,9 @@ def test_store_supports_partial_writes(self, store: GpuMemoryStore) -> None:

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


def test_uses_dict():
store_dict = {}
store = MemoryStore(store_dict)
assert store._store_dict is store_dict