mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-12 18:26:17 +03:00
Merge pull request #1327 from hugovk/more_imagefont_tests
More ImageFont tests
This commit is contained in:
commit
290fa69dfa
|
@ -182,7 +182,10 @@ try:
|
||||||
ttf = ImageFont.truetype(FONT_PATH, FONT_SIZE)
|
ttf = ImageFont.truetype(FONT_PATH, FONT_SIZE)
|
||||||
|
|
||||||
# Act/Assert
|
# 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):
|
def test_multiline_size(self):
|
||||||
ttf = ImageFont.truetype(FONT_PATH, FONT_SIZE)
|
ttf = ImageFont.truetype(FONT_PATH, FONT_SIZE)
|
||||||
|
@ -199,7 +202,8 @@ try:
|
||||||
draw = ImageDraw.Draw(im)
|
draw = ImageDraw.Draw(im)
|
||||||
|
|
||||||
self.assertEqual(draw.textsize("longest line", font=ttf)[0],
|
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):
|
def test_multiline_spacing(self):
|
||||||
ttf = ImageFont.truetype(FONT_PATH, FONT_SIZE)
|
ttf = ImageFont.truetype(FONT_PATH, FONT_SIZE)
|
||||||
|
@ -256,6 +260,34 @@ try:
|
||||||
# Check boxes a and b are same size
|
# Check boxes a and b are same size
|
||||||
self.assertEqual(box_size_a, box_size_b)
|
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):
|
def test_free_type_font_get_name(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
font = ImageFont.truetype(FONT_PATH, FONT_SIZE)
|
font = ImageFont.truetype(FONT_PATH, FONT_SIZE)
|
||||||
|
@ -278,6 +310,28 @@ try:
|
||||||
self.assertIsInstance(descent, int)
|
self.assertIsInstance(descent, int)
|
||||||
self.assertEqual((ascent, descent), (16, 4)) # too exact check?
|
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):
|
def test_load_path_not_found(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
filename = "somefilenamethatdoesntexist.ttf"
|
filename = "somefilenamethatdoesntexist.ttf"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user