Merge pull request #6865 from Yay295/test_cleanup_s

Clean up tests (simplified)
This commit is contained in:
mergify[bot] 2023-01-07 08:49:45 +00:00 committed by GitHub
commit 6c7d6cf4a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 41 deletions

View File

@ -135,16 +135,15 @@ class TestImagingCoreResampleAccuracy:
@pytest.mark.parametrize("mode", ("RGBX", "RGB", "La", "L"))
def test_reduce_bicubic(self, mode):
for mode in ["RGBX", "RGB", "La", "L"]:
case = self.make_case(mode, (12, 12), 0xE1)
case = case.resize((6, 6), Image.Resampling.BICUBIC)
# fmt: off
data = ("e1 e3 d4"
"e3 e5 d6"
"d4 d6 c9")
# fmt: on
for channel in case.split():
self.check_case(channel, self.make_sample(data, (6, 6)))
case = self.make_case(mode, (12, 12), 0xE1)
case = case.resize((6, 6), Image.Resampling.BICUBIC)
# fmt: off
data = ("e1 e3 d4"
"e3 e5 d6"
"d4 d6 c9")
# fmt: on
for channel in case.split():
self.check_case(channel, self.make_sample(data, (6, 6)))
@pytest.mark.parametrize("mode", ("RGBX", "RGB", "La", "L"))
def test_reduce_lanczos(self, mode):

View File

@ -42,12 +42,12 @@ class TestImageTransform:
def test_extent(self):
im = hopper("RGB")
(w, h) = im.size
# fmt: off
transformed = im.transform(im.size, Image.Transform.EXTENT,
(0, 0,
w//2, h//2), # ul -> lr
Image.Resampling.BILINEAR)
# fmt: on
transformed = im.transform(
im.size,
Image.Transform.EXTENT,
(0, 0, w // 2, h // 2), # ul -> lr
Image.Resampling.BILINEAR,
)
scaled = im.resize((w * 2, h * 2), Image.Resampling.BILINEAR).crop((0, 0, w, h))
@ -58,13 +58,12 @@ class TestImageTransform:
# one simple quad transform, equivalent to scale & crop upper left quad
im = hopper("RGB")
(w, h) = im.size
# fmt: off
transformed = im.transform(im.size, Image.Transform.QUAD,
(0, 0, 0, h//2,
# ul -> ccw around quad:
w//2, h//2, w//2, 0),
Image.Resampling.BILINEAR)
# fmt: on
transformed = im.transform(
im.size,
Image.Transform.QUAD,
(0, 0, 0, h // 2, w // 2, h // 2, w // 2, 0), # ul -> ccw around quad
Image.Resampling.BILINEAR,
)
scaled = im.transform(
(w, h),
@ -99,16 +98,21 @@ class TestImageTransform:
# this should be a checkerboard of halfsized hoppers in ul, lr
im = hopper("RGBA")
(w, h) = im.size
# fmt: off
transformed = im.transform(im.size, Image.Transform.MESH,
[((0, 0, w//2, h//2), # box
(0, 0, 0, h,
w, h, w, 0)), # ul -> ccw around quad
((w//2, h//2, w, h), # box
(0, 0, 0, h,
w, h, w, 0))], # ul -> ccw around quad
Image.Resampling.BILINEAR)
# fmt: on
transformed = im.transform(
im.size,
Image.Transform.MESH,
(
(
(0, 0, w // 2, h // 2), # box
(0, 0, 0, h, w, h, w, 0), # ul -> ccw around quad
),
(
(w // 2, h // 2, w, h), # box
(0, 0, 0, h, w, h, w, 0), # ul -> ccw around quad
),
),
Image.Resampling.BILINEAR,
)
scaled = im.transform(
(w // 2, h // 2),
@ -174,11 +178,13 @@ class TestImageTransform:
im = op(im, (40, 10))
colors = im.getcolors()
assert colors == [
(20 * 10, opaque),
(20 * 10, transparent),
]
colors = sorted(im.getcolors())
assert colors == sorted(
(
(20 * 10, opaque),
(20 * 10, transparent),
)
)
@pytest.mark.parametrize("mode", ("RGBA", "LA"))
def test_nearest_resize(self, mode):

View File

@ -88,9 +88,8 @@ def test_parsing():
b"D:20180729214124+08'00'": "20180729134124",
b"D:20180729214124-05'00'": "20180730024124",
}.items():
d = PdfParser.get_value(b"<</" + name.encode() + b" (" + date + b")>>", 0)[
0
]
b = b"<</" + name.encode() + b" (" + date + b")>>"
d = PdfParser.get_value(b, 0)[0]
assert time.strftime("%Y%m%d%H%M%S", getattr(d, name)) == value