mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-11 12:17:14 +03:00
4f185329f4
This adds a new test decorator: skip_unless_feature(). The argument is the same as passed to features.check(). If the feature is not supported, the test will be skipped. This removes several kinds of boilerplate copied and pasted around tests so test feature checking is handled and displayed more consistently. Refs #4193
34 lines
922 B
Python
34 lines
922 B
Python
from PIL import Image, ImageDraw, ImageFont
|
|
|
|
from .helper import PillowLeakTestCase, skip_unless_feature
|
|
|
|
|
|
class TestTTypeFontLeak(PillowLeakTestCase):
|
|
# fails at iteration 3 in master
|
|
iterations = 10
|
|
mem_limit = 4096 # k
|
|
|
|
def _test_font(self, font):
|
|
im = Image.new("RGB", (255, 255), "white")
|
|
draw = ImageDraw.ImageDraw(im)
|
|
self._test_leak(
|
|
lambda: draw.text(
|
|
(0, 0), "some text " * 1024, font=font, fill="black" # ~10k
|
|
)
|
|
)
|
|
|
|
@skip_unless_feature("freetype2")
|
|
def test_leak(self):
|
|
ttype = ImageFont.truetype("Tests/fonts/FreeMono.ttf", 20)
|
|
self._test_font(ttype)
|
|
|
|
|
|
class TestDefaultFontLeak(TestTTypeFontLeak):
|
|
# fails at iteration 37 in master
|
|
iterations = 100
|
|
mem_limit = 1024 # k
|
|
|
|
def test_leak(self):
|
|
default_font = ImageFont.load_default()
|
|
self._test_font(default_font)
|