-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Added type hints to Tests/test_font_*.py #7743
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
from __future__ import annotations | ||
|
||
import os | ||
from pathlib import PosixPath | ||
|
||
import pytest | ||
|
||
|
@@ -20,7 +21,7 @@ | |
pytestmark = skip_unless_feature("zlib") | ||
|
||
|
||
def save_font(request, tmp_path): | ||
def save_font(request: pytest.FixtureRequest, tmp_path: PosixPath) -> str: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I've pushed a commit to update it, both the changes from here and #7732 |
||
with open(fontname, "rb") as test_file: | ||
font = PcfFontFile.PcfFontFile(test_file) | ||
assert isinstance(font, FontFile.FontFile) | ||
|
@@ -29,7 +30,7 @@ def save_font(request, tmp_path): | |
|
||
tempname = str(tmp_path / "temp.pil") | ||
|
||
def delete_tempfile(): | ||
def delete_tempfile() -> None: | ||
try: | ||
os.remove(tempname[:-4] + ".pbm") | ||
except OSError: | ||
|
@@ -47,25 +48,25 @@ def delete_tempfile(): | |
return tempname | ||
|
||
|
||
def test_sanity(request, tmp_path): | ||
def test_sanity(request: pytest.FixtureRequest, tmp_path: PosixPath) -> None: | ||
save_font(request, tmp_path) | ||
|
||
|
||
def test_less_than_256_characters(): | ||
def test_less_than_256_characters() -> None: | ||
with open("Tests/fonts/10x20-ISO8859-1-fewer-characters.pcf", "rb") as test_file: | ||
font = PcfFontFile.PcfFontFile(test_file) | ||
assert isinstance(font, FontFile.FontFile) | ||
# check the number of characters in the font | ||
assert len([_f for _f in font.glyph if _f]) == 127 | ||
|
||
|
||
def test_invalid_file(): | ||
def test_invalid_file() -> None: | ||
with open("Tests/images/flower.jpg", "rb") as fp: | ||
with pytest.raises(SyntaxError): | ||
PcfFontFile.PcfFontFile(fp) | ||
|
||
|
||
def test_draw(request, tmp_path): | ||
def test_draw(request: pytest.FixtureRequest, tmp_path: PosixPath) -> None: | ||
tempname = save_font(request, tmp_path) | ||
font = ImageFont.load(tempname) | ||
im = Image.new("L", (130, 30), "white") | ||
|
@@ -74,7 +75,7 @@ def test_draw(request, tmp_path): | |
assert_image_similar_tofile(im, "Tests/images/test_draw_pbm_target.png", 0) | ||
|
||
|
||
def test_textsize(request, tmp_path): | ||
def test_textsize(request: pytest.FixtureRequest, tmp_path: PosixPath) -> None: | ||
tempname = save_font(request, tmp_path) | ||
font = ImageFont.load(tempname) | ||
for i in range(255): | ||
|
@@ -90,7 +91,9 @@ def test_textsize(request, tmp_path): | |
assert font.getbbox(msg) == (0, 0, len(msg) * 10, 20) | ||
|
||
|
||
def _test_high_characters(request, tmp_path, message): | ||
def _test_high_characters( | ||
request: pytest.FixtureRequest, tmp_path: PosixPath, message: str | bytes | ||
) -> None: | ||
tempname = save_font(request, tmp_path) | ||
font = ImageFont.load(tempname) | ||
im = Image.new("L", (750, 30), "white") | ||
|
@@ -99,7 +102,7 @@ def _test_high_characters(request, tmp_path, message): | |
assert_image_similar_tofile(im, "Tests/images/high_ascii_chars.png", 0) | ||
|
||
|
||
def test_high_characters(request, tmp_path): | ||
def test_high_characters(request: pytest.FixtureRequest, tmp_path: PosixPath) -> None: | ||
message = "".join(chr(i + 1) for i in range(140, 232)) | ||
_test_high_characters(request, tmp_path, message) | ||
# accept bytes instances. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this test is checking for leaks with a PIL font and was also broken by #7354.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I've created #7748 for this.