diff --git a/src/databricks/labs/blueprint/paths.py b/src/databricks/labs/blueprint/paths.py index 8b9c96e..d990f73 100644 --- a/src/databricks/labs/blueprint/paths.py +++ b/src/databricks/labs/blueprint/paths.py @@ -695,8 +695,8 @@ def _file_info(self) -> FileInfo: def stat(self, *, follow_symlinks=True) -> os.stat_result: seq: list[float] = [-1] * 10 - seq[stat.ST_SIZE] = self._file_info.file_size or -1 # 6 - seq[stat.ST_MTIME] = self._file_info.modification_time or -1 # 8 + seq[stat.ST_SIZE] = float(self._file_info.file_size) / 1000.0 or -1 # 6 + seq[stat.ST_MTIME] = float(self._file_info.modification_time) / 1000.0 or -1 # 8 return os.stat_result(seq) def is_dir(self) -> bool: @@ -852,8 +852,8 @@ def _object_info(self) -> ObjectInfo: def stat(self, *, follow_symlinks=True) -> os.stat_result: seq: list[float] = [-1] * 10 seq[stat.ST_SIZE] = self._object_info.size or -1 # 6 - seq[stat.ST_MTIME] = self._object_info.modified_at or -1 # 8 - seq[stat.ST_CTIME] = self._object_info.created_at or -1 # 9 + seq[stat.ST_MTIME] = float(self._object_info.modified_at) / 1000.0 or -1 # 8 + seq[stat.ST_CTIME] = float(self._object_info.created_at) / 1000.0 or -1 # 9 return os.stat_result(seq) def is_dir(self) -> bool: diff --git a/tests/integration/test_paths.py b/tests/integration/test_paths.py index 4691f17..17edab7 100644 --- a/tests/integration/test_paths.py +++ b/tests/integration/test_paths.py @@ -1,4 +1,5 @@ import codecs +from datetime import datetime from pathlib import Path import pytest @@ -67,6 +68,21 @@ def test_open_text_io(ws, make_random, cls): assert not hello_txt.exists() +@pytest.mark.parametrize("cls", DATABRICKS_PATHLIKE) +def test_stat(ws, make_random, cls): + now = datetime.now().timestamp() + name = make_random() + wsp = cls(ws, f"~/{name}/a/b/c") + with_user = wsp.expanduser() + with_user.mkdir(parents=True) + + hello_txt = with_user / "hello.txt" + hello_txt.write_text("Hello, World!") + if cls is WorkspacePath: # DBFSPath has no st_ctime + assert hello_txt.stat().st_ctime >= now + assert hello_txt.stat().st_mtime >= now + + @pytest.mark.parametrize("cls", DATABRICKS_PATHLIKE) def test_unlink(ws, make_random, cls): name = make_random()