mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-08-15 09:44:46 +03:00
Use assert_image_equal and assert_image_equal_tofile
This commit is contained in:
parent
879f4b7e54
commit
f5d866fce0
|
@ -6,18 +6,18 @@ import pytest
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
|
from .helper import assert_image_equal_tofile
|
||||||
|
|
||||||
|
|
||||||
def test_aero_busy() -> None:
|
def test_aero_busy() -> None:
|
||||||
with Image.open("Tests/images/ani/aero_busy.ani") as im:
|
with Image.open("Tests/images/ani/aero_busy.ani") as im:
|
||||||
assert im.size == (64, 64)
|
assert im.size == (64, 64)
|
||||||
assert im.n_frames == 18
|
assert im.n_frames == 18
|
||||||
|
|
||||||
with Image.open("Tests/images/ani/aero_busy_0.png") as png:
|
assert_image_equal_tofile(im, "Tests/images/ani/aero_busy_0.png")
|
||||||
assert png.tobytes() == im.tobytes()
|
|
||||||
|
|
||||||
im.seek(8)
|
im.seek(8)
|
||||||
with Image.open("Tests/images/ani/aero_busy_8.png") as png:
|
assert_image_equal_tofile(im, "Tests/images/ani/aero_busy_8.png")
|
||||||
assert png.tobytes() == im.tobytes()
|
|
||||||
|
|
||||||
with pytest.raises(EOFError):
|
with pytest.raises(EOFError):
|
||||||
im.seek(-1)
|
im.seek(-1)
|
||||||
|
@ -31,44 +31,33 @@ def test_posy_busy() -> None:
|
||||||
assert im.size == (96, 96)
|
assert im.size == (96, 96)
|
||||||
assert im.n_frames == 77
|
assert im.n_frames == 77
|
||||||
|
|
||||||
with Image.open("Tests/images/ani/posy_busy_0.png") as png:
|
assert_image_equal_tofile(im, "Tests/images/ani/posy_busy_0.png")
|
||||||
assert png.tobytes() == im.tobytes()
|
|
||||||
|
|
||||||
im.seek(24)
|
im.seek(24)
|
||||||
with Image.open("Tests/images/ani/posy_busy_24.png") as png:
|
assert_image_equal_tofile(im, "Tests/images/ani/posy_busy_24.png")
|
||||||
assert png.tobytes() == im.tobytes()
|
|
||||||
|
|
||||||
with pytest.raises(EOFError):
|
with pytest.raises(EOFError):
|
||||||
im.seek(77)
|
im.seek(77)
|
||||||
|
|
||||||
|
|
||||||
def test_stopwtch() -> None:
|
def test_seq_rate() -> None:
|
||||||
with Image.open("Tests/images/ani/stopwtch.ani") as im:
|
with Image.open("Tests/images/ani/stopwtch.ani") as im:
|
||||||
assert im.size == (32, 32)
|
assert im.size == (32, 32)
|
||||||
assert im.n_frames == 8
|
assert im.n_frames == 8
|
||||||
|
|
||||||
assert im.info["seq"][0] == 0
|
assert im.info["seq"][:3] == [0, 1, 0]
|
||||||
assert im.info["seq"][2] == 0
|
assert im.info["rate"] == [8, 16, 16] + [8] * 42
|
||||||
|
|
||||||
for i, r in enumerate(im.info["rate"]):
|
assert_image_equal_tofile(im, "Tests/images/ani/stopwtch_0.png")
|
||||||
if i == 1 or i == 2:
|
|
||||||
assert r == 16
|
|
||||||
else:
|
|
||||||
assert r == 8
|
|
||||||
|
|
||||||
with Image.open("Tests/images/ani/stopwtch_0.png") as png:
|
|
||||||
assert png.tobytes() == im.tobytes()
|
|
||||||
|
|
||||||
im.seek(5)
|
im.seek(5)
|
||||||
with Image.open("Tests/images/ani/stopwtch_5.png") as png:
|
assert_image_equal_tofile(im, "Tests/images/ani/stopwtch_5.png")
|
||||||
assert png.tobytes() == im.tobytes()
|
|
||||||
|
|
||||||
with pytest.raises(EOFError):
|
with pytest.raises(EOFError):
|
||||||
im.seek(8)
|
im.seek(8)
|
||||||
|
|
||||||
|
|
||||||
def test_save() -> None:
|
def test_save() -> None:
|
||||||
directory_path = "Tests/images/ani/"
|
|
||||||
filenames = [
|
filenames = [
|
||||||
"aero_busy_0.png",
|
"aero_busy_0.png",
|
||||||
"aero_busy_8.png",
|
"aero_busy_8.png",
|
||||||
|
@ -78,7 +67,7 @@ def test_save() -> None:
|
||||||
"stopwtch_5.png",
|
"stopwtch_5.png",
|
||||||
]
|
]
|
||||||
|
|
||||||
images = [Image.open(directory_path + filename) for filename in filenames]
|
images = [Image.open("Tests/images/ani/" + filename) for filename in filenames]
|
||||||
|
|
||||||
with BytesIO() as output:
|
with BytesIO() as output:
|
||||||
images[0].save(
|
images[0].save(
|
||||||
|
|
|
@ -6,13 +6,16 @@ import pytest
|
||||||
|
|
||||||
from PIL import CurImagePlugin, Image
|
from PIL import CurImagePlugin, Image
|
||||||
|
|
||||||
|
from .helper import assert_image_equal
|
||||||
|
|
||||||
def test_deerstalker() -> None:
|
|
||||||
|
def test_sanity() -> None:
|
||||||
with Image.open("Tests/images/cur/deerstalker.cur") as im:
|
with Image.open("Tests/images/cur/deerstalker.cur") as im:
|
||||||
assert im.size == (32, 32)
|
assert im.size == (32, 32)
|
||||||
assert im.info["hotspots"] == [(0, 0)]
|
assert im.info["hotspots"] == [(0, 0)]
|
||||||
assert isinstance(im, CurImagePlugin.CurImageFile)
|
assert isinstance(im, CurImagePlugin.CurImageFile)
|
||||||
# Check some pixel colors to ensure image is loaded properly
|
|
||||||
|
# Check pixel colors to ensure image is loaded properly
|
||||||
assert im.getpixel((10, 1)) == (0, 0, 0, 0)
|
assert im.getpixel((10, 1)) == (0, 0, 0, 0)
|
||||||
assert im.getpixel((11, 1)) == (253, 254, 254, 1)
|
assert im.getpixel((11, 1)) == (253, 254, 254, 1)
|
||||||
assert im.getpixel((16, 16)) == (84, 87, 86, 255)
|
assert im.getpixel((16, 16)) == (84, 87, 86, 255)
|
||||||
|
@ -23,7 +26,8 @@ def test_posy_link() -> None:
|
||||||
assert im.size == (128, 128)
|
assert im.size == (128, 128)
|
||||||
assert im.info["sizes"] == {(128, 128), (96, 96), (64, 64), (48, 48), (32, 32)}
|
assert im.info["sizes"] == {(128, 128), (96, 96), (64, 64), (48, 48), (32, 32)}
|
||||||
assert im.info["hotspots"] == [(25, 7), (18, 5), (12, 3), (9, 2), (5, 1)]
|
assert im.info["hotspots"] == [(25, 7), (18, 5), (12, 3), (9, 2), (5, 1)]
|
||||||
# check some pixel colors
|
|
||||||
|
# check pixel colors
|
||||||
assert im.getpixel((0, 0)) == (0, 0, 0, 0)
|
assert im.getpixel((0, 0)) == (0, 0, 0, 0)
|
||||||
assert im.getpixel((20, 20)) == (0, 0, 0, 255)
|
assert im.getpixel((20, 20)) == (0, 0, 0, 255)
|
||||||
assert im.getpixel((40, 40)) == (255, 255, 255, 255)
|
assert im.getpixel((40, 40)) == (255, 255, 255, 255)
|
||||||
|
@ -79,9 +83,8 @@ def test_save_win98_arrow() -> None:
|
||||||
hotspots=[(10, 10)],
|
hotspots=[(10, 10)],
|
||||||
bitmap_format="bmp",
|
bitmap_format="bmp",
|
||||||
)
|
)
|
||||||
|
|
||||||
with Image.open(output) as reloaded:
|
with Image.open(output) as reloaded:
|
||||||
assert im.tobytes() == reloaded.tobytes()
|
assert_image_equal(im, reloaded)
|
||||||
|
|
||||||
with BytesIO() as output:
|
with BytesIO() as output:
|
||||||
im.save(output, format="CUR")
|
im.save(output, format="CUR")
|
||||||
|
@ -120,11 +123,10 @@ def test_save_posy_link() -> None:
|
||||||
# make sure saved output is readable
|
# make sure saved output is readable
|
||||||
# and sizes/hotspots are correct
|
# and sizes/hotspots are correct
|
||||||
with Image.open(output, formats=["CUR"]) as reloaded:
|
with Image.open(output, formats=["CUR"]) as reloaded:
|
||||||
assert (48, 48) == reloaded.size
|
assert reloaded.size == (48, 48)
|
||||||
assert set(sizes[3:]) == reloaded.info["sizes"]
|
assert reloaded.info["sizes"] == set(sizes[3:])
|
||||||
|
|
||||||
# make sure error is thrown when size and hotspot len's
|
# check error is thrown when size and hotspot length don't match
|
||||||
# don't match
|
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
im.save(
|
im.save(
|
||||||
output,
|
output,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user