Skip to content

Commit ffdfed1

Browse files
authored
dirfs: consistency of details returned by the “ls” and “info” methods. (#1798)
1 parent 56054c0 commit ffdfed1

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

fsspec/implementations/dirfs.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,16 @@ def exists(self, path):
231231
return self.fs.exists(self._join(path))
232232

233233
async def _info(self, path, **kwargs):
234-
return await self.fs._info(self._join(path), **kwargs)
234+
info = await self.fs._info(self._join(path), **kwargs)
235+
info = info.copy()
236+
info["name"] = self._relpath(info["name"])
237+
return info
235238

236239
def info(self, path, **kwargs):
237-
return self.fs.info(self._join(path), **kwargs)
240+
info = self.fs.info(self._join(path), **kwargs)
241+
info = info.copy()
242+
info["name"] = self._relpath(info["name"])
243+
return info
238244

239245
async def _ls(self, path, detail=True, **kwargs):
240246
ret = (await self.fs._ls(self._join(path), detail=detail, **kwargs)).copy()

fsspec/implementations/tests/test_dirfs.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -327,12 +327,14 @@ def test_exists(dirfs):
327327

328328
@pytest.mark.asyncio
329329
async def test_async_info(adirfs):
330-
assert await adirfs._info("file", **KWARGS) == adirfs.fs._info.return_value
330+
adirfs.fs._info.return_value = {"name": f"{PATH}/file", "foo": "bar"}
331+
assert await adirfs._info("file", **KWARGS) == {"name": "file", "foo": "bar"}
331332
adirfs.fs._info.assert_called_once_with(f"{PATH}/file", **KWARGS)
332333

333334

334335
def test_info(dirfs):
335-
assert dirfs.info("file", **KWARGS) == dirfs.fs.info.return_value
336+
dirfs.fs.info.return_value = {"name": f"{PATH}/file", "foo": "bar"}
337+
assert dirfs.info("file", **KWARGS) == {"name": "file", "foo": "bar"}
336338
dirfs.fs.info.assert_called_once_with(f"{PATH}/file", **KWARGS)
337339

338340

0 commit comments

Comments
 (0)