Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restored testing of ImageFont class #7647

Merged
merged 1 commit into from Dec 29, 2023
Merged

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
56 checks passed
@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.

None yet

3 participants