test_domain_substitution.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. # -*- coding: UTF-8 -*-
  2. # Copyright (c) 2019 The ungoogled-chromium Authors. All rights reserved.
  3. # Use of this source code is governed by a BSD-style license that can be
  4. # found in the LICENSE file.
  5. import os
  6. import tempfile
  7. from pathlib import Path
  8. from .. import domain_substitution
  9. def test_update_timestamp():
  10. with tempfile.TemporaryDirectory() as tmpdirname:
  11. path = Path(tmpdirname, 'tmp_update_timestamp')
  12. path.touch()
  13. orig_stats: os.stat_result = path.stat()
  14. # Add delta to timestamp
  15. with domain_substitution._update_timestamp(path, set_new=True):
  16. with path.open('w') as fileobj:
  17. fileobj.write('foo')
  18. new_stats: os.stat_result = path.stat()
  19. assert orig_stats.st_atime_ns != new_stats.st_atime_ns
  20. assert orig_stats.st_mtime_ns != new_stats.st_mtime_ns
  21. # Remove delta from timestamp
  22. with domain_substitution._update_timestamp(path, set_new=False):
  23. with path.open('w') as fileobj:
  24. fileobj.write('bar')
  25. new_stats: os.stat_result = path.stat()
  26. assert orig_stats.st_atime_ns == new_stats.st_atime_ns
  27. assert orig_stats.st_mtime_ns == new_stats.st_mtime_ns