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")) @pytest.mark.parametrize("mode", ("RGBX", "RGB", "La", "L"))
def test_reduce_bicubic(self, mode): def test_reduce_bicubic(self, mode):
for mode in ["RGBX", "RGB", "La", "L"]: case = self.make_case(mode, (12, 12), 0xE1)
case = self.make_case(mode, (12, 12), 0xE1) case = case.resize((6, 6), Image.Resampling.BICUBIC)
case = case.resize((6, 6), Image.Resampling.BICUBIC) # fmt: off
# fmt: off data = ("e1 e3 d4"
data = ("e1 e3 d4" "e3 e5 d6"
"e3 e5 d6" "d4 d6 c9")
"d4 d6 c9") # fmt: on
# fmt: on for channel in case.split():
for channel in case.split(): self.check_case(channel, self.make_sample(data, (6, 6)))
self.check_case(channel, self.make_sample(data, (6, 6)))
@pytest.mark.parametrize("mode", ("RGBX", "RGB", "La", "L")) @pytest.mark.parametrize("mode", ("RGBX", "RGB", "La", "L"))
def test_reduce_lanczos(self, mode): def test_reduce_lanczos(self, mode):

View File

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

View File

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