Skip to content

Commit cba096b

Browse files
committed
Assert pixel data is tuple
1 parent 33460d2 commit cba096b

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

Tests/test_file_gif.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,9 @@ def test_dispose_background_transparency() -> None:
540540
img.seek(2)
541541
px = img.load()
542542
assert px is not None
543-
assert px[35, 30][3] == 0
543+
value = px[35, 30]
544+
assert isinstance(value, tuple)
545+
assert value[3] == 0
544546

545547

546548
@pytest.mark.parametrize(
@@ -1479,7 +1481,9 @@ def test_saving_rgba(tmp_path: Path) -> None:
14791481

14801482
with Image.open(out) as reloaded:
14811483
reloaded_rgba = reloaded.convert("RGBA")
1482-
assert reloaded_rgba.load()[0, 0][3] == 0
1484+
value = reloaded_rgba.load()[0, 0]
1485+
assert isinstance(value, tuple)
1486+
assert value[3] == 0
14831487

14841488

14851489
@pytest.mark.parametrize("params", ({}, {"disposal": 2, "optimize": False}))

Tests/test_file_jpeg.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,17 @@ def test_cmyk(self) -> None:
133133
f = "Tests/images/pil_sample_cmyk.jpg"
134134
with Image.open(f) as im:
135135
# the source image has red pixels in the upper left corner.
136-
c, m, y, k = (x / 255.0 for x in im.getpixel((0, 0)))
136+
cmyk = im.getpixel((0, 0))
137+
assert isinstance(cmyk, tuple)
138+
c, m, y, k = (x / 255.0 for x in cmyk)
137139
assert c == 0.0
138140
assert m > 0.8
139141
assert y > 0.8
140142
assert k == 0.0
141143
# the opposite corner is black
142-
c, m, y, k = (
143-
x / 255.0 for x in im.getpixel((im.size[0] - 1, im.size[1] - 1))
144-
)
144+
cmyk = im.getpixel((im.size[0] - 1, im.size[1] - 1))
145+
assert isinstance(cmyk, tuple)
146+
k = cmyk[3] / 255.0
145147
assert k > 0.9
146148
# roundtrip, and check again
147149
im = self.roundtrip(im)

Tests/test_file_tga.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,16 @@ def test_horizontal_orientations() -> None:
220220
with Image.open("Tests/images/rgb32rle_top_right.tga") as im:
221221
px = im.load()
222222
assert px is not None
223-
assert px[90, 90][:3] == (0, 0, 0)
223+
value = px[90, 90]
224+
assert isinstance(value, tuple)
225+
assert value[:3] == (0, 0, 0)
224226

225227
with Image.open("Tests/images/rgb32rle_bottom_right.tga") as im:
226228
px = im.load()
227229
assert px is not None
228-
assert px[90, 90][:3] == (0, 255, 0)
230+
value = px[90, 90]
231+
assert isinstance(value, tuple)
232+
assert value[:3] == (0, 255, 0)
229233

230234

231235
def test_save_rle(tmp_path: Path) -> None:

Tests/test_file_webp.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ def test_background_from_gif(self, tmp_path: Path) -> None:
219219
# Save P mode GIF with background
220220
with Image.open("Tests/images/chi.gif") as im:
221221
original_value = im.convert("RGB").getpixel((1, 1))
222+
assert isinstance(original_value, tuple)
222223

223224
# Save as WEBP
224225
im.save(out_webp, save_all=True)
@@ -230,6 +231,7 @@ def test_background_from_gif(self, tmp_path: Path) -> None:
230231

231232
with Image.open(out_gif) as reread:
232233
reread_value = reread.convert("RGB").getpixel((1, 1))
234+
assert isinstance(reread_value, tuple)
233235
difference = sum(abs(original_value[i] - reread_value[i]) for i in range(3))
234236
assert difference < 5
235237

0 commit comments

Comments
 (0)