@@ -130,9 +130,7 @@ def test_comment_write(self) -> None:
130
130
def test_cmyk (self ) -> None :
131
131
# Test CMYK handling. Thanks to Tim and Charlie for test data,
132
132
# Michael for getting me to look one more time.
133
- f = "Tests/images/pil_sample_cmyk.jpg"
134
- with Image .open (f ) as im :
135
- # the source image has red pixels in the upper left corner.
133
+ def check (im : ImageFile .ImageFile ) -> None :
136
134
cmyk = im .getpixel ((0 , 0 ))
137
135
assert isinstance (cmyk , tuple )
138
136
c , m , y , k = (x / 255.0 for x in cmyk )
@@ -145,19 +143,13 @@ def test_cmyk(self) -> None:
145
143
assert isinstance (cmyk , tuple )
146
144
k = cmyk [3 ] / 255.0
147
145
assert k > 0.9
146
+
147
+ with Image .open ("Tests/images/pil_sample_cmyk.jpg" ) as im :
148
+ # the source image has red pixels in the upper left corner.
149
+ check (im )
150
+
148
151
# roundtrip, and check again
149
- im = self .roundtrip (im )
150
- cmyk = im .getpixel ((0 , 0 ))
151
- assert isinstance (cmyk , tuple )
152
- c , m , y , k = (x / 255.0 for x in cmyk )
153
- assert c == 0.0
154
- assert m > 0.8
155
- assert y > 0.8
156
- assert k == 0.0
157
- cmyk = im .getpixel ((im .size [0 ] - 1 , im .size [1 ] - 1 ))
158
- assert isinstance (cmyk , tuple )
159
- k = cmyk [3 ] / 255.0
160
- assert k > 0.9
152
+ check (self .roundtrip (im ))
161
153
162
154
def test_rgb (self ) -> None :
163
155
def getchannels (im : JpegImagePlugin .JpegImageFile ) -> tuple [int , ...]:
0 commit comments