Skip to content

Commit 04c984f

Browse files
committed
Removed duplicate code
1 parent 89c3825 commit 04c984f

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

Tests/test_file_jpeg.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,7 @@ def test_comment_write(self) -> None:
130130
def test_cmyk(self) -> None:
131131
# Test CMYK handling. Thanks to Tim and Charlie for test data,
132132
# 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:
136134
cmyk = im.getpixel((0, 0))
137135
assert isinstance(cmyk, tuple)
138136
c, m, y, k = (x / 255.0 for x in cmyk)
@@ -145,19 +143,13 @@ def test_cmyk(self) -> None:
145143
assert isinstance(cmyk, tuple)
146144
k = cmyk[3] / 255.0
147145
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+
148151
# 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))
161153

162154
def test_rgb(self) -> None:
163155
def getchannels(im: JpegImagePlugin.JpegImageFile) -> tuple[int, ...]:

0 commit comments

Comments
 (0)