Skip to content

Commit dda7e26

Browse files
committed
tests: read a zipped OME-Zarr through a ZipStore
ZipStore is a zarr Store, so ZarrLocation accepts it without changes. Only the read path is covered: dask writes to a ZipStore corrupt the archive (zarr-developers/zarr-python#3516), so the test zips a directory store.
1 parent 3e50a42 commit dda7e26

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

‎tests/test_io.py‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import zipfile
12
from pathlib import Path
23

34
import numpy as np
45
import pytest
56
import zarr
6-
from zarr.storage import LocalStore, MemoryStore, StorePath
7+
from zarr.storage import LocalStore, MemoryStore, StorePath, ZipStore
78

89
from ome_zarr import OMEZarrImage, OMEZarrMultiscale
910
from ome_zarr.data import create_zarr
@@ -117,3 +118,24 @@ def test_class_writer_on_a_store():
117118
zarr.open_group(store, path="images/img", mode="r")
118119
)
119120
np.testing.assert_array_equal(np.asarray(read_back.images[0].data), IMAGE)
121+
122+
123+
def test_read_from_a_zip(tmp_path):
124+
"""A zipped OME-Zarr reads through ZarrLocation on a ZipStore."""
125+
# Dask writes to a ZipStore corrupt the archive (zarr-python#3516),
126+
# so the test zips a directory store instead of writing to the ZipStore.
127+
directory = tmp_path / "img.zarr"
128+
write_image(IMAGE, zarr.open_group(directory, mode="w"), axes="yx", scaler=None)
129+
archive = tmp_path / "img.zarr.zip"
130+
with zipfile.ZipFile(archive, mode="w") as zf:
131+
for file in directory.rglob("*"):
132+
if file.is_file():
133+
zf.write(file, file.relative_to(directory).as_posix())
134+
135+
store = ZipStore(archive, mode="r")
136+
loc = ZarrLocation(store)
137+
assert loc.exists()
138+
nodes = list(Reader(loc)())
139+
assert nodes, "the reader found no node in the archive"
140+
np.testing.assert_array_equal(np.asarray(nodes[0].data[0]), IMAGE)
141+
store.close()

0 commit comments

Comments
 (0)