From 5226daaff7978f59754bafc9759fc2b6805bd580 Mon Sep 17 00:00:00 2001 From: vinoyang Date: Thu, 26 Sep 2024 20:55:51 +0800 Subject: [PATCH] API: ls support last_modified property (#149) * API: ls support last_modified property * API: ls support last_modified property --- tosfs/core.py | 1 + tosfs/tests/test_fsspec.py | 4 ++-- tosfs/tests/test_tosfs.py | 12 +++++++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/tosfs/core.py b/tosfs/core.py index 477f774..dba3cab 100644 --- a/tosfs/core.py +++ b/tosfs/core.py @@ -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) diff --git a/tosfs/tests/test_fsspec.py b/tosfs/tests/test_fsspec.py index dfa43d6..b9a55b1 100644 --- a/tosfs/tests/test_fsspec.py +++ b/tosfs/tests/test_fsspec.py @@ -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" 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")