#!/usr/bin/env python3 # Copyright 2023 The Chromium Authors # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file.
import os import pathlib import shutil import sys import tempfile import time import unittest
import action_helpers
class ActionHelpersTest(unittest.TestCase): def test_atomic_output(self):
tmp_file = pathlib.Path(tempfile.mktemp())
tmp_file.write_text('test') try: # Test that same contents does not change mtime.
orig_mtime = os.path.getmtime(tmp_file) with action_helpers.atomic_output(str(tmp_file), 'wt') as af:
time.sleep(.01)
af.write('test')
# Test that contents is written. with action_helpers.atomic_output(str(tmp_file), 'wt') as af:
af.write('test2')
self.assertEqual(tmp_file.read_text(), 'test2')
self.assertNotEqual(os.path.getmtime(tmp_file), orig_mtime) finally:
tmp_file.unlink()
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.