|  | 
| 1 | 1 | from __future__ import annotations | 
| 2 | 2 | 
 | 
|  | 3 | +from typing import TYPE_CHECKING | 
|  | 4 | + | 
| 3 | 5 | import pytest | 
| 4 | 6 | 
 | 
|  | 7 | +import zarr | 
| 5 | 8 | from zarr.core.buffer import Buffer, cpu, gpu | 
| 6 | 9 | from zarr.storage import GpuMemoryStore, MemoryStore | 
| 7 | 10 | from zarr.testing.store import StoreTests | 
| 8 | 11 | from zarr.testing.utils import gpu_test | 
| 9 | 12 | 
 | 
|  | 13 | +if TYPE_CHECKING: | 
|  | 14 | +    from zarr.core.common import ZarrFormat | 
|  | 15 | + | 
| 10 | 16 | 
 | 
| 11 | 17 | class TestMemoryStore(StoreTests[MemoryStore, cpu.Buffer]): | 
| 12 | 18 |     store_cls = MemoryStore | 
| @@ -46,6 +52,28 @@ def test_store_supports_partial_writes(self, store: MemoryStore) -> None: | 
| 46 | 52 |     def test_list_prefix(self, store: MemoryStore) -> None: | 
| 47 | 53 |         assert True | 
| 48 | 54 | 
 | 
|  | 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 | + | 
| 49 | 77 | 
 | 
| 50 | 78 | @gpu_test | 
| 51 | 79 | class TestGpuMemoryStore(StoreTests[GpuMemoryStore, gpu.Buffer]): | 
|  | 
0 commit comments