Merge pull request #7748 from radarhere/test_font_leaks

This commit is contained in:
Hugo van Kemenade 2024-03-11 17:35:26 +02:00 committed by GitHub
commit e09366307c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,8 +1,10 @@
from __future__ import annotations from __future__ import annotations
from PIL import Image, ImageDraw, ImageFont from PIL import Image, ImageDraw, ImageFont, _util
from .helper import PillowLeakTestCase, skip_unless_feature from .helper import PillowLeakTestCase, features, skip_unless_feature
original_core = ImageFont.core
class TestTTypeFontLeak(PillowLeakTestCase): class TestTTypeFontLeak(PillowLeakTestCase):
@ -31,5 +33,11 @@ class TestDefaultFontLeak(TestTTypeFontLeak):
mem_limit = 1024 # k mem_limit = 1024 # k
def test_leak(self) -> None: def test_leak(self) -> None:
if features.check_module("freetype2"):
ImageFont.core = _util.DeferredError(ImportError)
try:
default_font = ImageFont.load_default() default_font = ImageFont.load_default()
finally:
ImageFont.core = original_core
self._test_font(default_font) self._test_font(default_font)