Skip to content

Commit d0134ce

Browse files
committed
Add test for fsspec's list behavior
1 parent 90812f5 commit d0134ce

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

tests/test_store/test_fsspec.py

+39
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,45 @@ async def test_empty_nonexistent_path(self, store_kwargs) -> None:
218218
assert await store.is_empty("")
219219

220220

221+
async def test_list_empty_path() -> None:
222+
"""
223+
Verify that list and list_prefix work correctly when path is an empty string,
224+
i.e. no unwanted replacement of separators occurs.
225+
"""
226+
from fsspec.implementations.asyn_wrapper import AsyncFileSystemWrapper
227+
228+
fs, _ = fsspec.url_to_fs("memory://store_root", asynchronous=True)
229+
store_kwargs = {"path": "", "fs": AsyncFileSystemWrapper(fs)}
230+
231+
store = await FsspecStore.open(**store_kwargs)
232+
233+
data = cpu.Buffer.from_bytes(b"")
234+
store_dict = {
235+
"foo/bar/zarr.json": data,
236+
"foo/bar/c/1": data,
237+
"foo/baz/c/0": data,
238+
}
239+
await store._set_many(store_dict.items())
240+
241+
# Test list()
242+
observed_list = await _collect_aiterator(store.list())
243+
observed_list_sorted = sorted(observed_list)
244+
expected_list_sorted = sorted(store_dict.keys())
245+
assert observed_list_sorted == expected_list_sorted
246+
247+
# Test list_prefix() with an empty prefix
248+
observed_prefix_empty = await _collect_aiterator(store.list_prefix(""))
249+
observed_prefix_empty_sorted = sorted(observed_prefix_empty)
250+
expected_prefix_empty_sorted = sorted(store_dict.keys())
251+
assert observed_prefix_empty_sorted == expected_prefix_empty_sorted
252+
253+
# Test list_prefix() with a non-empty prefix
254+
observed_prefix = await _collect_aiterator(store.list_prefix("foo/bar/"))
255+
observed_prefix_sorted = sorted(observed_prefix)
256+
expected_prefix_sorted = sorted(k for k in store_dict if k.startswith("foo/bar/"))
257+
assert observed_prefix_sorted == expected_prefix_sorted
258+
259+
221260
@pytest.mark.skipif(
222261
parse_version(fsspec.__version__) < parse_version("2024.12.0"),
223262
reason="No AsyncFileSystemWrapper",

0 commit comments

Comments
 (0)