Skip to content

Commit cfaf356

Browse files
committed
Assert getcolors does not return None
1 parent 8d31625 commit cfaf356

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

Tests/test_file_png.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,9 @@ def test_load_transparent_p(self) -> None:
229229
assert_image(im, "RGBA", (162, 150))
230230

231231
# image has 124 unique alpha values
232-
assert len(im.getchannel("A").getcolors()) == 124
232+
colors = im.getchannel("A").getcolors()
233+
assert colors is not None
234+
assert len(colors) == 124
233235

234236
def test_load_transparent_rgb(self) -> None:
235237
test_file = "Tests/images/rgb_trns.png"
@@ -241,7 +243,9 @@ def test_load_transparent_rgb(self) -> None:
241243
assert_image(im, "RGBA", (64, 64))
242244

243245
# image has 876 transparent pixels
244-
assert im.getchannel("A").getcolors()[0][0] == 876
246+
colors = im.getchannel("A").getcolors()
247+
assert colors is not None
248+
assert colors[0][0] == 876
245249

246250
def test_save_p_transparent_palette(self, tmp_path: Path) -> None:
247251
in_file = "Tests/images/pil123p.png"
@@ -262,7 +266,9 @@ def test_save_p_transparent_palette(self, tmp_path: Path) -> None:
262266
assert_image(im, "RGBA", (162, 150))
263267

264268
# image has 124 unique alpha values
265-
assert len(im.getchannel("A").getcolors()) == 124
269+
colors = im.getchannel("A").getcolors()
270+
assert colors is not None
271+
assert len(colors) == 124
266272

267273
def test_save_p_single_transparency(self, tmp_path: Path) -> None:
268274
in_file = "Tests/images/p_trns_single.png"
@@ -285,7 +291,9 @@ def test_save_p_single_transparency(self, tmp_path: Path) -> None:
285291
assert im.getpixel((31, 31)) == (0, 255, 52, 0)
286292

287293
# image has 876 transparent pixels
288-
assert im.getchannel("A").getcolors()[0][0] == 876
294+
colors = im.getchannel("A").getcolors()
295+
assert colors is not None
296+
assert colors[0][0] == 876
289297

290298
def test_save_p_transparent_black(self, tmp_path: Path) -> None:
291299
# check if solid black image with full transparency
@@ -313,7 +321,9 @@ def test_save_grayscale_transparency(self, tmp_path: Path) -> None:
313321
assert im.info["transparency"] == 255
314322

315323
im_rgba = im.convert("RGBA")
316-
assert im_rgba.getchannel("A").getcolors()[0][0] == num_transparent
324+
colors = im_rgba.getchannel("A").getcolors()
325+
assert colors is not None
326+
assert colors[0][0] == num_transparent
317327

318328
test_file = tmp_path / "temp.png"
319329
im.save(test_file)
@@ -324,7 +334,9 @@ def test_save_grayscale_transparency(self, tmp_path: Path) -> None:
324334
assert_image_equal(im, test_im)
325335

326336
test_im_rgba = test_im.convert("RGBA")
327-
assert test_im_rgba.getchannel("A").getcolors()[0][0] == num_transparent
337+
colors = test_im_rgba.getchannel("A").getcolors()
338+
assert colors is not None
339+
assert colors[0][0] == num_transparent
328340

329341
def test_save_rgb_single_transparency(self, tmp_path: Path) -> None:
330342
in_file = "Tests/images/caption_6_33_22.png"

Tests/test_file_tga.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,13 +274,17 @@ def test_save_l_transparency(tmp_path: Path) -> None:
274274
in_file = "Tests/images/la.tga"
275275
with Image.open(in_file) as im:
276276
assert im.mode == "LA"
277-
assert im.getchannel("A").getcolors()[0][0] == num_transparent
277+
colors = im.getchannel("A").getcolors()
278+
assert colors is not None
279+
assert colors[0][0] == num_transparent
278280

279281
out = tmp_path / "temp.tga"
280282
im.save(out)
281283

282284
with Image.open(out) as test_im:
283285
assert test_im.mode == "LA"
284-
assert test_im.getchannel("A").getcolors()[0][0] == num_transparent
286+
colors = test_im.getchannel("A").getcolors()
287+
assert colors is not None
288+
assert colors[0][0] == num_transparent
285289

286290
assert_image_equal(im, test_im)

0 commit comments

Comments
 (0)