Fix tests for CI?
Python CI / test (push) Failing after 7m45s

This commit is contained in:
2025-11-04 22:30:04 +01:00
parent 9ba35d2fa8
commit 37505d3dcc
5 changed files with 148 additions and 31 deletions
@@ -11,6 +11,8 @@ from unittest.mock import Mock, patch
from PIL import Image, ImageDraw
import numpy as np
from typing import List, Optional
import os
import logging
from pyWebLayout.layout.document_layouter import paragraph_layouter, DocumentLayouter
from pyWebLayout.style.abstract_style import AbstractStyle
@@ -21,13 +23,42 @@ from pyWebLayout.concrete.page import Page
from pyWebLayout.concrete.text import Line, Text
from pyWebLayout.abstract.inline import Word
# Enable logging to see font loading messages
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def verify_bundled_font_available():
"""Verify that the bundled font is available for integration tests."""
# Get the bundled font path
current_dir = os.path.dirname(os.path.abspath(__file__))
# Navigate up to pyWebLayout root, then to assets/fonts
project_root = os.path.dirname(os.path.dirname(current_dir))
bundled_font_path = os.path.join(project_root, 'pyWebLayout', 'assets', 'fonts', 'DejaVuSans.ttf')
logger.info(f"Integration tests checking for bundled font at: {bundled_font_path}")
if not os.path.exists(bundled_font_path):
pytest.fail(
f"INTEGRATION TEST FAILURE: Bundled font not found at {bundled_font_path}\n"
f"Integration tests require the bundled font to ensure consistent behavior.\n"
f"This likely means the font was not included in the package build."
)
logger.info(f"Bundled font found at: {bundled_font_path}")
return bundled_font_path
class MockWord(Word):
"""A simple mock word that extends the real Word class."""
def __init__(self, text, style=None):
if style is None:
# Integration tests MUST use the bundled font for consistency
style = Font(font_size=16)
# Verify the font loaded properly
if style.font.path is None:
logger.warning("Font loaded without explicit path - may be using PIL default")
# Initialize the base Word with required parameters
super().__init__(text, style)
self._concrete_texts = []
@@ -73,6 +104,11 @@ class MockParagraph:
class TestDocumentLayouterIntegration:
"""Integration tests using real components."""
@classmethod
def setup_class(cls):
"""Verify bundled font is available before running any tests."""
verify_bundled_font_available()
def test_single_page_layout_with_real_components(self):
"""Test layout on a single page using real Line and Text objects."""
# Create a real page that can fit content