Skip to content

Commit 08dc4f9

Browse files
committed
Adds tests for FsspecStore.delete_dir
1 parent bf78caf commit 08dc4f9

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

tests/test_store/test_fsspec.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,20 @@ async def test_empty_nonexistent_path(self, store_kwargs) -> None:
217217
store = await self.store_cls.open(**store_kwargs)
218218
assert await store.is_empty("")
219219

220+
async def test_delete_dir_unsupported_deletes(self, store: FsspecStore) -> None:
221+
store.supports_deletes = False
222+
with pytest.raises(
223+
NotImplementedError, match=".*only available for stores that support deletes."
224+
):
225+
await store.delete_dir("test_prefix")
226+
227+
async def test_delete_dir_unsupported_listing(self, store: FsspecStore) -> None:
228+
store.supports_listing = False
229+
with pytest.raises(
230+
NotImplementedError, match=".*only available for stores that support directory listing."
231+
):
232+
await store.delete_dir("test_prefix")
233+
220234

221235
@pytest.mark.skipif(
222236
parse_version(fsspec.__version__) < parse_version("2024.12.0"),
@@ -244,3 +258,27 @@ def test_no_wrap_async_filesystem():
244258

245259
assert not isinstance(store.fs, AsyncFileSystemWrapper)
246260
assert store.fs.async_impl
261+
262+
263+
@pytest.mark.skipif(
264+
parse_version(fsspec.__version__) < parse_version("2024.12.0"),
265+
reason="No AsyncFileSystemWrapper",
266+
)
267+
async def test_delete_dir_wrapped_filesystem(tmpdir) -> None:
268+
"""The local fs is not async so we should expect it to be wrapped automatically"""
269+
from fsspec.implementations.asyn_wrapper import AsyncFileSystemWrapper
270+
271+
store = FsspecStore.from_url(tmpdir / "test/path", storage_options={"auto_mkdir": True})
272+
273+
assert isinstance(store.fs, AsyncFileSystemWrapper)
274+
assert store.fs.async_impl
275+
276+
await store.set("zarr.json", cpu.Buffer.from_bytes(b"root"))
277+
await store.set("foo-bar/zarr.json", cpu.Buffer.from_bytes(b"root"))
278+
await store.set("foo/zarr.json", cpu.Buffer.from_bytes(b"bar"))
279+
await store.set("foo/c/0", cpu.Buffer.from_bytes(b"chunk"))
280+
await store.delete_dir("foo")
281+
assert await store.exists("zarr.json")
282+
assert await store.exists("foo-bar/zarr.json")
283+
assert not await store.exists("foo/zarr.json")
284+
assert not await store.exists("foo/c/0")

0 commit comments

Comments
 (0)