This commit is contained in:
2025-10-13 11:15:21 +02:00
parent 9a6543c530
commit 2519b55f08
24 changed files with 498 additions and 169 deletions

View File

@@ -48,6 +48,7 @@ def setup_pil_mocks(mock_pil_image_module, mock_pil_imagedraw_module,
# Setup ImageFont mock based on font_type
if font_type == 'default':
mock_font = MagicMock()
mock_pil_imagefont_module.truetype.return_value = mock_font
mock_pil_imagefont_module.load_default.return_value = mock_font
elif font_type == 'custom':
mock_font = MagicMock()
@@ -195,7 +196,47 @@ class TestGenerateTextureImage:
call_args = mock_pil_image_module.new.call_args
assert call_args[0][0] == "RGBA"
assert call_args[0][2] == (0, 0, 0, 0)
def test_default_font_uses_scalable_size(self):
"""Ensure default font configuration respects requested font size."""
with patch('PIL.Image') as mock_pil_image_module, \
patch('PIL.ImageDraw') as mock_pil_imagedraw_module, \
patch('PIL.ImageFont') as mock_pil_imagefont_module, \
patch('src.core.generation_engine.bpy') as mock_bpy, \
patch('src.core.generation_engine.find_default_truetype_font', return_value="/fonts/fallback.ttf", create=True):
setup_pil_mocks(
mock_pil_image_module,
mock_pil_imagedraw_module,
mock_pil_imagefont_module,
DEFAULT_WIDTH,
DEFAULT_HEIGHT,
font_type='default'
)
setup_bpy_mocks(mock_bpy, DEFAULT_WIDTH, DEFAULT_HEIGHT)
fallback_font = MagicMock()
def truetype_side_effect(font_path_arg, size_arg):
if font_path_arg is None:
raise TypeError("file must be a path, not None")
return fallback_font
mock_pil_imagefont_module.truetype.side_effect = truetype_side_effect
mock_pil_imagefont_module.load_default.return_value = MagicMock()
props = create_mock_props(
text="Size Probe",
font_path='default',
use_custom_font=False,
font_size=42
)
generate_texture_image(props, DEFAULT_WIDTH, DEFAULT_HEIGHT)
mock_pil_imagefont_module.truetype.assert_called_with("/fonts/fallback.ttf", 42)
mock_pil_imagefont_module.load_default.assert_not_called()
def test_generate_colored_background(self):
"""Test generation with custom background color."""
with patch('PIL.Image') as mock_pil_image_module, \