Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up tests (simplified) #6865

Merged
merged 4 commits into from Jan 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 9 additions & 10 deletions Tests/test_image_resample.py
Expand Up @@ -135,16 +135,15 @@ def test_reduce_hamming(self, mode):

@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):
Expand Down
62 changes: 34 additions & 28 deletions Tests/test_image_transform.py
Expand Up @@ -42,12 +42,12 @@ def test_palette(self):
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))

Expand All @@ -58,13 +58,12 @@ def test_quad(self):
# 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),
Expand Down Expand Up @@ -99,16 +98,21 @@ def test_mesh(self):
# 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),
Expand Down Expand Up @@ -174,11 +178,13 @@ def _test_nearest(self, op, mode):

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):
Expand Down
5 changes: 2 additions & 3 deletions Tests/test_pdfparser.py
Expand Up @@ -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


Expand Down