import tempfile from pathlib import Path from types import SimpleNamespace from unittest.mock import Mock, patch from tests.support.blender import BlenderTestCase class InputPreparationTest(BlenderTestCase): def test_sequence_format_is_checked_before_copy(self): with tempfile.TemporaryDirectory() as directory: path = Path(directory) / "frame.0001.exr" path.touch() image = SimpleNamespace(source="SEQUENCE") with ( patch.object(self.image_data, "image_path", return_value=path), patch.object(self.image_data, "image_is_packed", return_value=False), patch.object(self.image_data.tempfile, "mkdtemp") as create, ): with self.assertRaisesRegex(RuntimeError, "Unsupported input format: .exr"): self.image_data.prepare_image_input(image, None) create.assert_not_called() self.assertTrue(path.exists()) def test_packed_export_failure_removes_temporary_directory(self): for failure in (OSError("disk full"), None): with tempfile.TemporaryDirectory() as directory: output = Path(directory) / "export" output.mkdir() image = SimpleNamespace(file_format="OPEN_EXR", save=Mock(side_effect=failure)) with patch.object(self.image_data.tempfile, "mkdtemp", return_value=str(output)): with self.assertRaises(RuntimeError): self.image_data.save_packed_image(image, None) self.assertEqual(image.file_format, "OPEN_EXR") self.assertFalse(output.exists()) def test_sequence_copy_failure_preserves_originals(self): with tempfile.TemporaryDirectory() as directory: root = Path(directory) source = root / "frame.0001.png" source.write_bytes(b"source") output = root / "prepared" output.mkdir() with ( patch.object(self.image_data, "image_path", return_value=source), patch.object(self.image_data, "image_is_packed", return_value=False), patch.object(self.image_data, "collect_sequence_frames", return_value=[source]), patch.object(self.image_data.tempfile, "mkdtemp", return_value=str(output)), patch.object(self.image_data.shutil, "copy2", side_effect=OSError("disk full")), ): with self.assertRaises(OSError): self.image_data.prepare_image_input(SimpleNamespace(source="SEQUENCE"), None) self.assertFalse(output.exists()) self.assertEqual(source.read_bytes(), b"source")