mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-07-11 00:32:27 +03:00
Assert getcolors does not return None
This commit is contained in:
parent
8d31625ba8
commit
cfaf356c33
|
@ -229,7 +229,9 @@ class TestFilePng:
|
||||||
assert_image(im, "RGBA", (162, 150))
|
assert_image(im, "RGBA", (162, 150))
|
||||||
|
|
||||||
# image has 124 unique alpha values
|
# image has 124 unique alpha values
|
||||||
assert len(im.getchannel("A").getcolors()) == 124
|
colors = im.getchannel("A").getcolors()
|
||||||
|
assert colors is not None
|
||||||
|
assert len(colors) == 124
|
||||||
|
|
||||||
def test_load_transparent_rgb(self) -> None:
|
def test_load_transparent_rgb(self) -> None:
|
||||||
test_file = "Tests/images/rgb_trns.png"
|
test_file = "Tests/images/rgb_trns.png"
|
||||||
|
@ -241,7 +243,9 @@ class TestFilePng:
|
||||||
assert_image(im, "RGBA", (64, 64))
|
assert_image(im, "RGBA", (64, 64))
|
||||||
|
|
||||||
# image has 876 transparent pixels
|
# image has 876 transparent pixels
|
||||||
assert im.getchannel("A").getcolors()[0][0] == 876
|
colors = im.getchannel("A").getcolors()
|
||||||
|
assert colors is not None
|
||||||
|
assert colors[0][0] == 876
|
||||||
|
|
||||||
def test_save_p_transparent_palette(self, tmp_path: Path) -> None:
|
def test_save_p_transparent_palette(self, tmp_path: Path) -> None:
|
||||||
in_file = "Tests/images/pil123p.png"
|
in_file = "Tests/images/pil123p.png"
|
||||||
|
@ -262,7 +266,9 @@ class TestFilePng:
|
||||||
assert_image(im, "RGBA", (162, 150))
|
assert_image(im, "RGBA", (162, 150))
|
||||||
|
|
||||||
# image has 124 unique alpha values
|
# image has 124 unique alpha values
|
||||||
assert len(im.getchannel("A").getcolors()) == 124
|
colors = im.getchannel("A").getcolors()
|
||||||
|
assert colors is not None
|
||||||
|
assert len(colors) == 124
|
||||||
|
|
||||||
def test_save_p_single_transparency(self, tmp_path: Path) -> None:
|
def test_save_p_single_transparency(self, tmp_path: Path) -> None:
|
||||||
in_file = "Tests/images/p_trns_single.png"
|
in_file = "Tests/images/p_trns_single.png"
|
||||||
|
@ -285,7 +291,9 @@ class TestFilePng:
|
||||||
assert im.getpixel((31, 31)) == (0, 255, 52, 0)
|
assert im.getpixel((31, 31)) == (0, 255, 52, 0)
|
||||||
|
|
||||||
# image has 876 transparent pixels
|
# image has 876 transparent pixels
|
||||||
assert im.getchannel("A").getcolors()[0][0] == 876
|
colors = im.getchannel("A").getcolors()
|
||||||
|
assert colors is not None
|
||||||
|
assert colors[0][0] == 876
|
||||||
|
|
||||||
def test_save_p_transparent_black(self, tmp_path: Path) -> None:
|
def test_save_p_transparent_black(self, tmp_path: Path) -> None:
|
||||||
# check if solid black image with full transparency
|
# check if solid black image with full transparency
|
||||||
|
@ -313,7 +321,9 @@ class TestFilePng:
|
||||||
assert im.info["transparency"] == 255
|
assert im.info["transparency"] == 255
|
||||||
|
|
||||||
im_rgba = im.convert("RGBA")
|
im_rgba = im.convert("RGBA")
|
||||||
assert im_rgba.getchannel("A").getcolors()[0][0] == num_transparent
|
colors = im_rgba.getchannel("A").getcolors()
|
||||||
|
assert colors is not None
|
||||||
|
assert colors[0][0] == num_transparent
|
||||||
|
|
||||||
test_file = tmp_path / "temp.png"
|
test_file = tmp_path / "temp.png"
|
||||||
im.save(test_file)
|
im.save(test_file)
|
||||||
|
@ -324,7 +334,9 @@ class TestFilePng:
|
||||||
assert_image_equal(im, test_im)
|
assert_image_equal(im, test_im)
|
||||||
|
|
||||||
test_im_rgba = test_im.convert("RGBA")
|
test_im_rgba = test_im.convert("RGBA")
|
||||||
assert test_im_rgba.getchannel("A").getcolors()[0][0] == num_transparent
|
colors = test_im_rgba.getchannel("A").getcolors()
|
||||||
|
assert colors is not None
|
||||||
|
assert colors[0][0] == num_transparent
|
||||||
|
|
||||||
def test_save_rgb_single_transparency(self, tmp_path: Path) -> None:
|
def test_save_rgb_single_transparency(self, tmp_path: Path) -> None:
|
||||||
in_file = "Tests/images/caption_6_33_22.png"
|
in_file = "Tests/images/caption_6_33_22.png"
|
||||||
|
|
|
@ -274,13 +274,17 @@ def test_save_l_transparency(tmp_path: Path) -> None:
|
||||||
in_file = "Tests/images/la.tga"
|
in_file = "Tests/images/la.tga"
|
||||||
with Image.open(in_file) as im:
|
with Image.open(in_file) as im:
|
||||||
assert im.mode == "LA"
|
assert im.mode == "LA"
|
||||||
assert im.getchannel("A").getcolors()[0][0] == num_transparent
|
colors = im.getchannel("A").getcolors()
|
||||||
|
assert colors is not None
|
||||||
|
assert colors[0][0] == num_transparent
|
||||||
|
|
||||||
out = tmp_path / "temp.tga"
|
out = tmp_path / "temp.tga"
|
||||||
im.save(out)
|
im.save(out)
|
||||||
|
|
||||||
with Image.open(out) as test_im:
|
with Image.open(out) as test_im:
|
||||||
assert test_im.mode == "LA"
|
assert test_im.mode == "LA"
|
||||||
assert test_im.getchannel("A").getcolors()[0][0] == num_transparent
|
colors = test_im.getchannel("A").getcolors()
|
||||||
|
assert colors is not None
|
||||||
|
assert colors[0][0] == num_transparent
|
||||||
|
|
||||||
assert_image_equal(im, test_im)
|
assert_image_equal(im, test_im)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user