|
7 | 7 | import zarr |
8 | 8 | from zarr import Group |
9 | 9 | 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 |
11 | 11 | from zarr.storage._common import contains_array, contains_group, make_store_path |
12 | 12 | from zarr.storage._utils import ( |
13 | 13 | _join_paths, |
@@ -263,7 +263,19 @@ def test_relativize_path_invalid() -> None: |
263 | 263 | _relativize_path(path="a/b/c", prefix="b") |
264 | 264 |
|
265 | 265 |
|
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() |
267 | 268 | store = MemoryStore() |
268 | 269 | 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