import pytest import io import os from openpyxl import Workbook from openpyxl.styles import Font from core.renderer import ExcelRenderer from PIL import Image, ImageFont @pytest.fixture def font_family_excel_bytes(): wb = Workbook() ws = wb.active ws.title = "FontFamilyTest" # SimSun (Songti) ws['A1'] = "宋体文本" ws['A1'].font = Font(name="宋体", size=12) # SimHei (Heiti) ws['A2'] = "黑体文本" ws['A2'].font = Font(name="黑体", size=12) # English Font ws['A3'] = "Arial Text" ws['A3'].font = Font(name="Arial", size=12) out = io.BytesIO() wb.save(out) out.seek(0) return out.getvalue() def test_font_family_selection(font_family_excel_bytes): """ Test that different font families are mapped correctly. Note: We can't easily check visual output in unit test, but we can check if the renderer attempts to load different fonts. """ renderer = ExcelRenderer(font_family_excel_bytes) try: renderer.render_to_bytes(sheet_name="FontFamilyTest") except Exception as e: pytest.fail(f"Rendering failed: {e}") # Check internal cache to see if different fonts were loaded # This assumes we implement logic to cache based on font name too # Currently it might fail or only show 1 font if logic is missing # print(renderer.font_cache.keys()) pass