Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nulano committed Sep 1, 2020
1 parent ea582a1 commit 9d4e6c1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
6 changes: 3 additions & 3 deletions Tests/test_font_leaks.py
Expand Up @@ -5,15 +5,15 @@

class TestTTypeFontLeak(PillowLeakTestCase):
# fails at iteration 3 in master
iterations = 10
iterations = 40
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
(0, 0), "some text " * 256, font=font, fill="black" # ~2.5k
)
)

Expand All @@ -25,7 +25,7 @@ def test_leak(self):

class TestDefaultFontLeak(TestTTypeFontLeak):
# fails at iteration 37 in master
iterations = 100
iterations = 400
mem_limit = 1024 # k

def test_leak(self):
Expand Down
2 changes: 1 addition & 1 deletion Tests/test_imagedraw.py
Expand Up @@ -1039,7 +1039,7 @@ def test_stroke_descender():
draw.text((10, 0), "y", "#f00", font, stroke_width=2, stroke_fill="#0f0")

# Assert
assert_image_similar_tofile(im, "Tests/images/imagedraw_stroke_descender.png", 6.76)
assert_image_similar_tofile(im, "Tests/images/imagedraw_stroke_descender.png", 6.78)


@skip_unless_feature("freetype2")
Expand Down
9 changes: 5 additions & 4 deletions Tests/test_imagefont.py
Expand Up @@ -471,7 +471,8 @@ def test_unicode_extended(self):
d = ImageDraw.Draw(img)
d.text((10, 10), text, font=ttf)

assert_image_similar_tofile(img, target, self.metrics["multiline"])
# fails with 14.7
assert_image_similar_tofile(img, target, 6.2)

def _test_fake_loading_font(self, monkeypatch, path_to_fake, fontname):
# Make a copy of FreeTypeFont so we can patch the original
Expand Down Expand Up @@ -703,10 +704,10 @@ def test_variation_set_by_name(self):
font.set_variation_by_name("Bold")

font = ImageFont.truetype("Tests/fonts/AdobeVFPrototype.ttf", 36)
self._check_text(font, "Tests/images/variation_adobe.png", 11)
self._check_text(font, "Tests/images/variation_adobe.png", 11.2)
for name in ["Bold", b"Bold"]:
font.set_variation_by_name(name)
self._check_text(font, "Tests/images/variation_adobe_name.png", 11)
self._check_text(font, "Tests/images/variation_adobe_name.png", 11.3)

font = ImageFont.truetype("Tests/fonts/TINY5x3GX.ttf", 36)
self._check_text(font, "Tests/images/variation_tiny.png", 40)
Expand All @@ -728,7 +729,7 @@ def test_variation_set_by_axes(self):

font = ImageFont.truetype("Tests/fonts/AdobeVFPrototype.ttf", 36)
font.set_variation_by_axes([500, 50])
self._check_text(font, "Tests/images/variation_adobe_axes.png", 5.1)
self._check_text(font, "Tests/images/variation_adobe_axes.png", 5.8)

font = ImageFont.truetype("Tests/fonts/TINY5x3GX.ttf", 36)
font.set_variation_by_axes([100])
Expand Down
3 changes: 2 additions & 1 deletion src/PIL/ImageFont.py
Expand Up @@ -259,9 +259,10 @@ def getsize(
:return: (width, height)
"""
# vertical offset is added for historical reasons, see discussion in #4789
size, offset = self.font.getsize(text, False, direction, features, language)
return (
size[0] + stroke_width * 2 + offset[0],
size[0] + stroke_width * 2,
size[1] + stroke_width * 2 + offset[1],
)

Expand Down

0 comments on commit 9d4e6c1

Please sign in to comment.