From 723e7648267b5205b349d3d5a482202e0372fed5 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Fri, 6 Feb 2026 21:27:22 +1100 Subject: [PATCH] Improved coverage --- Tests/test_fontfile.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Tests/test_fontfile.py b/Tests/test_fontfile.py index 575dada86..1a9069fd8 100644 --- a/Tests/test_fontfile.py +++ b/Tests/test_fontfile.py @@ -1,5 +1,6 @@ from __future__ import annotations +from io import BytesIO from pathlib import Path import pytest @@ -7,6 +8,15 @@ import pytest from PIL import FontFile, Image +def test_puti16() -> None: + fp = BytesIO() + FontFile.puti16(fp, (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)) + assert fp.getvalue() == ( + b"\x00\x00\x00\x01\x00\x02\x00\x03\x00\x04" + b"\x00\x05\x00\x06\x00\x07\x00\x08\x00\t" + ) + + def test_compile() -> None: font = FontFile.FontFile() font.glyph[0] = ((0, 0), (0, 0, 0, 0), (0, 0, 0, 1), Image.new("L", (0, 0))) @@ -24,5 +34,11 @@ def test_save(tmp_path: Path) -> None: tempname = str(tmp_path / "temp.pil") font = FontFile.FontFile() - with pytest.raises(ValueError): + with pytest.raises(ValueError, match="No bitmap created"): font.save(tempname) + + +def test_to_imagefont() -> None: + font = FontFile.FontFile() + with pytest.raises(ValueError, match="No bitmap created"): + font.to_imagefont()