mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-02-11 17:10:58 +03:00
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
8aa0a864fe
commit
35475914b9
|
@ -1,5 +1,7 @@
|
|||
from io import BytesIO
|
||||
|
||||
import pytest
|
||||
|
||||
from PIL import Image
|
||||
|
||||
|
||||
|
@ -65,55 +67,72 @@ def test_stopwtch():
|
|||
|
||||
def test_save():
|
||||
directory_path = "Tests/images/ani/"
|
||||
filenames = ["aero_busy_0.png", "aero_busy_8.png",
|
||||
"posy_busy_0.png", "posy_busy_24.png",
|
||||
"stopwtch_0.png", "stopwtch_5.png"]
|
||||
filenames = [
|
||||
"aero_busy_0.png",
|
||||
"aero_busy_8.png",
|
||||
"posy_busy_0.png",
|
||||
"posy_busy_24.png",
|
||||
"stopwtch_0.png",
|
||||
"stopwtch_5.png",
|
||||
]
|
||||
|
||||
images = [Image.open(directory_path + filename) for filename in filenames]
|
||||
|
||||
with BytesIO() as output:
|
||||
images[0].save(output, append_images=[images[1]], seq=[
|
||||
0, 1], rate=[5, 10], format="ANI")
|
||||
images[0].save(
|
||||
output, append_images=[images[1]], seq=[0, 1], rate=[5, 10], format="ANI"
|
||||
)
|
||||
|
||||
with Image.open(output, formats=["ANI"]) as im:
|
||||
assert im.tobytes() == images[0].tobytes()
|
||||
im.seek(1)
|
||||
assert im.tobytes() == images[1].tobytes()
|
||||
assert im.info['seq'] == [0, 1]
|
||||
assert im.info['rate'] == [5, 10]
|
||||
assert im.info["seq"] == [0, 1]
|
||||
assert im.info["rate"] == [5, 10]
|
||||
|
||||
with BytesIO() as output:
|
||||
images[2].save(output, append_images=[images[3]], seq=[
|
||||
1, 0], rate=[2, 2], format="ANI", sizes=[(96, 96)])
|
||||
images[2].save(
|
||||
output,
|
||||
append_images=[images[3]],
|
||||
seq=[1, 0],
|
||||
rate=[2, 2],
|
||||
format="ANI",
|
||||
sizes=[(96, 96)],
|
||||
)
|
||||
|
||||
with Image.open(output, formats=["ANI"]) as im:
|
||||
assert im.tobytes() == images[2].tobytes()
|
||||
im.seek(1)
|
||||
assert im.tobytes() == images[3].tobytes()
|
||||
assert im.info['seq'] == [1, 0]
|
||||
assert im.info['rate'] == [2, 2]
|
||||
assert im.info["seq"] == [1, 0]
|
||||
assert im.info["rate"] == [2, 2]
|
||||
|
||||
with BytesIO() as output:
|
||||
images[4].save(output, append_images=[images[5]], seq=[
|
||||
0, 1], rate=[3, 4], format="ANI")
|
||||
images[4].save(
|
||||
output, append_images=[images[5]], seq=[0, 1], rate=[3, 4], format="ANI"
|
||||
)
|
||||
|
||||
with Image.open(output, formats=["ANI"]) as im:
|
||||
assert im.tobytes() == images[4].tobytes()
|
||||
im.seek(1)
|
||||
assert im.tobytes() == images[5].tobytes()
|
||||
assert im.info['seq'] == [0, 1]
|
||||
assert im.info['rate'] == [3, 4]
|
||||
assert im.info["seq"] == [0, 1]
|
||||
assert im.info["rate"] == [3, 4]
|
||||
|
||||
with BytesIO() as output:
|
||||
images[0].save(output, append_images=images[1:],
|
||||
seq=[0, 2, 4, 1, 3, 5, 0, 1, 0, 1],
|
||||
rate=[1, 2, 3, 1, 2, 3, 1, 2, 3, 4],
|
||||
format="ANI", sizes=[(32, 32)])
|
||||
images[0].save(
|
||||
output,
|
||||
append_images=images[1:],
|
||||
seq=[0, 2, 4, 1, 3, 5, 0, 1, 0, 1],
|
||||
rate=[1, 2, 3, 1, 2, 3, 1, 2, 3, 4],
|
||||
format="ANI",
|
||||
sizes=[(32, 32)],
|
||||
)
|
||||
|
||||
with Image.open(output, formats=["ANI"]) as im:
|
||||
assert im.info['frames'] == 6
|
||||
assert im.info['seq'] == [0, 2, 4, 1, 3, 5, 0, 1, 0, 1]
|
||||
assert im.info['rate'] == [1, 2, 3, 1, 2, 3, 1, 2, 3, 4]
|
||||
assert im.info["frames"] == 6
|
||||
assert im.info["seq"] == [0, 2, 4, 1, 3, 5, 0, 1, 0, 1]
|
||||
assert im.info["rate"] == [1, 2, 3, 1, 2, 3, 1, 2, 3, 4]
|
||||
assert im.size == (32, 32)
|
||||
|
||||
im.seek(4)
|
||||
|
@ -121,12 +140,30 @@ def test_save():
|
|||
|
||||
with BytesIO() as output:
|
||||
with pytest.raises(ValueError):
|
||||
images[0].save(output, append_images=images[1:], seq=[
|
||||
0, 1, 8, 1, 2], rate=[1, 1, 1, 1, 1], format="ANI", sizes=[(32, 32)])
|
||||
images[0].save(
|
||||
output,
|
||||
append_images=images[1:],
|
||||
seq=[0, 1, 8, 1, 2],
|
||||
rate=[1, 1, 1, 1, 1],
|
||||
format="ANI",
|
||||
sizes=[(32, 32)],
|
||||
)
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
images[0].save(output, append_images=images[1:], seq=[
|
||||
0, 1, 1, 1, 2], rate=[1, 1, 1, 1], format="ANI", sizes=[(32, 32)])
|
||||
images[0].save(
|
||||
output,
|
||||
append_images=images[1:],
|
||||
seq=[0, 1, 1, 1, 2],
|
||||
rate=[1, 1, 1, 1],
|
||||
format="ANI",
|
||||
sizes=[(32, 32)],
|
||||
)
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
images[0].save(output, append_images=images[1:], rate=[1, 1, 1, 1], format="ANI", sizes=[(32, 32)])
|
||||
images[0].save(
|
||||
output,
|
||||
append_images=images[1:],
|
||||
rate=[1, 1, 1, 1],
|
||||
format="ANI",
|
||||
sizes=[(32, 32)],
|
||||
)
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
from io import BytesIO
|
||||
|
||||
import pytest
|
||||
|
||||
from io import BytesIO
|
||||
from PIL import CurImagePlugin, Image
|
||||
|
||||
|
||||
def test_deerstalker():
|
||||
with Image.open("Tests/images/cur/deerstalker.cur") as im:
|
||||
assert im.size == (32, 32)
|
||||
assert im.info['hotspots'] == [(0, 0)]
|
||||
assert im.info["hotspots"] == [(0, 0)]
|
||||
assert isinstance(im, CurImagePlugin.CurImageFile)
|
||||
# Check some pixel colors to ensure image is loaded properly
|
||||
assert im.getpixel((10, 1)) == (0, 0, 0, 0)
|
||||
|
@ -18,8 +19,8 @@ def test_deerstalker():
|
|||
def test_posy_link():
|
||||
with Image.open("Tests/images/cur/posy_link.cur") as im:
|
||||
assert im.size == (128, 128)
|
||||
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["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)]
|
||||
# check some pixel colors
|
||||
assert im.getpixel((0, 0)) == (0, 0, 0, 0)
|
||||
assert im.getpixel((20, 20)) == (0, 0, 0, 255)
|
||||
|
@ -69,8 +70,13 @@ def test_save_win98_arrow():
|
|||
with Image.open("Tests/images/cur/win98_arrow.png") as im:
|
||||
# save the data
|
||||
with BytesIO() as output:
|
||||
im.save(output, format="CUR", sizes=[(32, 32)], hotspots=[
|
||||
(10, 10)], bitmap_format="bmp")
|
||||
im.save(
|
||||
output,
|
||||
format="CUR",
|
||||
sizes=[(32, 32)],
|
||||
hotspots=[(10, 10)],
|
||||
bitmap_format="bmp",
|
||||
)
|
||||
|
||||
with Image.open(output) as im2:
|
||||
assert im.tobytes() == im2.tobytes()
|
||||
|
@ -92,27 +98,36 @@ def test_save_posy_link():
|
|||
with Image.open("Tests/images/cur/posy_link.png") as im:
|
||||
# save the data
|
||||
with BytesIO() as output:
|
||||
im.save(output, sizes=sizes, hotspots=hotspots,
|
||||
format="CUR", bitmap_format="bmp")
|
||||
im.save(
|
||||
output,
|
||||
sizes=sizes,
|
||||
hotspots=hotspots,
|
||||
format="CUR",
|
||||
bitmap_format="bmp",
|
||||
)
|
||||
|
||||
# make sure saved output is readable
|
||||
# and sizes/hotspots are correct
|
||||
with Image.open(output, formats=["CUR"]) as im2:
|
||||
assert (128, 128) == im2.size
|
||||
assert sizes == im2.info['sizes']
|
||||
assert sizes == im2.info["sizes"]
|
||||
|
||||
with BytesIO() as output:
|
||||
im.save(output, sizes=sizes[3:], hotspots=hotspots[3:],
|
||||
format="CUR")
|
||||
im.save(output, sizes=sizes[3:], hotspots=hotspots[3:], format="CUR")
|
||||
|
||||
# make sure saved output is readable
|
||||
# and sizes/hotspots are correct
|
||||
with Image.open(output, formats=["CUR"]) as im2:
|
||||
assert (48, 48) == im2.size
|
||||
assert sizes[3:] == im2.info['sizes']
|
||||
assert sizes[3:] == im2.info["sizes"]
|
||||
|
||||
# make sure error is thrown when size and hotspot len's
|
||||
# don't match
|
||||
with pytest.raises(ValueError):
|
||||
im.save(output, sizes=sizes[2:], hotspots=hotspots[3:],
|
||||
format="CUR", bitmap_format="bmp")
|
||||
im.save(
|
||||
output,
|
||||
sizes=sizes[2:],
|
||||
hotspots=hotspots[3:],
|
||||
format="CUR",
|
||||
bitmap_format="bmp",
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue
Block a user