hoist tests out of try/except, use feature detection

This commit is contained in:
wiredfool 2017-06-13 09:02:43 -07:00
parent 42831098ac
commit f371ca07f4

View File

@ -1,23 +1,22 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from helper import unittest, PillowTestCase from helper import unittest, PillowTestCase
from PIL import Image from PIL import Image, ImageDraw, ImageFont, features
from PIL import ImageDraw, ImageFont
#check if raqm installed
have_raqm = ImageFont.core.have_raqm
FONT_SIZE = 20 FONT_SIZE = 20
FONT_PATH = "Tests/fonts/DejaVuSans.ttf" FONT_PATH = "Tests/fonts/DejaVuSans.ttf"
try: @unittest.skipUnless(features.check('raqm'), "Raqm Library is not installed.")
from PIL import ImageFont class TestImagecomplextext(PillowTestCase):
def test_english(self):
#smoke test, this should not fail
ttf = ImageFont.truetype(FONT_PATH, FONT_SIZE) ttf = ImageFont.truetype(FONT_PATH, FONT_SIZE)
im = Image.new(mode='RGB', size=(300, 100)) im = Image.new(mode='RGB', size=(300, 100))
draw = ImageDraw.Draw(im) draw = ImageDraw.Draw(im)
draw.text((0, 0), 'TEST', font=ttf, fill=500, direction='ltr') draw.text((0, 0), 'TEST', font=ttf, fill=500, direction='ltr')
@unittest.skipIf(not have_raqm, "Raqm Library is not installed !")
class TestImagecomplextext(PillowTestCase):
def test_complex_text(self): def test_complex_text(self):
ttf = ImageFont.truetype(FONT_PATH, FONT_SIZE) ttf = ImageFont.truetype(FONT_PATH, FONT_SIZE)
@ -126,15 +125,6 @@ try:
self.assert_image_similar(im, target_img, .5) self.assert_image_similar(im, target_img, .5)
except ImportError:
class TestImagecomplextext(PillowTestCase):
def test_skip(self):
self.skipTest("ImportError")
except KeyError:
class TestImagecomplextext(PillowTestCase):
def test_skip(self):
self.skipTest("KeyError")
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()