2017-09-02 19:03:56 +03:00
|
|
|
from __future__ import division
|
|
|
|
from helper import unittest, PillowLeakTestCase
|
|
|
|
import sys
|
|
|
|
from PIL import Image, features, ImageDraw, ImageFont
|
|
|
|
|
2018-03-03 12:54:00 +03:00
|
|
|
|
2018-03-19 11:36:07 +03:00
|
|
|
@unittest.skipIf(sys.platform.startswith('win32'), "requires Unix or macOS")
|
2017-09-02 19:03:56 +03:00
|
|
|
class TestTTypeFontLeak(PillowLeakTestCase):
|
|
|
|
# fails at iteration 3 in master
|
|
|
|
iterations = 10
|
2018-03-04 07:33:44 +03:00
|
|
|
mem_limit = 4096 # k
|
2017-09-02 19:03:56 +03:00
|
|
|
|
|
|
|
def _test_font(self, font):
|
2018-03-06 11:53:07 +03:00
|
|
|
im = Image.new('RGB', (255, 255), 'white')
|
2017-09-02 19:03:56 +03:00
|
|
|
draw = ImageDraw.ImageDraw(im)
|
2018-03-04 07:33:44 +03:00
|
|
|
self._test_leak(lambda: draw.text((0, 0), "some text "*1024, # ~10k
|
2017-09-02 19:03:56 +03:00
|
|
|
font=font, fill="black"))
|
2018-01-27 09:07:24 +03:00
|
|
|
|
2017-09-02 19:03:56 +03:00
|
|
|
@unittest.skipIf(not features.check('freetype2'), "Test requires freetype2")
|
|
|
|
def test_leak(self):
|
|
|
|
ttype = ImageFont.truetype('Tests/fonts/FreeMono.ttf', 20)
|
|
|
|
self._test_font(ttype)
|
|
|
|
|
2018-03-03 12:54:00 +03:00
|
|
|
|
2017-09-02 19:03:56 +03:00
|
|
|
class TestDefaultFontLeak(TestTTypeFontLeak):
|
|
|
|
# fails at iteration 37 in master
|
|
|
|
iterations = 100
|
2018-03-04 07:33:44 +03:00
|
|
|
mem_limit = 1024 # k
|
2018-01-27 09:07:24 +03:00
|
|
|
|
2017-09-02 19:03:56 +03:00
|
|
|
def test_leak(self):
|
|
|
|
default_font = ImageFont.load_default()
|
|
|
|
self._test_font(default_font)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|