mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-08-22 21:24:46 +03:00
add tests for invalid anchor
This commit is contained in:
parent
e0b53f0014
commit
f9624c3205
|
@ -864,6 +864,24 @@ class TestImageFont:
|
||||||
with Image.open(target) as expected:
|
with Image.open(target) as expected:
|
||||||
assert_image_similar(im, expected, self.metrics["multiline-anchor"])
|
assert_image_similar(im, expected, self.metrics["multiline-anchor"])
|
||||||
|
|
||||||
|
def test_anchor_invalid(self):
|
||||||
|
font = self.get_font()
|
||||||
|
im = Image.new("RGB", (100, 100), "white")
|
||||||
|
d = ImageDraw.Draw(im)
|
||||||
|
d.font = font
|
||||||
|
|
||||||
|
for anchor in ["", "l", "a", "lax", "sa", "xa", "lx"]:
|
||||||
|
pytest.raises(ValueError, lambda: font.getmask2("hello", anchor=anchor))
|
||||||
|
pytest.raises(ValueError, lambda: font.getbbox("hello", anchor=anchor))
|
||||||
|
pytest.raises(ValueError, lambda: d.text((0, 0), "hello", anchor=anchor))
|
||||||
|
pytest.raises(
|
||||||
|
ValueError, lambda: d.multiline_text((0, 0), "foo\nbar", anchor=anchor)
|
||||||
|
)
|
||||||
|
for anchor in ["lt", "lb"]:
|
||||||
|
pytest.raises(
|
||||||
|
ValueError, lambda: d.multiline_text((0, 0), "foo\nbar", anchor=anchor)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@skip_unless_feature("raqm")
|
@skip_unless_feature("raqm")
|
||||||
class TestImageFont_RaqmLayout(TestImageFont):
|
class TestImageFont_RaqmLayout(TestImageFont):
|
||||||
|
|
|
@ -380,3 +380,32 @@ def test_combine_multiline(anchor, align):
|
||||||
|
|
||||||
with Image.open(path) as expected:
|
with Image.open(path) as expected:
|
||||||
assert_image_similar(im, expected, 0.015)
|
assert_image_similar(im, expected, 0.015)
|
||||||
|
|
||||||
|
|
||||||
|
def test_anchor_invalid_ttb():
|
||||||
|
font = ImageFont.truetype(FONT_PATH, FONT_SIZE)
|
||||||
|
im = Image.new("RGB", (100, 100), "white")
|
||||||
|
d = ImageDraw.Draw(im)
|
||||||
|
d.font = font
|
||||||
|
|
||||||
|
for anchor in ["", "l", "a", "lax", "xa", "la", "ls", "ld", "lx"]:
|
||||||
|
pytest.raises(
|
||||||
|
ValueError, lambda: font.getmask2("hello", anchor=anchor, direction="ttb")
|
||||||
|
)
|
||||||
|
pytest.raises(
|
||||||
|
ValueError, lambda: font.getbbox("hello", anchor=anchor, direction="ttb")
|
||||||
|
)
|
||||||
|
pytest.raises(
|
||||||
|
ValueError, lambda: d.text((0, 0), "hello", anchor=anchor, direction="ttb")
|
||||||
|
)
|
||||||
|
pytest.raises(
|
||||||
|
ValueError,
|
||||||
|
lambda: d.multiline_text(
|
||||||
|
(0, 0), "foo\nbar", anchor=anchor, direction="ttb"
|
||||||
|
),
|
||||||
|
)
|
||||||
|
# ttb multiline text does not support anchors at all
|
||||||
|
pytest.raises(
|
||||||
|
ValueError,
|
||||||
|
lambda: d.multiline_text((0, 0), "foo\nbar", anchor="mm", direction="ttb"),
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user