Skip to content

Commit

Permalink
Add test for fsspec's list behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
moradology committed Jan 30, 2025
1 parent 90812f5 commit d0134ce
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tests/test_store/test_fsspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,45 @@ async def test_empty_nonexistent_path(self, store_kwargs) -> None:
assert await store.is_empty("")


async def test_list_empty_path() -> None:
"""
Verify that list and list_prefix work correctly when path is an empty string,
i.e. no unwanted replacement of separators occurs.
"""
from fsspec.implementations.asyn_wrapper import AsyncFileSystemWrapper

fs, _ = fsspec.url_to_fs("memory://store_root", asynchronous=True)
store_kwargs = {"path": "", "fs": AsyncFileSystemWrapper(fs)}

store = await FsspecStore.open(**store_kwargs)

data = cpu.Buffer.from_bytes(b"")
store_dict = {
"foo/bar/zarr.json": data,
"foo/bar/c/1": data,
"foo/baz/c/0": data,
}
await store._set_many(store_dict.items())

# Test list()
observed_list = await _collect_aiterator(store.list())
observed_list_sorted = sorted(observed_list)
expected_list_sorted = sorted(store_dict.keys())
assert observed_list_sorted == expected_list_sorted

# Test list_prefix() with an empty prefix
observed_prefix_empty = await _collect_aiterator(store.list_prefix(""))
observed_prefix_empty_sorted = sorted(observed_prefix_empty)
expected_prefix_empty_sorted = sorted(store_dict.keys())
assert observed_prefix_empty_sorted == expected_prefix_empty_sorted

# Test list_prefix() with a non-empty prefix
observed_prefix = await _collect_aiterator(store.list_prefix("foo/bar/"))
observed_prefix_sorted = sorted(observed_prefix)
expected_prefix_sorted = sorted(k for k in store_dict if k.startswith("foo/bar/"))
assert observed_prefix_sorted == expected_prefix_sorted


@pytest.mark.skipif(
parse_version(fsspec.__version__) < parse_version("2024.12.0"),
reason="No AsyncFileSystemWrapper",
Expand Down

0 comments on commit d0134ce

Please sign in to comment.