Skip to content

Commit

Permalink
Ensure paths created (#2337)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAugspurger authored Oct 11, 2024
1 parent 42ab847 commit 979b6f2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/zarr/storage/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ def __init__(self, root: Path | str, *, mode: AccessModeLiteral = "r") -> None:
assert isinstance(root, Path)
self.root = root

async def _open(self) -> None:
if not self.mode.readonly:
self.root.mkdir(parents=True, exist_ok=True)
return await super()._open()

async def clear(self) -> None:
self._check_writable()
shutil.rmtree(self.root)
Expand Down
13 changes: 13 additions & 0 deletions tests/v3/test_store/test_local.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
from __future__ import annotations

from typing import TYPE_CHECKING

import pytest

import zarr
from zarr.core.buffer import Buffer, cpu
from zarr.storage.local import LocalStore
from zarr.testing.store import StoreTests

if TYPE_CHECKING:
import pathlib


class TestLocalStore(StoreTests[LocalStore, cpu.Buffer]):
store_cls = LocalStore
Expand Down Expand Up @@ -40,3 +46,10 @@ async def test_empty_with_empty_subdir(self, store: LocalStore) -> None:
assert await store.empty()
(store.root / "foo/bar").mkdir(parents=True)
assert await store.empty()

def test_creates_new_directory(self, tmp_path: pathlib.Path):
target = tmp_path.joinpath("a", "b", "c")
assert not target.exists()

store = self.store_cls(root=target, mode="w")
zarr.group(store=store)

0 comments on commit 979b6f2

Please sign in to comment.