Skip to content

Commit 2d0f6e9

Browse files
committed
add tests for load_array
1 parent 4863811 commit 2d0f6e9

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

tests/test_api.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
)
4040
from zarr.core.buffer import NDArrayLike
4141
from zarr.errors import MetadataValidationError
42-
from zarr.storage import MemoryStore
42+
from zarr.storage import MemoryStore, ZipStore
4343
from zarr.storage._utils import normalize_path
4444
from zarr.testing.utils import gpu_test
4545

@@ -230,7 +230,7 @@ async def test_open_group_unspecified_version(
230230
@pytest.mark.parametrize("n_args", [10, 1, 0])
231231
@pytest.mark.parametrize("n_kwargs", [10, 1, 0])
232232
@pytest.mark.parametrize("path", [None, "some_path"])
233-
def test_save(store: Store, n_args: int, n_kwargs: int, path) -> None:
233+
def test_save(store: Store, n_args: int, n_kwargs: int, path: None | str) -> None:
234234
data = np.arange(10)
235235
args = [np.arange(10) for _ in range(n_args)]
236236
kwargs = {f"arg_{i}": data for i in range(n_kwargs)}
@@ -385,8 +385,8 @@ def test_array_order_warns(order: MemoryOrder | None, zarr_format: ZarrFormat) -
385385
# assert "LazyLoader: " in repr(loader)
386386

387387

388-
def test_load_array(memory_store: Store) -> None:
389-
store = memory_store
388+
def test_load_array(sync_store: Store) -> None:
389+
store = sync_store
390390
foo = np.arange(100)
391391
bar = np.arange(100, 0, -1)
392392
save(store, foo=foo, bar=bar)
@@ -400,6 +400,17 @@ def test_load_array(memory_store: Store) -> None:
400400
else:
401401
assert_array_equal(bar, array)
402402

403+
def test_load_zip(tmp_path: pathlib.Path) -> None:
404+
file = tmp_path / "test.zip"
405+
# Create a zip file with some data
406+
with ZipStore(file, mode="w", read_only=False) as zs:
407+
save(zs, np.arange(100).reshape(10, 10), path="data")
408+
with ZipStore(file, mode="r", read_only=False) as zs:
409+
data = zarr.load(store=zs, path="data") # This works
410+
print(data.shape)
411+
with ZipStore(file, mode="r") as zs:
412+
data = zarr.load(store=zs, path="data") # This does not work
413+
print(data.shape)
403414

404415
def test_tree() -> None:
405416
pytest.importorskip("rich")

0 commit comments

Comments
 (0)