# Path: oslo_utils/fileutils.py
# _DEFAULT_MODE = stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO
# def ensure_tree(path, mode=_DEFAULT_MODE):
# def delete_if_exists(path, remove=os.unlink):
# def remove_path_on_error(path, remove=delete_if_exists):
# def write_to_tempfile(content, path=None, suffix='', prefix='tmp'):
# def compute_file_checksum(path, read_chunksize=65536, algorithm='sha256'):
# def last_bytes(path, num):
# def is_json(file_path):
# def is_yaml(file_path):


import errno
import hashlib
import json
import os
import shutil
import stat
import tempfile
import time
import uuid
import yaml
from unittest import mock
from oslotest import base as test_base
from oslo_utils import fileutils
        path = fileutils.write_to_tempfile(self.content)
        self.assertTrue(os.path.exists(path))
        self.check_file_content(self.content, path)

        expected_checksum = hashlib.sha256()
        expected_checksum.update(self.content)

        with mock.patch.object(time, "sleep") as sleep_mock:
            actual_checksum = fileutils.compute_file_checksum(
                path, read_chunksize=4)

        sleep_mock.assert_has_calls([mock.call(0)] * 3)
        # Just to make sure that there were exactly 3 calls
        self.assertEqual(3, sleep_mock.call_count)
        self.assertEqual(expected_checksum.hexdigest(), actual_checksum)

    def test_compute_checksum_named_algorithm(self):
        path = fileutils.write_to_tempfile(self.content)
        self.assertTrue(os.path.exists(path))
        self.check_file_content(self.content, path)

        expected_checksum = hashlib.sha512()
        expected_checksum.update(self.content)

        actual_checksum = fileutils.compute_file_checksum(path,
                                                          algorithm='sha512')

        self.assertEqual(expected_checksum.hexdigest(), actual_checksum)

    def test_compute_checksum_invalid_algorithm(self):

# Path: oslo_utils/fileutils.py
# _DEFAULT_MODE = stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO
# def ensure_tree(path, mode=_DEFAULT_MODE):
# def delete_if_exists(path, remove=os.unlink):
# def remove_path_on_error(path, remove=delete_if_exists):
# def write_to_tempfile(content, path=None, suffix='', prefix='tmp'):
# def compute_file_checksum(path, read_chunksize=65536, algorithm='sha256'):
# def last_bytes(path, num):
# def is_json(file_path):
# def is_yaml(file_path):


# Path: oslo_utils/tests/test_fileutils.py
import errno
import hashlib
import json
import os
import shutil
import stat
import tempfile
import time
import uuid
import yaml
from unittest import mock
from oslotest import base as test_base
from oslo_utils import fileutils

        path = fileutils.write_to_tempfile(self.content)
        self.assertTrue(os.path.exists(path))
        self.check_file_content(self.content, path)

        expected_checksum = hashlib.sha256()
        expected_checksum.update(self.content)

        with mock.patch.object(time, "sleep") as sleep_mock:
            actual_checksum = fileutils.compute_file_checksum(
                path, read_chunksize=4)

        sleep_mock.assert_has_calls([mock.call(0)] * 3)
        # Just to make sure that there were exactly 3 calls
        self.assertEqual(3, sleep_mock.call_count)
        self.assertEqual(expected_checksum.hexdigest(), actual_checksum)

    def test_compute_checksum_named_algorithm(self):
        path = fileutils.write_to_tempfile(self.content)
        self.assertTrue(os.path.exists(path))
        self.check_file_content(self.content, path)

        expected_checksum = hashlib.sha512()
        expected_checksum.update(self.content)

        actual_checksum = fileutils.compute_file_checksum(path,
                                                          algorithm='sha512')

        self.assertEqual(expected_checksum.hexdigest(), actual_checksum)

    def test_compute_checksum_invalid_algorithm(self):

        path = fileutils.write_to_tempfile(self.content)