mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-13 13:16:52 +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.
41 lines
1.5 KiB
Python
41 lines
1.5 KiB
Python
from .helper import unittest, PillowTestCase
|
|
from PIL import Image, ImageFont, ImageDraw
|
|
|
|
|
|
image_font_installed = True
|
|
try:
|
|
ImageFont.core.getfont
|
|
except ImportError:
|
|
image_font_installed = False
|
|
|
|
|
|
@unittest.skipIf(not image_font_installed, "image font not installed")
|
|
class TestImageFontBitmap(PillowTestCase):
|
|
def test_similar(self):
|
|
text = 'EmbeddedBitmap'
|
|
font_outline = ImageFont.truetype(
|
|
font='Tests/fonts/DejaVuSans.ttf', size=24)
|
|
font_bitmap = ImageFont.truetype(
|
|
font='Tests/fonts/DejaVuSans-bitmap.ttf', size=24)
|
|
size_outline = font_outline.getsize(text)
|
|
size_bitmap = font_bitmap.getsize(text)
|
|
size_final = (max(size_outline[0], size_bitmap[0]),
|
|
max(size_outline[1], size_bitmap[1]))
|
|
im_bitmap = Image.new('RGB', size_final, (255, 255, 255))
|
|
im_outline = im_bitmap.copy()
|
|
draw_bitmap = ImageDraw.Draw(im_bitmap)
|
|
draw_outline = ImageDraw.Draw(im_outline)
|
|
|
|
# Metrics are different on the bitmap and ttf fonts,
|
|
# more so on some platforms and versions of freetype than others.
|
|
# Mac has a 1px difference, linux doesn't.
|
|
draw_bitmap.text((0, size_final[1] - size_bitmap[1]),
|
|
text, fill=(0, 0, 0), font=font_bitmap)
|
|
draw_outline.text((0, size_final[1] - size_outline[1]),
|
|
text, fill=(0, 0, 0), font=font_outline)
|
|
self.assert_image_similar(im_bitmap, im_outline, 20)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|