mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 01:46:18 +03:00
Merge pull request #2 from radarhere/improve-error-messages
Sort extensions alphabetically in error message
This commit is contained in:
commit
7d223fbcaa
|
@ -461,15 +461,16 @@ def test_free_type_font_get_mask(font: ImageFont.FreeTypeFont) -> None:
|
||||||
assert mask.size == (108, 13)
|
assert mask.size == (108, 13)
|
||||||
|
|
||||||
|
|
||||||
def test_load_when_image_not_found(tmp_path: Path) -> None:
|
def test_load_when_image_not_found() -> None:
|
||||||
tmpfile = tmp_path / "file.font"
|
with tempfile.NamedTemporaryFile(delete=False) as tmp:
|
||||||
tmpfile.write_bytes(b"")
|
pass
|
||||||
tempfile = str(tmpfile)
|
|
||||||
with pytest.raises(OSError) as e:
|
with pytest.raises(OSError) as e:
|
||||||
ImageFont.load(tempfile)
|
ImageFont.load(tmp.name)
|
||||||
|
|
||||||
root = os.path.splitext(tempfile)[0]
|
os.unlink(tmp.name)
|
||||||
assert str(e.value) == f"cannot find glyph data file {root}.{{png|gif|pbm}}"
|
|
||||||
|
root = os.path.splitext(tmp.name)[0]
|
||||||
|
assert str(e.value) == f"cannot find glyph data file {root}.{{gif|pbm|png}}"
|
||||||
|
|
||||||
|
|
||||||
def test_load_path_not_found() -> None:
|
def test_load_path_not_found() -> None:
|
||||||
|
|
|
@ -115,7 +115,7 @@ class ImageFont:
|
||||||
if image:
|
if image:
|
||||||
image.close()
|
image.close()
|
||||||
|
|
||||||
msg = f"cannot find glyph data file {root}.{{png|gif|pbm}}"
|
msg = f"cannot find glyph data file {root}.{{gif|pbm|png}}"
|
||||||
raise OSError(msg)
|
raise OSError(msg)
|
||||||
|
|
||||||
self.file = fullname
|
self.file = fullname
|
||||||
|
@ -772,13 +772,12 @@ class TransposedFont:
|
||||||
def load(filename: str) -> ImageFont:
|
def load(filename: str) -> ImageFont:
|
||||||
"""
|
"""
|
||||||
Load a font file. This function loads a font object from the given
|
Load a font file. This function loads a font object from the given
|
||||||
bitmap font file, and returns the corresponding font object.
|
bitmap font file, and returns the corresponding font object. For loading TrueType
|
||||||
|
or OpenType fonts instead, see :py:func:`~PIL.ImageFont.truetype`.
|
||||||
|
|
||||||
:param filename: Name of font file.
|
:param filename: Name of font file.
|
||||||
:return: A font object.
|
:return: A font object.
|
||||||
:exception OSError: If the file could not be read.
|
:exception OSError: If the file could not be read.
|
||||||
|
|
||||||
.. seealso:: :py:func:`PIL.ImageFont.truetype`
|
|
||||||
"""
|
"""
|
||||||
f = ImageFont()
|
f = ImageFont()
|
||||||
f._load_pilfont(filename)
|
f._load_pilfont(filename)
|
||||||
|
@ -794,7 +793,8 @@ def truetype(
|
||||||
) -> FreeTypeFont:
|
) -> FreeTypeFont:
|
||||||
"""
|
"""
|
||||||
Load a TrueType or OpenType font from a file or file-like object,
|
Load a TrueType or OpenType font from a file or file-like object,
|
||||||
and create a font object.
|
and create a font object. For loading bitmap fonts instead,
|
||||||
|
see :py:func:`~PIL.ImageFont.load` and :py:func:`~PIL.ImageFont.load_path`.
|
||||||
This function loads a font object from the given file or file-like
|
This function loads a font object from the given file or file-like
|
||||||
object, and creates a font object for a font of the given size.
|
object, and creates a font object for a font of the given size.
|
||||||
|
|
||||||
|
@ -855,8 +855,6 @@ def truetype(
|
||||||
:return: A font object.
|
:return: A font object.
|
||||||
:exception OSError: If the file could not be read.
|
:exception OSError: If the file could not be read.
|
||||||
:exception ValueError: If the font size is not greater than zero.
|
:exception ValueError: If the font size is not greater than zero.
|
||||||
|
|
||||||
.. seealso:: :py:func:`PIL.ImageFont.load`
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def freetype(font: StrOrBytesPath | BinaryIO | None) -> FreeTypeFont:
|
def freetype(font: StrOrBytesPath | BinaryIO | None) -> FreeTypeFont:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user