Skip to content

Commit 1926a32

Browse files
committed
add test to ensure that write_empty_chunks can be set via the global config
1 parent 0ae1a23 commit 1926a32

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

tests/test_array.py

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from zarr.core.buffer import default_buffer_prototype
1717
from zarr.core.buffer.cpu import NDBuffer
1818
from zarr.core.common import JSON, MemoryOrder, ZarrFormat
19-
from zarr.core.config import config
2019
from zarr.core.group import AsyncGroup
2120
from zarr.core.indexing import ceildiv
2221
from zarr.core.metadata.v3 import DataType
@@ -759,10 +758,21 @@ def test_array_create_order(
759758
raise AssertionError
760759

761760

761+
@pytest.mark.parametrize("write_empty_chunks", [True, False])
762+
def test_write_empty_chunks_config(write_empty_chunks: bool) -> None:
763+
"""
764+
Test that the value of write_empty_chunks is sensitive to the global config when not set
765+
explicitly
766+
"""
767+
with zarr.config.set({"array.write_empty_chunks": write_empty_chunks}):
768+
arr = Array.create({}, shape=(2, 2), dtype="i4")
769+
assert arr._async_array.config.write_empty_chunks == write_empty_chunks
770+
771+
762772
@pytest.mark.parametrize("store", ["memory"], indirect=True)
763773
@pytest.mark.parametrize("write_empty_chunks", [True, False])
764774
@pytest.mark.parametrize("fill_value", [0, 5])
765-
def test_write_empty_chunks(
775+
def test_write_empty_chunks_behavior(
766776
zarr_format: ZarrFormat, store: MemoryStore, write_empty_chunks: bool, fill_value: int
767777
) -> None:
768778
"""
@@ -774,15 +784,18 @@ def test_write_empty_chunks(
774784
those chunks not being present in the store. In particular, they should be deleted if they were
775785
already present.
776786
"""
777-
with config.set({"array.write_empty_chunks": write_empty_chunks}):
778-
arr = Array.create(
779-
store=store,
780-
shape=(2,),
781-
zarr_format=zarr_format,
782-
dtype="i4",
783-
fill_value=fill_value,
784-
chunk_shape=(1,),
785-
)
787+
788+
arr = Array.create(
789+
store=store,
790+
shape=(2,),
791+
zarr_format=zarr_format,
792+
dtype="i4",
793+
fill_value=fill_value,
794+
chunk_shape=(1,),
795+
write_empty_chunks=write_empty_chunks,
796+
)
797+
798+
assert arr._async_array.config.write_empty_chunks == write_empty_chunks
786799

787800
# initialize the store with some non-fill value chunks
788801
arr[:] = fill_value + 1

0 commit comments

Comments
 (0)