remove multiline
This commit is contained in:
@@ -4,7 +4,7 @@ Tests how the core modules work together.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
from unittest.mock import Mock, patch, MagicMock
|
||||
from unittest.mock import Mock, patch
|
||||
import sys
|
||||
import os
|
||||
|
||||
@@ -18,17 +18,13 @@ class TestTextGenerationPipeline:
|
||||
"""Integration tests for the complete text generation workflow"""
|
||||
|
||||
@pytest.mark.integration
|
||||
@patch('src.core.text_processor.process_multiline_text')
|
||||
@patch('src.core.text_processor.wrap_text_to_width')
|
||||
@patch('src.core.text_fitting.find_optimal_font_size')
|
||||
@patch('src.core.text_fitting.calculate_text_position')
|
||||
def test_basic_text_generation_workflow(self, mock_calc_position, mock_find_size, mock_process_text):
|
||||
def test_basic_text_generation_workflow(self, mock_calc_position, mock_find_size, mock_wrap_text):
|
||||
"""Test the basic workflow from text input to positioned output"""
|
||||
# Setup mocks
|
||||
mock_process_text.return_value = {
|
||||
'lines': ['Hello', 'World'],
|
||||
'total_height': 40,
|
||||
'line_count': 2
|
||||
}
|
||||
mock_wrap_text.return_value = ['Hello', 'World']
|
||||
mock_find_size.return_value = 24
|
||||
mock_calc_position.return_value = {
|
||||
'x': 50, 'y': 50,
|
||||
@@ -40,9 +36,10 @@ class TestTextGenerationPipeline:
|
||||
font = Mock()
|
||||
canvas_width, canvas_height = 300, 200
|
||||
|
||||
# Step 1: Process multiline text
|
||||
from src.core.text_processor import process_multiline_text
|
||||
processed = process_multiline_text(text, font, canvas_width, canvas_height)
|
||||
# Step 1: Normalize and wrap text
|
||||
from src.core.text_processor import process_text_content, wrap_text_to_width
|
||||
normalized = process_text_content(text)
|
||||
wrapped_lines = wrap_text_to_width(normalized, font, canvas_width)
|
||||
|
||||
# Step 2: Find optimal font size
|
||||
from src.core.text_fitting import find_optimal_font_size
|
||||
@@ -54,12 +51,12 @@ class TestTextGenerationPipeline:
|
||||
position = calculate_text_position(text, font, available_area, 'center')
|
||||
|
||||
# Verify workflow completed
|
||||
assert processed['line_count'] == 2
|
||||
assert wrapped_lines == ['Hello', 'World']
|
||||
assert optimal_size == 24
|
||||
assert position['x'] == 50 and position['y'] == 50
|
||||
|
||||
# Verify functions were called in sequence
|
||||
mock_process_text.assert_called_once()
|
||||
mock_wrap_text.assert_called_once_with(normalized, font, canvas_width)
|
||||
mock_find_size.assert_called_once()
|
||||
mock_calc_position.assert_called_once()
|
||||
|
||||
@@ -190,15 +187,13 @@ class TestErrorHandlingIntegration:
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_error_handling_in_text_processing_chain(self):
|
||||
"""Test error handling when text processing components fail"""
|
||||
with patch('src.core.text_processor.wrap_text_to_width') as mock_wrap:
|
||||
mock_wrap.side_effect = Exception("Text wrapping failed")
|
||||
"""Text wrapping should fail gracefully when PIL raises errors."""
|
||||
with patch('PIL.Image.new'), patch('PIL.ImageDraw.Draw') as mock_draw_class:
|
||||
mock_draw = Mock()
|
||||
mock_draw_class.return_value = mock_draw
|
||||
mock_draw.textbbox.side_effect = Exception("Text measurement failed")
|
||||
|
||||
# Test that multiline processing handles wrap failures
|
||||
from src.core.text_processor import process_multiline_text
|
||||
result = process_multiline_text("Test text", Mock(), 200, 100)
|
||||
from src.core.text_processor import wrap_text_to_width
|
||||
result = wrap_text_to_width("Test text", Mock(), 200)
|
||||
|
||||
# Should return fallback result instead of crashing
|
||||
assert 'lines' in result
|
||||
assert 'total_height' in result
|
||||
assert 'line_count' in result
|
||||
assert result == ["Test text"]
|
||||
|
||||
Reference in New Issue
Block a user