Skip to content

Commit

Permalink
Wire up Zarr stateful tests (#437)
Browse files Browse the repository at this point in the history
  • Loading branch information
dcherian authored Dec 10, 2024
1 parent 05d61b9 commit 22154b6
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions icechunk-python/tests/test_zarr/test_stateful.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
from typing import Any

import hypothesis.strategies as st
import numpy as np
import pytest
from hypothesis import assume
from hypothesis.stateful import (
Settings,
rule,
run_state_machine_as_test,
)

from icechunk import IcechunkStore, StorageConfig
from zarr.testing.stateful import ZarrHierarchyStateMachine, ZarrStoreStateMachine
from zarr.testing.strategies import (
node_names,
np_array_and_chunks,
numpy_arrays,
)


class ModifiedZarrHierarchyStateMachine(ZarrHierarchyStateMachine):
@rule(
data=st.data(),
name=node_names,
array_and_chunks=np_array_and_chunks(
arrays=numpy_arrays(zarr_formats=st.just(3))
),
)
def add_array(
self,
data: st.DataObject,
name: str,
array_and_chunks: tuple[np.ndarray[Any, Any], tuple[int, ...]],
) -> None:
array, _ = array_and_chunks
# TODO: support size-0 arrays GH392
assume(array.size > 0)
# TODO: fix complex fill values GH391
assume(not np.iscomplexobj(array))
super().add_array(data, name, array_and_chunks)


def test_zarr_hierarchy():
store = IcechunkStore.create(StorageConfig.memory())

def mk_test_instance_sync() -> ModifiedZarrHierarchyStateMachine:
return ModifiedZarrHierarchyStateMachine(store)

run_state_machine_as_test(
mk_test_instance_sync, settings=Settings(report_multiple_bugs=False)
)


def test_zarr_store():
pytest.skip("icechunk is more strict about keys")
store = IcechunkStore.create(StorageConfig.memory())

def mk_test_instance_sync() -> ZarrHierarchyStateMachine:
return ZarrStoreStateMachine(store)

run_state_machine_as_test(
mk_test_instance_sync, settings=Settings(report_multiple_bugs=False)
)

0 comments on commit 22154b6

Please sign in to comment.