update
This commit is contained in:
Binary file not shown.
@@ -4,6 +4,7 @@ import pytest
|
||||
from unittest.mock import Mock, MagicMock, patch
|
||||
|
||||
from src.core.generation_engine import generate_texture_image, generate_preview
|
||||
from src.utils.overlay_assets import RasterizationResult
|
||||
# Test configuration constants
|
||||
DEFAULT_WIDTH = 512
|
||||
DEFAULT_HEIGHT = 512
|
||||
@@ -507,6 +508,58 @@ class TestGenerateTextureImage:
|
||||
assert center_pixel[2] == pytest.approx(0.0, abs=1e-3)
|
||||
assert center_pixel[3] == pytest.approx(1.0, rel=1e-3)
|
||||
|
||||
def test_svg_overlay_is_rasterized_and_applied(self, tmp_path):
|
||||
"""SVG overlays should be rasterized before being composited."""
|
||||
Image = pytest.importorskip("PIL.Image")
|
||||
with patch('src.core.generation_engine.bpy') as mock_bpy, \
|
||||
patch('src.core.generation_engine.ensure_svg_raster') as mock_rasterize:
|
||||
width = height = 64
|
||||
svg_path = tmp_path / "overlay.svg"
|
||||
svg_path.write_text('<svg xmlns="http://www.w3.org/2000/svg" width="10" height="10"></svg>')
|
||||
|
||||
raster_path = tmp_path / "overlay_raster.png"
|
||||
overlay_source = Image.new("RGBA", (16, 16), (0, 255, 0, 255))
|
||||
overlay_source.save(raster_path)
|
||||
|
||||
mock_rasterize.return_value = RasterizationResult(path=str(raster_path), applied_scale=1.0)
|
||||
|
||||
mock_blender_image = MagicMock()
|
||||
mock_blender_image.pixels = [0.0] * (width * height * 4)
|
||||
mock_bpy.data.images.new.return_value = mock_blender_image
|
||||
mock_bpy.data.images.__contains__.return_value = False
|
||||
|
||||
props = create_mock_props(
|
||||
text="",
|
||||
background_transparent=False,
|
||||
background_color=(1.0, 1.0, 1.0, 1.0)
|
||||
)
|
||||
|
||||
overlay = MagicMock()
|
||||
overlay.enabled = True
|
||||
overlay.image_path = str(svg_path)
|
||||
overlay.positioning_mode = 'ABSOLUTE'
|
||||
overlay.x_position = 0.5
|
||||
overlay.y_position = 0.5
|
||||
overlay.scale = 1.0
|
||||
overlay.rotation = 0.0
|
||||
overlay.z_index = 0
|
||||
overlay.text_spacing = 0.0
|
||||
overlay.image_spacing = 0.0
|
||||
props.image_overlays = [overlay]
|
||||
|
||||
result, normal_map = generate_texture_image(props, width, height)
|
||||
|
||||
assert result is mock_blender_image
|
||||
assert normal_map is None
|
||||
mock_rasterize.assert_called_once_with(str(svg_path), overlay.scale)
|
||||
|
||||
center_index = ((height // 2) * width + (width // 2)) * 4
|
||||
center_pixel = mock_blender_image.pixels[center_index:center_index + 4]
|
||||
assert center_pixel[0] == pytest.approx(0.0, abs=1e-3)
|
||||
assert center_pixel[1] == pytest.approx(1.0, rel=1e-3)
|
||||
assert center_pixel[2] == pytest.approx(0.0, abs=1e-3)
|
||||
assert center_pixel[3] == pytest.approx(1.0, rel=1e-3)
|
||||
|
||||
def test_skips_overlays_without_valid_path(self, tmp_path):
|
||||
"""Overlays without a valid image path should be ignored."""
|
||||
pytest.importorskip("PIL.Image")
|
||||
|
||||
Reference in New Issue
Block a user