mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-15 20:06:28 +03:00
7da17ad41e
The previous test configuration made it difficult to run a single test with the pytest CLI. There were two major issues: - The Tests directory was not a package. It now includes a __init__.py file and imports from other tests modules are done with relative imports. - setup.cfg always specified the Tests directory. So even if a specific test were specified as a CLI arg, this configuration would also always include all tests. This configuration has been removed to allow specifying a single test on the command line. Contributors can now run specific tests with a single command such as: $ tox -e py37 -- Tests/test_file_pdf.py::TestFilePdf.test_rgb This makes it easy and faster to iterate on a single test failure and is very familiar to those that have previously used tox and pytest. When running tox or pytest with no arguments, they still discover and runs all tests in the Tests directory.
38 lines
1.1 KiB
Python
38 lines
1.1 KiB
Python
from __future__ import division
|
|
from .helper import unittest, PillowLeakTestCase
|
|
import sys
|
|
from PIL import Image, features, ImageDraw, ImageFont
|
|
|
|
|
|
@unittest.skipIf(sys.platform.startswith('win32'), "requires Unix or macOS")
|
|
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, # ~10k
|
|
font=font, fill="black"))
|
|
|
|
@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)
|
|
|
|
|
|
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)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|