From 50c2322d7d7140484c284dbd84b09bb987851191 Mon Sep 17 00:00:00 2001 From: yanghua Date: Thu, 26 Sep 2024 20:08:19 +0800 Subject: [PATCH] API: ls support last_modified property --- tosfs/core.py | 1 + tosfs/tests/test_tosfs.py | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/tosfs/core.py b/tosfs/core.py index 947626d..cd33f26 100644 --- a/tosfs/core.py +++ b/tosfs/core.py @@ -2140,6 +2140,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) diff --git a/tosfs/tests/test_tosfs.py b/tosfs/tests/test_tosfs.py index 7fb9bbe..0bce6f8 100644 --- a/tosfs/tests/test_tosfs.py +++ b/tosfs/tests/test_tosfs.py @@ -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) == [] @@ -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")