Improve SgiImagePlugin test coverage#8896
Merged
hugovk merged 4 commits intopython-pillow:mainfrom Jun 27, 2025
Merged
Conversation
hugovk
approved these changes
Jun 26, 2025
src/PIL/SgiImagePlugin.py
Outdated
Comment on lines
158
to
160
| dim = 1 if y == 1 else 2 | ||
| else: | ||
| dim = 3 |
Member
There was a problem hiding this comment.
Shall we use more a descriptive name? (and below)
Suggested change
| dim = 1 if y == 1 else 2 | |
| else: | |
| dim = 3 | |
| dimensions = 1 if y == 1 else 2 | |
| else: | |
| dimensions = 3 |
Member
Author
There was a problem hiding this comment.
I've pushed a commit with dimension. It matches
Pillow/src/PIL/SgiImagePlugin.py
Lines 73 to 74 in 1788ab7
and the NAME in 'The Header' at https://paulbourke.net/dataformats/sgirgb/sgiversion.html
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Looking at SgiImagePlugin, I see that an error for the incorrect number of bands will never be raised.
Pillow/src/PIL/SgiImagePlugin.py
Lines 160 to 176 in 507fefb
Only L, RGB and RGBA modes are supported when saving.
Pillow/src/PIL/SgiImagePlugin.py
Lines 137 to 139 in 507fefb
In the first code snippet, you can see that
z = len(im.mode)would be setzto the correct values of 1 for L, 3 for RGB and 4 for RGBA. It is later set to 1 ifdimis 1 or 2, butdimonly has those values for L mode images, which should be 1 anyway.So the error can be removed.
After some code simplification, this adds coverage for the lines missing at https://app.codecov.io/gh/python-pillow/Pillow/blob/main/src%2FPIL%2FSgiImagePlugin.py