Skip to content

Commit

Permalink
API: ls support last_modified property (#149)
Browse files Browse the repository at this point in the history
* API: ls support last_modified property

* API: ls support last_modified property
  • Loading branch information
yanghua authored Sep 26, 2024
1 parent bf6b0f6 commit 5226daa
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions tosfs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2141,6 +2141,7 @@ def _fill_file_info(obj: ListedObject, bucket: str, versions: bool = False) -> d
"size": obj.size,
"name": f"{bucket}/{obj.key}",
"type": "file",
"LastModified": obj.last_modified,
}
if (
isinstance(obj, ListedObjectVersion)
Expand Down
4 changes: 2 additions & 2 deletions tosfs/tests/test_fsspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,8 @@ def test_find(fsspecfs: Any, bucket: str, temporary_workspace: str):
def remove_last_modification_time_ms(data):
if isinstance(data, dict):
for key in data:
if "last_modification_time_ms" in data[key]:
del data[key]["last_modification_time_ms"]
if "LastModified" in data[key]:
del data[key]["LastModified"]
return data

file1_path = f"{bucket}/{temporary_workspace}/file1"
Expand Down
12 changes: 11 additions & 1 deletion tosfs/tests/test_tosfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ def test_ls_dir(tosfs: TosFileSystem, bucket: str, temporary_workspace: str) ->
f"Directory {temporary_workspace} not found in {detailed_list}"
)

assert tosfs.ls(f"{bucket}/{temporary_workspace}", detail=False) == []
tosfs.touch(f"{bucket}/{temporary_workspace}/file")
for item in tosfs.ls(f"{bucket}/{temporary_workspace}", detail=True):
assert item["name"] in [f"{bucket}/{temporary_workspace}/file"]
assert item["LastModified"] is not None

assert tosfs.ls(f"{bucket}/{temporary_workspace}/nonexistent", detail=False) == []


Expand Down Expand Up @@ -123,6 +127,12 @@ def test_info(tosfs: TosFileSystem, bucket: str, temporary_workspace: str) -> No
"size": 0,
"StorageClass": "DIRECTORY",
}
tosfs.touch(f"{bucket}/{temporary_workspace}/file")
file_info = tosfs.info(f"{bucket}/{temporary_workspace}/file")
assert file_info["name"] == f"{bucket}/{temporary_workspace}/file"
assert file_info["type"] == "file"
assert file_info["size"] == 0
assert file_info["LastModified"] is not None

with pytest.raises(FileNotFoundError):
tosfs.info(f"{bucket}/nonexistent")
Expand Down

0 comments on commit 5226daa

Please sign in to comment.