Skip to content

Conversation

@radarhere
Copy link
Member

#7244 added the following test code

Pillow/Tests/test_imagefont.py

Lines 1056 to 1060 in 78b96c0

default_font = ImageFont.load_default()
with pytest.raises(ValueError):
default_font.getlength("A" * 1_000_001)
with pytest.raises(ValueError):
default_font.getbbox("A" * 1_000_001)

At the time, this was testing the "better than nothing" font that uses ImageFont class. However, #7354 changed the default font in some environments, so the ImageFont class would no longer have been covered in this test.

This PR fixes that by creating an instance of the ImageFont class directly.

Copy link
Contributor

@nulano nulano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought using a not-fully-initialized instance of ImageFont would not be a good test, but adding ImageFont.MAX_STRING_LENGTH = None, I see that this fails with AttributeError instead, confirming this fixes the test.

As far as testing the rest of ImageFont (i.e. coverage after the string length check), I have since found test_font_pcf.py uses an instance initialized with ImageFont.load.

@hugovk hugovk merged commit 2de26d0 into python-pillow:main Dec 29, 2023
@radarhere radarhere deleted the imagefont branch December 29, 2023 21:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants