Skip to content

Commit 5969018

Browse files
committed
test deterministic memory store
1 parent 45146ca commit 5969018

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tests/test_store/test_memory.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
from __future__ import annotations
22

3+
from typing import TYPE_CHECKING
4+
35
import pytest
46

7+
import zarr
58
from zarr.core.buffer import Buffer, cpu, gpu
69
from zarr.storage import GpuMemoryStore, MemoryStore
710
from zarr.testing.store import StoreTests
811
from zarr.testing.utils import gpu_test
912

13+
if TYPE_CHECKING:
14+
from zarr.core.common import ZarrFormat
15+
1016

1117
class TestMemoryStore(StoreTests[MemoryStore, cpu.Buffer]):
1218
store_cls = MemoryStore
@@ -46,6 +52,28 @@ def test_store_supports_partial_writes(self, store: MemoryStore) -> None:
4652
def test_list_prefix(self, store: MemoryStore) -> None:
4753
assert True
4854

55+
@pytest.mark.parametrize("dtype", ["uint8", "float32", "str"])
56+
@pytest.mark.parametrize("zarr_format", [2, 3])
57+
async def test_deterministic_size(
58+
self, store: MemoryStore, dtype, zarr_format: ZarrFormat
59+
) -> None:
60+
def padding_size() -> int:
61+
a = zarr.empty(
62+
store=store,
63+
shape=(3,),
64+
chunks=(1000,),
65+
dtype=dtype,
66+
zarr_format=zarr_format,
67+
overwrite=True,
68+
)
69+
a[...] = b"1" if dtype == "str" else 1
70+
key = "0" if zarr_format == 2 else "c/0"
71+
return len(store._store_dict[key])
72+
73+
l1 = padding_size()
74+
l2 = padding_size()
75+
assert l1 == l2
76+
4977

5078
@gpu_test
5179
class TestGpuMemoryStore(StoreTests[GpuMemoryStore, gpu.Buffer]):

0 commit comments

Comments
 (0)