-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Test speedups #10042
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
Open
akx
wants to merge
5
commits into
python-pillow:main
Choose a base branch
from
akx:test-speedups
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+122
−81
Open
Test speedups #10042
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
54e7809
test_apng_save_split_fdat: force smaller block size instead of larger…
akx 5952339
Remove remnant MAXBLOCK/IMAGEBLOCK originals post 29ff5fcb55
akx c2df8ab
Split TestImageFile.test_parser so it can be parallelized
akx ff3fd92
convert_to_comparable: use Image.frombytes
akx 9792b72
Speed up assert_image_similar
akx 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from io import BytesIO | ||
|
|
||
| import pytest | ||
|
|
||
| from PIL import EpsImagePlugin, Image, ImageFile | ||
| from Tests.helper import ( | ||
| assert_image, | ||
| assert_image_equal, | ||
| assert_image_similar, | ||
| hopper, | ||
| skip_unless_feature, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module") | ||
| def hopper_l_1k() -> Image.Image: | ||
| return hopper("L").resize((1000, 1000), Image.Resampling.NEAREST) | ||
|
|
||
|
|
||
| def roundtrip(im: Image.Image, format: str) -> tuple[Image.Image, Image.Image]: | ||
| if format in ("MSP", "XBM"): | ||
| im = im.convert("1") | ||
|
|
||
| test_file = BytesIO() | ||
|
|
||
| im.copy().save(test_file, format) | ||
|
|
||
| data = test_file.getvalue() | ||
|
|
||
| parser = ImageFile.Parser() | ||
| parser.feed(data) | ||
| im_out = parser.close() | ||
|
|
||
| return im, im_out | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "format", | ||
| [ | ||
| "BMP", | ||
| pytest.param( | ||
| "EPS", | ||
| marks=pytest.mark.skipif( | ||
| not EpsImagePlugin.has_ghostscript(), | ||
| reason="Ghostscript not available", | ||
| ), | ||
| ), | ||
| "GIF", | ||
| "IM", | ||
| pytest.param("JPEG", marks=skip_unless_feature("jpg")), | ||
| "MSP", | ||
| "PCX", | ||
| pytest.param("PNG", marks=skip_unless_feature("zlib")), | ||
| "PPM", | ||
| "TGA", | ||
| "TIFF", | ||
| "XBM", | ||
| ], | ||
| ) | ||
| def test_parser( | ||
| monkeypatch: pytest.MonkeyPatch, hopper_l_1k: Image.Image, format: str | ||
| ) -> None: | ||
| # force multiple blocks in PNG driver | ||
| monkeypatch.setattr(ImageFile, "MAXBLOCK", 8192) | ||
|
|
||
| if format == "IM": | ||
| with pytest.warns(DeprecationWarning, match="IM image format"): | ||
| im1, im2 = roundtrip(hopper_l_1k, format) | ||
| else: | ||
| im1, im2 = roundtrip(hopper_l_1k, format) | ||
|
|
||
| if format == "GIF": | ||
| assert_image_similar(im1.convert("P"), im2, 1) | ||
| elif format == "EPS": | ||
| # This test fails on Ubuntu 12.04, PPC (Bigendian) It | ||
| # appears to be a ghostscript 9.05 bug, since the | ||
| # ghostscript rendering is wonky and the file is identical | ||
| # to that written on ubuntu 12.04 x64 | ||
| # md5sum: ba974835ff2d6f3f2fd0053a23521d4a | ||
|
|
||
| # EPS comes back in RGB: | ||
| assert_image_similar(im1, im2.convert("L"), 20) | ||
| elif format == "JPEG": # Lossy compression | ||
| assert_image(im1, im2.mode, im2.size) | ||
| else: | ||
| assert_image_equal(im1, im2) | ||
|
|
||
|
|
||
| def test_parser_pdf_roundtrip_error(hopper_l_1k: Image.Image) -> None: | ||
| # See https://github.com/python-pillow/Pillow/issues/78 | ||
| with pytest.raises(OSError, match="cannot parse this image"): | ||
| roundtrip(hopper_l_1k, "PDF") |
Oops, something went wrong.
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.
I know we have a difference of opinion on this, but I still don't see minor performance improvements in the test suite as a reason to start monkeypatching. I would rather test Pillow as it is with a real image.
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.
Pillow is not being monkeypatched.
MAXBLOCKis a documented public API, this just sets it temporarily.This is the same pattern as used in e.g.
test_padded_idatintest_file_png.