Skip to content

Commit ce225ec

Browse files
committed
Use assert_image_equal_tofile
1 parent 879f4b7 commit ce225ec

File tree

2 files changed

+23
-33
lines changed

2 files changed

+23
-33
lines changed

Tests/test_file_ani.py

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@
66

77
from PIL import Image
88

9+
from .helper import assert_image_equal_tofile
10+
911

1012
def test_aero_busy() -> None:
1113
with Image.open("Tests/images/ani/aero_busy.ani") as im:
1214
assert im.size == (64, 64)
1315
assert im.n_frames == 18
1416

15-
with Image.open("Tests/images/ani/aero_busy_0.png") as png:
16-
assert png.tobytes() == im.tobytes()
17+
assert_image_equal_tofile(im, "Tests/images/ani/aero_busy_0.png")
1718

1819
im.seek(8)
19-
with Image.open("Tests/images/ani/aero_busy_8.png") as png:
20-
assert png.tobytes() == im.tobytes()
20+
assert_image_equal_tofile(im, "Tests/images/ani/aero_busy_8.png")
2121

2222
with pytest.raises(EOFError):
2323
im.seek(-1)
@@ -31,44 +31,33 @@ def test_posy_busy() -> None:
3131
assert im.size == (96, 96)
3232
assert im.n_frames == 77
3333

34-
with Image.open("Tests/images/ani/posy_busy_0.png") as png:
35-
assert png.tobytes() == im.tobytes()
34+
assert_image_equal_tofile(im, "Tests/images/ani/posy_busy_0.png")
3635

3736
im.seek(24)
38-
with Image.open("Tests/images/ani/posy_busy_24.png") as png:
39-
assert png.tobytes() == im.tobytes()
37+
assert_image_equal_tofile(im, "Tests/images/ani/posy_busy_24.png")
4038

4139
with pytest.raises(EOFError):
4240
im.seek(77)
4341

4442

45-
def test_stopwtch() -> None:
43+
def test_seq_rate() -> None:
4644
with Image.open("Tests/images/ani/stopwtch.ani") as im:
4745
assert im.size == (32, 32)
4846
assert im.n_frames == 8
4947

50-
assert im.info["seq"][0] == 0
51-
assert im.info["seq"][2] == 0
52-
53-
for i, r in enumerate(im.info["rate"]):
54-
if i == 1 or i == 2:
55-
assert r == 16
56-
else:
57-
assert r == 8
48+
assert im.info["seq"][:3] == [0, 1, 0]
49+
assert im.info["rate"] == [8, 16, 16] + [8] * 42
5850

59-
with Image.open("Tests/images/ani/stopwtch_0.png") as png:
60-
assert png.tobytes() == im.tobytes()
51+
assert_image_equal_tofile(im, "Tests/images/ani/stopwtch_0.png")
6152

6253
im.seek(5)
63-
with Image.open("Tests/images/ani/stopwtch_5.png") as png:
64-
assert png.tobytes() == im.tobytes()
54+
assert_image_equal_tofile(im, "Tests/images/ani/stopwtch_5.png")
6555

6656
with pytest.raises(EOFError):
6757
im.seek(8)
6858

6959

7060
def test_save() -> None:
71-
directory_path = "Tests/images/ani/"
7261
filenames = [
7362
"aero_busy_0.png",
7463
"aero_busy_8.png",
@@ -78,7 +67,7 @@ def test_save() -> None:
7867
"stopwtch_5.png",
7968
]
8069

81-
images = [Image.open(directory_path + filename) for filename in filenames]
70+
images = [Image.open("Tests/images/ani/" + filename) for filename in filenames]
8271

8372
with BytesIO() as output:
8473
images[0].save(

Tests/test_file_cur.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@
66

77
from PIL import CurImagePlugin, Image
88

9+
from .helper import assert_image_equal_tofile
910

10-
def test_deerstalker() -> None:
11+
12+
def test_sanity() -> None:
1113
with Image.open("Tests/images/cur/deerstalker.cur") as im:
1214
assert im.size == (32, 32)
1315
assert im.info["hotspots"] == [(0, 0)]
1416
assert isinstance(im, CurImagePlugin.CurImageFile)
15-
# Check some pixel colors to ensure image is loaded properly
17+
18+
# Check pixel colors to ensure image is loaded properly
1619
assert im.getpixel((10, 1)) == (0, 0, 0, 0)
1720
assert im.getpixel((11, 1)) == (253, 254, 254, 1)
1821
assert im.getpixel((16, 16)) == (84, 87, 86, 255)
@@ -23,7 +26,8 @@ def test_posy_link() -> None:
2326
assert im.size == (128, 128)
2427
assert im.info["sizes"] == {(128, 128), (96, 96), (64, 64), (48, 48), (32, 32)}
2528
assert im.info["hotspots"] == [(25, 7), (18, 5), (12, 3), (9, 2), (5, 1)]
26-
# check some pixel colors
29+
30+
# check pixel colors
2731
assert im.getpixel((0, 0)) == (0, 0, 0, 0)
2832
assert im.getpixel((20, 20)) == (0, 0, 0, 255)
2933
assert im.getpixel((40, 40)) == (255, 255, 255, 255)
@@ -79,9 +83,7 @@ def test_save_win98_arrow() -> None:
7983
hotspots=[(10, 10)],
8084
bitmap_format="bmp",
8185
)
82-
83-
with Image.open(output) as reloaded:
84-
assert im.tobytes() == reloaded.tobytes()
86+
assert_image_equal_tofile(im, output)
8587

8688
with BytesIO() as output:
8789
im.save(output, format="CUR")
@@ -120,11 +122,10 @@ def test_save_posy_link() -> None:
120122
# make sure saved output is readable
121123
# and sizes/hotspots are correct
122124
with Image.open(output, formats=["CUR"]) as reloaded:
123-
assert (48, 48) == reloaded.size
124-
assert set(sizes[3:]) == reloaded.info["sizes"]
125+
assert reloaded.size == (48, 48)
126+
assert reloaded.info["sizes"] == set(sizes[3:])
125127

126-
# make sure error is thrown when size and hotspot len's
127-
# don't match
128+
# check error is thrown when size and hotspot length don't match
128129
with pytest.raises(ValueError):
129130
im.save(
130131
output,

0 commit comments

Comments
 (0)