From efa0fa1b4f4775a109bed56ec1875a8bac6c5944 Mon Sep 17 00:00:00 2001 From: hugovk Date: Wed, 1 Jul 2015 22:51:38 +0300 Subject: [PATCH 1/2] More ImageFont tests --- Tests/test_imagefont.py | 50 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/Tests/test_imagefont.py b/Tests/test_imagefont.py index 8414584f9..fd1c8af9d 100644 --- a/Tests/test_imagefont.py +++ b/Tests/test_imagefont.py @@ -256,6 +256,34 @@ try: # Check boxes a and b are same size self.assertEqual(box_size_a, box_size_b) + def test_rotated_transposed_font_get_mask(self): + # Arrange + text = "mask this" + font = ImageFont.truetype(FONT_PATH, FONT_SIZE) + orientation = Image.ROTATE_90 + transposed_font = ImageFont.TransposedFont( + font, orientation=orientation) + + # Act + mask = transposed_font.getmask(text) + + # Assert + self.assertEqual(mask.size, (13, 108)) + + def test_unrotated_transposed_font_get_mask(self): + # Arrange + text = "mask this" + font = ImageFont.truetype(FONT_PATH, FONT_SIZE) + orientation = None + transposed_font = ImageFont.TransposedFont( + font, orientation=orientation) + + # Act + mask = transposed_font.getmask(text) + + # Assert + self.assertEqual(mask.size, (108, 13)) + def test_free_type_font_get_name(self): # Arrange font = ImageFont.truetype(FONT_PATH, FONT_SIZE) @@ -278,6 +306,28 @@ try: self.assertIsInstance(descent, int) self.assertEqual((ascent, descent), (16, 4)) # too exact check? + def test_free_type_font_get_offset(self): + # Arrange + font = ImageFont.truetype(FONT_PATH, FONT_SIZE) + text = "offset this" + + # Act + offset = font.getoffset(text) + + # Assert + self.assertEqual(offset, (0, 3)) + + def test_free_type_font_get_mask(self): + # Arrange + font = ImageFont.truetype(FONT_PATH, FONT_SIZE) + text = "mask this" + + # Act + mask = font.getmask(text) + + # Assert + self.assertEqual(mask.size, (108, 13)) + def test_load_path_not_found(self): # Arrange filename = "somefilenamethatdoesntexist.ttf" From bfa6b0774143ec891b8460cb339c6aa8cfea8f56 Mon Sep 17 00:00:00 2001 From: hugovk Date: Wed, 1 Jul 2015 22:53:18 +0300 Subject: [PATCH 2/2] flake8 --- Tests/test_imagefont.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Tests/test_imagefont.py b/Tests/test_imagefont.py index fd1c8af9d..1fd70b3d8 100644 --- a/Tests/test_imagefont.py +++ b/Tests/test_imagefont.py @@ -182,7 +182,10 @@ try: ttf = ImageFont.truetype(FONT_PATH, FONT_SIZE) # Act/Assert - self.assertRaises(AssertionError, lambda: draw.multiline_text((0, 0), TEST_TEXT, font=ttf, align="unknown")) + self.assertRaises(AssertionError, + lambda: draw.multiline_text((0, 0), TEST_TEXT, + font=ttf, + align="unknown")) def test_multiline_size(self): ttf = ImageFont.truetype(FONT_PATH, FONT_SIZE) @@ -199,7 +202,8 @@ try: draw = ImageDraw.Draw(im) self.assertEqual(draw.textsize("longest line", font=ttf)[0], - draw.multiline_textsize("longest line\nline", font=ttf)[0]) + draw.multiline_textsize("longest line\nline", + font=ttf)[0]) def test_multiline_spacing(self): ttf = ImageFont.truetype(FONT_PATH, FONT_SIZE)