Skip to content

Commit 058b8d3

Browse files
authored
Merge pull request #5275 from radarhere/tofile
2 parents 1857bf5 + 3495b31 commit 058b8d3

36 files changed

Lines changed: 310 additions & 392 deletions

Tests/test_file_blp.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
from PIL import Image
22

3-
from .helper import assert_image_equal
3+
from .helper import assert_image_equal_tofile
44

55

66
def test_load_blp2_raw():
77
with Image.open("Tests/images/blp/blp2_raw.blp") as im:
8-
with Image.open("Tests/images/blp/blp2_raw.png") as target:
9-
assert_image_equal(im, target)
8+
assert_image_equal_tofile(im, "Tests/images/blp/blp2_raw.png")
109

1110

1211
def test_load_blp2_dxt1():
1312
with Image.open("Tests/images/blp/blp2_dxt1.blp") as im:
14-
with Image.open("Tests/images/blp/blp2_dxt1.png") as target:
15-
assert_image_equal(im, target)
13+
assert_image_equal_tofile(im, "Tests/images/blp/blp2_dxt1.png")
1614

1715

1816
def test_load_blp2_dxt1a():
1917
with Image.open("Tests/images/blp/blp2_dxt1a.blp") as im:
20-
with Image.open("Tests/images/blp/blp2_dxt1a.png") as target:
21-
assert_image_equal(im, target)
18+
assert_image_equal_tofile(im, "Tests/images/blp/blp2_dxt1a.png")

Tests/test_file_bmp.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from PIL import BmpImagePlugin, Image
66

7-
from .helper import assert_image_equal, hopper
7+
from .helper import assert_image_equal, assert_image_equal_tofile, hopper
88

99

1010
def test_sanity(tmp_path):
@@ -111,8 +111,7 @@ def test_load_dib():
111111
assert im.format == "DIB"
112112
assert im.get_format_mimetype() == "image/bmp"
113113

114-
with Image.open("Tests/images/clipboard_target.png") as target:
115-
assert_image_equal(im, target)
114+
assert_image_equal_tofile(im, "Tests/images/clipboard_target.png")
116115

117116

118117
def test_save_dib(tmp_path):
@@ -136,5 +135,4 @@ def test_rgba_bitfields():
136135
b, g, r = im.split()[1:]
137136
im = Image.merge("RGB", (r, g, b))
138137

139-
with Image.open("Tests/images/bmp/q/rgb32bf-xbgr.bmp") as target:
140-
assert_image_equal(im, target)
138+
assert_image_equal_tofile(im, "Tests/images/bmp/q/rgb32bf-xbgr.bmp")

Tests/test_file_dds.py

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from PIL import DdsImagePlugin, Image
77

8-
from .helper import assert_image_equal
8+
from .helper import assert_image_equal, assert_image_equal_tofile
99

1010
TEST_FILE_DXT1 = "Tests/images/dxt1-rgb-4bbp-noalpha_MipMaps-1.dds"
1111
TEST_FILE_DXT3 = "Tests/images/dxt3-argb-8bbp-explicitalpha_MipMaps-1.dds"
@@ -41,22 +41,20 @@ def test_sanity_dxt5():
4141
assert im.mode == "RGBA"
4242
assert im.size == (256, 256)
4343

44-
with Image.open(TEST_FILE_DXT5.replace(".dds", ".png")) as target:
45-
assert_image_equal(target, im)
44+
assert_image_equal_tofile(im, TEST_FILE_DXT5.replace(".dds", ".png"))
4645

4746

4847
def test_sanity_dxt3():
4948
"""Check DXT3 images can be opened"""
5049

51-
with Image.open(TEST_FILE_DXT3.replace(".dds", ".png")) as target:
52-
with Image.open(TEST_FILE_DXT3) as im:
53-
im.load()
50+
with Image.open(TEST_FILE_DXT3) as im:
51+
im.load()
5452

55-
assert im.format == "DDS"
56-
assert im.mode == "RGBA"
57-
assert im.size == (256, 256)
53+
assert im.format == "DDS"
54+
assert im.mode == "RGBA"
55+
assert im.size == (256, 256)
5856

59-
assert_image_equal(target, im)
57+
assert_image_equal_tofile(im, TEST_FILE_DXT3.replace(".dds", ".png"))
6058

6159

6260
def test_dx10_bc7():
@@ -69,8 +67,7 @@ def test_dx10_bc7():
6967
assert im.mode == "RGBA"
7068
assert im.size == (256, 256)
7169

72-
with Image.open(TEST_FILE_DX10_BC7.replace(".dds", ".png")) as target:
73-
assert_image_equal(target, im)
70+
assert_image_equal_tofile(im, TEST_FILE_DX10_BC7.replace(".dds", ".png"))
7471

7572

7673
def test_dx10_bc7_unorm_srgb():
@@ -84,10 +81,9 @@ def test_dx10_bc7_unorm_srgb():
8481
assert im.size == (16, 16)
8582
assert im.info["gamma"] == 1 / 2.2
8683

87-
with Image.open(
88-
TEST_FILE_DX10_BC7_UNORM_SRGB.replace(".dds", ".png")
89-
) as target:
90-
assert_image_equal(target, im)
84+
assert_image_equal_tofile(
85+
im, TEST_FILE_DX10_BC7_UNORM_SRGB.replace(".dds", ".png")
86+
)
9187

9288

9389
def test_dx10_r8g8b8a8():
@@ -100,8 +96,7 @@ def test_dx10_r8g8b8a8():
10096
assert im.mode == "RGBA"
10197
assert im.size == (256, 256)
10298

103-
with Image.open(TEST_FILE_DX10_R8G8B8A8.replace(".dds", ".png")) as target:
104-
assert_image_equal(target, im)
99+
assert_image_equal_tofile(im, TEST_FILE_DX10_R8G8B8A8.replace(".dds", ".png"))
105100

106101

107102
def test_dx10_r8g8b8a8_unorm_srgb():
@@ -115,10 +110,9 @@ def test_dx10_r8g8b8a8_unorm_srgb():
115110
assert im.size == (16, 16)
116111
assert im.info["gamma"] == 1 / 2.2
117112

118-
with Image.open(
119-
TEST_FILE_DX10_R8G8B8A8_UNORM_SRGB.replace(".dds", ".png")
120-
) as target:
121-
assert_image_equal(target, im)
113+
assert_image_equal_tofile(
114+
im, TEST_FILE_DX10_R8G8B8A8_UNORM_SRGB.replace(".dds", ".png")
115+
)
122116

123117

124118
def test_unimplemented_dxgi_format():
@@ -137,8 +131,9 @@ def test_uncompressed_rgb():
137131
assert im.mode == "RGBA"
138132
assert im.size == (800, 600)
139133

140-
with Image.open(TEST_FILE_UNCOMPRESSED_RGB.replace(".dds", ".png")) as target:
141-
assert_image_equal(target, im)
134+
assert_image_equal_tofile(
135+
im, TEST_FILE_UNCOMPRESSED_RGB.replace(".dds", ".png")
136+
)
142137

143138

144139
def test__validate_true():

Tests/test_file_eps.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44

55
from PIL import EpsImagePlugin, Image, features
66

7-
from .helper import assert_image_similar, hopper, skip_unless_feature
7+
from .helper import (
8+
assert_image_similar,
9+
assert_image_similar_tofile,
10+
hopper,
11+
skip_unless_feature,
12+
)
813

914
HAS_GHOSTSCRIPT = EpsImagePlugin.has_ghostscript()
1015

@@ -72,8 +77,9 @@ def test_cmyk():
7277
assert cmyk_image.mode == "RGB"
7378

7479
if features.check("jpg"):
75-
with Image.open("Tests/images/pil_sample_rgb.jpg") as target:
76-
assert_image_similar(cmyk_image, target, 10)
80+
assert_image_similar_tofile(
81+
cmyk_image, "Tests/images/pil_sample_rgb.jpg", 10
82+
)
7783

7884

7985
@pytest.mark.skipif(not HAS_GHOSTSCRIPT, reason="Ghostscript not available")

Tests/test_file_fli.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from PIL import FliImagePlugin, Image
44

5-
from .helper import assert_image_equal, is_pypy
5+
from .helper import assert_image_equal_tofile, is_pypy
66

77
# created as an export of a palette image from Gimp2.6
88
# save as...-> hopper.fli, default options.
@@ -122,5 +122,4 @@ def test_seek():
122122
with Image.open(animated_test_file) as im:
123123
im.seek(50)
124124

125-
with Image.open("Tests/images/a_fli.png") as expected:
126-
assert_image_equal(im, expected)
125+
assert_image_equal_tofile(im, "Tests/images/a_fli.png")

Tests/test_file_ftex.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
from PIL import Image
22

3-
from .helper import assert_image_equal, assert_image_similar
3+
from .helper import assert_image_equal_tofile, assert_image_similar
44

55

66
def test_load_raw():
77
with Image.open("Tests/images/ftex_uncompressed.ftu") as im:
8-
with Image.open("Tests/images/ftex_uncompressed.png") as target:
9-
assert_image_equal(im, target)
8+
assert_image_equal_tofile(im, "Tests/images/ftex_uncompressed.png")
109

1110

1211
def test_load_dxt1():

Tests/test_file_gbr.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from PIL import GbrImagePlugin, Image
44

5-
from .helper import assert_image_equal
5+
from .helper import assert_image_equal_tofile
66

77

88
def test_invalid_file():
@@ -14,13 +14,11 @@ def test_invalid_file():
1414

1515
def test_gbr_file():
1616
with Image.open("Tests/images/gbr.gbr") as im:
17-
with Image.open("Tests/images/gbr.png") as target:
18-
assert_image_equal(target, im)
17+
assert_image_equal_tofile(im, "Tests/images/gbr.png")
1918

2019

2120
def test_multiple_load_operations():
2221
with Image.open("Tests/images/gbr.gbr") as im:
2322
im.load()
2423
im.load()
25-
with Image.open("Tests/images/gbr.png") as target:
26-
assert_image_equal(target, im)
24+
assert_image_equal_tofile(im, "Tests/images/gbr.png")

Tests/test_file_gif.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from .helper import (
88
assert_image_equal,
9+
assert_image_equal_tofile,
910
assert_image_similar,
1011
hopper,
1112
is_pypy,
@@ -317,8 +318,7 @@ def test_dispose_none_load_end():
317318
with Image.open("Tests/images/dispose_none_load_end.gif") as img:
318319
img.seek(1)
319320

320-
with Image.open("Tests/images/dispose_none_load_end_second.gif") as expected:
321-
assert_image_equal(img, expected)
321+
assert_image_equal_tofile(img, "Tests/images/dispose_none_load_end_second.gif")
322322

323323

324324
def test_dispose_background():
@@ -629,8 +629,7 @@ def test_comment_over_255(tmp_path):
629629

630630
def test_zero_comment_subblocks():
631631
with Image.open("Tests/images/hopper_zero_comment_subblocks.gif") as im:
632-
with Image.open(TEST_GIF) as expected:
633-
assert_image_equal(im, expected)
632+
assert_image_equal_tofile(im, TEST_GIF)
634633

635634

636635
def test_version(tmp_path):

Tests/test_file_icns.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from PIL import IcnsImagePlugin, Image, features
77

8-
from .helper import assert_image_equal, assert_image_similar
8+
from .helper import assert_image_equal, assert_image_similar_tofile
99

1010
# sample icon file
1111
TEST_FILE = "Tests/images/pillow.icns"
@@ -49,8 +49,7 @@ def test_save_append_images(tmp_path):
4949
with Image.open(TEST_FILE) as im:
5050
im.save(temp_file, append_images=[provided_im])
5151

52-
with Image.open(temp_file) as reread:
53-
assert_image_similar(reread, im, 1)
52+
assert_image_similar_tofile(im, temp_file, 1)
5453

5554
with Image.open(temp_file) as reread:
5655
reread.size = (16, 16, 2)

Tests/test_file_ico.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from PIL import IcoImagePlugin, Image, ImageDraw
66

7-
from .helper import assert_image_equal, hopper
7+
from .helper import assert_image_equal, assert_image_equal_tofile, hopper
88

99
TEST_ICO_FILE = "Tests/images/hopper.ico"
1010

@@ -120,5 +120,4 @@ def test_draw_reloaded(tmp_path):
120120

121121
with Image.open(outfile) as im:
122122
im.save("Tests/images/hopper_draw.ico")
123-
with Image.open("Tests/images/hopper_draw.ico") as reloaded:
124-
assert_image_equal(im, reloaded)
123+
assert_image_equal_tofile(im, "Tests/images/hopper_draw.ico")

0 commit comments

Comments
 (0)