Skip to content

Commit

Permalink
Add delete_dir step to stateful tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dcherian committed Dec 31, 2024
1 parent a42ca30 commit 91d1267
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion icechunk-python/tests/test_zarr/test_stateful.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def chunk_paths(
st.tuples(*tuple(st.integers(min_value=0, max_value=b - 1) for b in numblocks))
)
subset_slicer = (
slice(draw(st.integers(min_value=1, max_value=ndim))) if subset else slice(None)
slice(draw(st.integers(min_value=0, max_value=ndim))) if subset else slice(None)
)
return "/".join(map(str, blockidx[subset_slicer]))

Expand Down Expand Up @@ -154,6 +154,42 @@ def delete_chunk(self, data) -> None:
self._sync(self.model.delete(path))
self._sync(self.store.delete(path))

@precondition(lambda self: bool(self.all_arrays) or bool(self.all_groups))
@rule(data=st.data())
def delete_dir(self, data) -> None:
array_or_group = data.draw(
st.one_of(
st.sampled_from(sorted(self.all_groups))
if self.all_groups
else st.nothing(),
st.sampled_from(sorted(self.all_arrays))
if self.all_arrays
else st.nothing(),
)
)
if data.draw(st.booleans()) and array_or_group in self.all_arrays:
arr = zarr.open_array(path=array_or_group, store=self.model)
path = data.draw(
st.one_of(
st.sampled_from([array_or_group]),
chunk_paths(ndim=arr.ndim, numblocks=arr.cdata_shape).map(
lambda x: f"{array_or_group}/c/"
),
)
)
else:
path = array_or_group
note(f"delete_dir with {path=!r}")
self._sync(self.model.delete_dir(path))
self._sync(self.store.delete_dir(path))

matches = set()
for node in self.all_groups | self.all_arrays:
if node.startswith(path):
matches.add(node)
self.all_groups = self.all_groups - matches
self.all_arrays = self.all_arrays - matches

@invariant()
def check_list_prefix_from_root(self) -> None:
model_list = self._sync_iter(self.model.list_prefix(""))
Expand Down

0 comments on commit 91d1267

Please sign in to comment.