Fix up pytest.raises lambda: uses

This commit is contained in:
Aarni Koskela 2023-02-23 15:18:11 +02:00
parent 583dd3b424
commit 5c8a9165ab
2 changed files with 34 additions and 52 deletions

View File

@ -351,7 +351,8 @@ def test_rotated_transposed_font(font, orientation):
assert bbox_b[3] == 20 + bbox_a[2] - bbox_a[0] assert bbox_b[3] == 20 + bbox_a[2] - bbox_a[0]
# text length is undefined for vertical text # text length is undefined for vertical text
pytest.raises(ValueError, draw.textlength, word) with pytest.raises(ValueError):
draw.textlength(word)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -872,25 +873,23 @@ def test_anchor_invalid(font):
d.font = font d.font = font
for anchor in ["", "l", "a", "lax", "sa", "xa", "lx"]: for anchor in ["", "l", "a", "lax", "sa", "xa", "lx"]:
pytest.raises(ValueError, lambda: font.getmask2("hello", anchor=anchor)) with pytest.raises(ValueError):
pytest.raises(ValueError, lambda: font.getbbox("hello", anchor=anchor)) font.getmask2("hello", anchor=anchor)
pytest.raises(ValueError, lambda: d.text((0, 0), "hello", anchor=anchor)) with pytest.raises(ValueError):
pytest.raises(ValueError, lambda: d.textbbox((0, 0), "hello", anchor=anchor)) font.getbbox("hello", anchor=anchor)
pytest.raises( with pytest.raises(ValueError):
ValueError, lambda: d.multiline_text((0, 0), "foo\nbar", anchor=anchor) d.text((0, 0), "hello", anchor=anchor)
) with pytest.raises(ValueError):
pytest.raises( d.textbbox((0, 0), "hello", anchor=anchor)
ValueError, with pytest.raises(ValueError):
lambda: d.multiline_textbbox((0, 0), "foo\nbar", anchor=anchor), d.multiline_text((0, 0), "foo\nbar", anchor=anchor)
) with pytest.raises(ValueError):
d.multiline_textbbox((0, 0), "foo\nbar", anchor=anchor)
for anchor in ["lt", "lb"]: for anchor in ["lt", "lb"]:
pytest.raises( with pytest.raises(ValueError):
ValueError, lambda: d.multiline_text((0, 0), "foo\nbar", anchor=anchor) d.multiline_text((0, 0), "foo\nbar", anchor=anchor)
) with pytest.raises(ValueError):
pytest.raises( d.multiline_textbbox((0, 0), "foo\nbar", anchor=anchor)
ValueError,
lambda: d.multiline_textbbox((0, 0), "foo\nbar", anchor=anchor),
)
@pytest.mark.parametrize("bpp", (1, 2, 4, 8)) @pytest.mark.parametrize("bpp", (1, 2, 4, 8))

View File

@ -360,37 +360,20 @@ def test_anchor_invalid_ttb():
d.font = font d.font = font
for anchor in ["", "l", "a", "lax", "xa", "la", "ls", "ld", "lx"]: for anchor in ["", "l", "a", "lax", "xa", "la", "ls", "ld", "lx"]:
pytest.raises( with pytest.raises(ValueError):
ValueError, lambda: font.getmask2("hello", anchor=anchor, direction="ttb") font.getmask2("hello", anchor=anchor, direction="ttb")
) with pytest.raises(ValueError):
pytest.raises( font.getbbox("hello", anchor=anchor, direction="ttb")
ValueError, lambda: font.getbbox("hello", anchor=anchor, direction="ttb") with pytest.raises(ValueError):
) d.text((0, 0), "hello", anchor=anchor, direction="ttb")
pytest.raises( with pytest.raises(ValueError):
ValueError, lambda: d.text((0, 0), "hello", anchor=anchor, direction="ttb") d.textbbox((0, 0), "hello", anchor=anchor, direction="ttb")
) with pytest.raises(ValueError):
pytest.raises( d.multiline_text((0, 0), "foo\nbar", anchor=anchor, direction="ttb")
ValueError, with pytest.raises(ValueError):
lambda: d.textbbox((0, 0), "hello", anchor=anchor, direction="ttb"), d.multiline_textbbox((0, 0), "foo\nbar", anchor=anchor, direction="ttb")
)
pytest.raises(
ValueError,
lambda: d.multiline_text(
(0, 0), "foo\nbar", anchor=anchor, direction="ttb"
),
)
pytest.raises(
ValueError,
lambda: d.multiline_textbbox(
(0, 0), "foo\nbar", anchor=anchor, direction="ttb"
),
)
# ttb multiline text does not support anchors at all # ttb multiline text does not support anchors at all
pytest.raises( with pytest.raises(ValueError):
ValueError, d.multiline_text((0, 0), "foo\nbar", anchor="mm", direction="ttb")
lambda: d.multiline_text((0, 0), "foo\nbar", anchor="mm", direction="ttb"), with pytest.raises(ValueError):
) d.multiline_textbbox((0, 0), "foo\nbar", anchor="mm", direction="ttb")
pytest.raises(
ValueError,
lambda: d.multiline_textbbox((0, 0), "foo\nbar", anchor="mm", direction="ttb"),
)