summaryrefslogtreecommitdiff
path: root/tests/internals
diff options
context:
space:
mode:
authorDarius Makovsky <traveltissues@protonmail.com>2020-01-08 16:30:47 +0000
committerJürg Billeter <j@bitron.ch>2020-02-05 16:11:32 +0100
commitc4dafc8477f0787d622164d5c45fd9081af25a00 (patch)
tree797fc7afee13ef4634bf768ea8afdcec1cb7cd38 /tests/internals
parent59b26c9697a23966ae72db7fed0e8af4258e4317 (diff)
downloadbuildstream-c4dafc8477f0787d622164d5c45fd9081af25a00.tar.gz
utils.py: Add file timestamp helpers
Diffstat (limited to 'tests/internals')
-rw-r--r--tests/internals/utils_move_atomic.py23
1 files changed, 22 insertions, 1 deletions
diff --git a/tests/internals/utils_move_atomic.py b/tests/internals/utils_move_atomic.py
index cda020809..dd417cb66 100644
--- a/tests/internals/utils_move_atomic.py
+++ b/tests/internals/utils_move_atomic.py
@@ -3,7 +3,13 @@
import pytest
-from buildstream.utils import move_atomic, DirectoryExistsError
+from buildstream.utils import (
+ move_atomic,
+ DirectoryExistsError,
+ _get_file_mtimestamp,
+ _set_file_mtime,
+ _parse_timestamp,
+)
@pytest.fixture
@@ -89,3 +95,18 @@ def test_move_to_existing_non_empty_dir(src, tmp_path):
with pytest.raises(DirectoryExistsError):
move_atomic(src, dst)
+
+
+def test_move_to_empty_dir_set_mtime(src, tmp_path):
+ dst = tmp_path.joinpath("dst")
+ move_atomic(src, dst)
+ assert dst.joinpath("test").exists()
+ _dst = str(dst)
+ # set the mtime via stamp
+ timestamp1 = "2020-01-08T11:05:50.832123Z"
+ _set_file_mtime(_dst, _parse_timestamp(timestamp1))
+ assert timestamp1 == _get_file_mtimestamp(_dst)
+ # reset the mtime using an offset stamp
+ timestamp2 = "2010-02-12T12:05:50.832123+01:00"
+ _set_file_mtime(_dst, _parse_timestamp(timestamp2))
+ assert _get_file_mtimestamp(_dst) == "2010-02-12T11:05:50.832123Z"