Skip to content

Commit 542da8e

Browse files
committed
fixups
1 parent 10f0d97 commit 542da8e

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

src/zarr/api/asynchronous.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,13 @@
6565
]
6666

6767

68+
_READ_MODES: tuple[AccessModeLiteral, ...] = ("r", "r+", "a")
69+
_CREATE_MODES: tuple[AccessModeLiteral, ...] = ("a", "w", "w-")
70+
_OVERWRITE_MODES: tuple[AccessModeLiteral, ...] = ("a", "r+", "w")
71+
72+
6873
def _infer_exists_ok(mode: AccessModeLiteral) -> bool:
69-
return mode in ("a", "r+", "w")
74+
return mode in _OVERWRITE_MODES
7075

7176

7277
def _get_shape_chunks(a: ArrayLike | Any) -> tuple[ChunkCoords | None, ChunkCoords | None]:
@@ -708,24 +713,23 @@ async def open_group(
708713
if chunk_store is not None:
709714
warnings.warn("chunk_store is not yet implemented", RuntimeWarning, stacklevel=2)
710715

711-
exists_ok = _infer_exists_ok(mode)
712716
store_path = await make_store_path(store, mode=mode, storage_options=storage_options, path=path)
713717

714718
if attributes is None:
715719
attributes = {}
716720

717721
try:
718-
if mode in {"r", "r+", "a"}:
722+
if mode in _READ_MODES:
719723
return await AsyncGroup.open(
720724
store_path, zarr_format=zarr_format, use_consolidated=use_consolidated
721725
)
722726
except (KeyError, FileNotFoundError):
723727
pass
724-
if mode in {"a", "w", "w-"}:
728+
if mode in _CREATE_MODES:
725729
return await AsyncGroup.from_store(
726730
store_path,
727731
zarr_format=zarr_format or _default_zarr_version(),
728-
exists_ok=exists_ok,
732+
exists_ok=_infer_exists_ok(mode),
729733
attributes=attributes,
730734
)
731735
raise FileNotFoundError(f"Unable to find group: {store_path}")

src/zarr/testing/strategies.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ def arrays(
144144
attributes=attributes,
145145
# compressor=compressor, # FIXME
146146
fill_value=fill_value,
147-
# exists_ok=True, # TODO: shouldn't need this!
148147
)
149148

150149
assert isinstance(a, Array)

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ async def remote_store(url: str) -> RemoteStore:
6262

6363
@pytest.fixture
6464
async def memory_store() -> MemoryStore:
65-
return await MemoryStore.open(readonly=False)
65+
return await MemoryStore.open()
6666

6767

6868
@pytest.fixture

tests/test_store/test_zip.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ async def set(self, store: ZipStore, key: str, value: Buffer) -> None:
3838
def test_store_readonly(self, store: ZipStore, store_kwargs: dict[str, Any]) -> None:
3939
assert not store.readonly
4040

41-
async def test_not_writable_store_raises(self, store_kwargs: dict[str, Any]) -> None:
41+
async def test_readonly_store_raises(self, store_kwargs: dict[str, Any]) -> None:
4242
# we need to create the zipfile in write mode before switching to read mode
4343
store = await self.store_cls.open(**store_kwargs)
4444
store.close()

0 commit comments

Comments
 (0)