Skip to content

Commit 07bb607

Browse files
committed
Improve code coverage
1 parent 0b1e31b commit 07bb607

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/zarr/storage/_common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ async def open(cls, store: Store, path: str, mode: AccessModeLiteral | None = No
120120
except NotImplementedError as e:
121121
raise ValueError(
122122
"Store is not read-only but mode is 'r'. Unable to create a read-only copy of the store. "
123-
"Please use a read-only store or a storage class that implements .with_read_only()"
123+
"Please use a read-only store or a storage class that implements .with_read_only()."
124124
) from e
125125
self = await cls._create_open_instance(read_only_store, path)
126126
else:

tests/test_store/test_core.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import zarr
88
from zarr import Group
99
from zarr.core.common import AccessModeLiteral, ZarrFormat
10-
from zarr.storage import FsspecStore, LocalStore, MemoryStore, StoreLike, StorePath
10+
from zarr.storage import FsspecStore, LocalStore, MemoryStore, StoreLike, StorePath, ZipStore
1111
from zarr.storage._common import contains_array, contains_group, make_store_path
1212
from zarr.storage._utils import (
1313
_join_paths,
@@ -263,7 +263,19 @@ def test_relativize_path_invalid() -> None:
263263
_relativize_path(path="a/b/c", prefix="b")
264264

265265

266-
def test_different_open_mode() -> None:
266+
def test_different_open_mode(tmp_path: LEGACY_PATH) -> None:
267+
# Test with a store that implements .with_read_only()
267268
store = MemoryStore()
268269
zarr.create((100,), store=store, zarr_format=2, path="a")
269-
zarr.open_array(store=store, path="a", zarr_format=2, mode="r")
270+
arr = zarr.open_array(store=store, path="a", zarr_format=2, mode="r")
271+
assert arr.store.read_only
272+
273+
# Test with a store that doesn't implement .with_read_only()
274+
zarr_path = tmp_path / "foo.zarr"
275+
store = ZipStore(zarr_path, mode="w")
276+
zarr.create((100,), store=store, zarr_format=2, path="a")
277+
with pytest.raises(
278+
ValueError,
279+
match="Store is not read-only but mode is 'r'. Unable to create a read-only copy of the store. Please use a read-only store or a storage class that implements .with_read_only().",
280+
):
281+
zarr.open_array(store=store, path="a", zarr_format=2, mode="r")

0 commit comments

Comments
 (0)