|
39 | 39 | ) |
40 | 40 | from zarr.core.buffer import NDArrayLike |
41 | 41 | from zarr.errors import MetadataValidationError |
42 | | -from zarr.storage import MemoryStore |
| 42 | +from zarr.storage import MemoryStore, ZipStore, LocalStore |
43 | 43 | from zarr.storage._utils import normalize_path |
44 | 44 | from zarr.testing.utils import gpu_test |
45 | 45 |
|
@@ -399,6 +399,37 @@ def test_load_array(memory_store: Store) -> None: |
399 | 399 | else: |
400 | 400 | assert_array_equal(bar, array) |
401 | 401 |
|
| 402 | +@pytest.mark.parametrize("path", ["data", None]) |
| 403 | +def test_load_zip(tmp_path: pathlib.Path, path: str | None) -> None: |
| 404 | + file = tmp_path / "test.zip" |
| 405 | + data = np.arange(100).reshape(10, 10) |
| 406 | + |
| 407 | + with ZipStore(file, mode="w", read_only=False) as zs: |
| 408 | + save(zs, data, path=path) |
| 409 | + with ZipStore(file, mode="r", read_only=False) as zs: |
| 410 | + result = zarr.load(store=zs, path=path) |
| 411 | + assert np.array_equal(result, data) |
| 412 | + with ZipStore(file, mode="r") as zs: |
| 413 | + result = zarr.load(store=zs, path=path) |
| 414 | + assert np.array_equal(result, data) |
| 415 | + with ZipStore(file, read_only=True) as zs: |
| 416 | + result = zarr.load(store=zs, path=path) |
| 417 | + assert np.array_equal(result, data) |
| 418 | + |
| 419 | + |
| 420 | +@pytest.mark.parametrize("path", ["data", None]) |
| 421 | +def test_load_local(tmp_path: pathlib.Path, path: str | None) -> None: |
| 422 | + file = tmp_path / "test.zip" |
| 423 | + data = np.arange(100).reshape(10, 10) |
| 424 | + |
| 425 | + with LocalStore(file, read_only=False) as zs: |
| 426 | + save(zs, data, path=path) |
| 427 | + with LocalStore(file, read_only=False) as zs: |
| 428 | + result = zarr.load(store=zs, path=path) |
| 429 | + assert np.array_equal(result, data) |
| 430 | + with LocalStore(file, read_only=True) as zs: |
| 431 | + result = zarr.load(store=zs, path=path) |
| 432 | + assert np.array_equal(result, data) |
402 | 433 |
|
403 | 434 | def test_tree() -> None: |
404 | 435 | pytest.importorskip("rich") |
|
0 commit comments