Files
mongo/buildscripts/tests/util/test_fileops.py
Zack Winter fbc2f1ea04 SERVER-111295 [v8.0] Set python as formatter in format_multirun (#41681)
GitOrigin-RevId: 0a5f595c13f329cc64a37f58e7369dd9469ee848
2026-01-15 19:55:28 +00:00

28 lines
885 B
Python

"""Unit tests for fileops.py."""
import unittest
from unittest.mock import patch
import buildscripts.util.fileops as under_test
class TestWriteFileToDir(unittest.TestCase):
@patch("os.path.exists")
@patch("buildscripts.util.fileops.write_file")
def test_existing_file_can_be_overriden(self, mock_write_file, mock_exists):
mock_exists.return_value = True
under_test.write_file_to_dir("dir", "file", "contents", overwrite=True)
mock_write_file.assert_called()
@patch("os.path.exists")
@patch("buildscripts.util.fileops.write_file")
def test_existing_file_can_cause_exception(self, mock_write_file, mock_exists):
mock_exists.return_value = True
with self.assertRaises(FileExistsError):
under_test.write_file_to_dir("dir", "file", "contents", overwrite=False)
mock_write_file.assert_not_called()