-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Expand file tree
/
Copy pathtest_file_ani.py
More file actions
165 lines (129 loc) · 4.8 KB
/
test_file_ani.py
File metadata and controls
165 lines (129 loc) · 4.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
from __future__ import annotations
from io import BytesIO
import pytest
from PIL import AniImagePlugin, Image
from .helper import assert_image_equal_tofile
def test_aero_busy() -> None:
with Image.open("Tests/images/ani/aero_busy.ani") as im:
assert isinstance(im, AniImagePlugin.AniImageFile)
assert im.size == (64, 64)
assert im.n_frames == 18
assert_image_equal_tofile(im, "Tests/images/ani/aero_busy_0.png")
im.seek(8)
assert im.tell() == 8
assert_image_equal_tofile(im, "Tests/images/ani/aero_busy_8.png")
with pytest.raises(EOFError):
im.seek(-1)
with pytest.raises(EOFError):
im.seek(18)
def test_posy_busy() -> None:
with Image.open("Tests/images/ani/posy_busy.ani") as im:
assert isinstance(im, AniImagePlugin.AniImageFile)
assert im.size == (96, 96)
assert im.n_frames == 77
assert_image_equal_tofile(im, "Tests/images/ani/posy_busy_0.png")
im.seek(24)
assert_image_equal_tofile(im, "Tests/images/ani/posy_busy_24.png")
with pytest.raises(EOFError):
im.seek(77)
def test_seq_rate() -> None:
with Image.open("Tests/images/ani/stopwtch.ani") as im:
assert isinstance(im, AniImagePlugin.AniImageFile)
assert im.size == (32, 32)
assert im.n_frames == 8
assert im.info["seq"][:3] == [0, 1, 0]
assert im.info["rate"] == [8, 16, 16] + [8] * 42
assert_image_equal_tofile(im, "Tests/images/ani/stopwtch_0.png")
im.seek(5)
assert_image_equal_tofile(im, "Tests/images/ani/stopwtch_5.png")
with pytest.raises(EOFError):
im.seek(8)
def test_save() -> None:
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("Tests/images/ani/" + 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"
)
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]
with BytesIO() as output:
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]
with BytesIO() as output:
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]
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)],
)
with Image.open(output, formats=["ANI"]) as im:
assert isinstance(im, AniImagePlugin.AniImageFile)
assert im.n_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)
assert im.tobytes() == images[4].tobytes()
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)],
)
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)],
)
with pytest.raises(ValueError):
images[0].save(
output,
append_images=images[1:],
rate=[1, 1, 1, 1],
format="ANI",
sizes=[(32, 32)],
)