import os
import icechunk
import pytest
import zarr
@pytest.fixture(scope="function")
async def tmp_store(tmpdir):
store_path = f"{tmpdir}"
store = await icechunk.IcechunkStore.open(
storage=icechunk.StorageConfig.filesystem(store_path),
mode="a",
config=icechunk.StoreConfig(inline_chunk_threshold_bytes=5),
)
yield store, store_path
store.close()
async def test_no_inline_chunks(tmp_store):
store = tmp_store[0]
store_path = tmp_store[1]
array = zarr.open_array(
store=store,
mode="a",
shape=(10),
dtype="int64",
zarr_format=3,
chunk_shape=(1),
fill_value=-1,
)
array[:] = 42
assert os.path.isdir(f"{store_path}/chunks")
assert len(os.listdir(f"{store_path}/chunks")) == 10
async def test_inline_chunks(tmp_store):
store = tmp_store[0]
store_path = tmp_store[1]
inline_array = zarr.open_array(
store=store,
mode="a",
path="inline",
shape=(10),
dtype="int32",
zarr_format=3,
chunk_shape=(1),
fill_value=-1,
)
inline_array[:] = 9
assert not os.path.isdir(f"{store_path}/chunks")
written_array = zarr.open_array(
store=store,
mode="a",
path="not_inline",
shape=(10),
dtype="int64",
zarr_format=3,
chunk_shape=(1),
fill_value=-1,
)
written_array[:] = 3
assert os.path.isdir(f"{store_path}/chunks")
assert len(os.listdir(f"/{store_path}/chunks")) == 10