mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-12 18:26:17 +03:00
Apply suggestions from code review
Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
This commit is contained in:
parent
2fd3cb55d2
commit
09a7255ced
|
@ -74,7 +74,7 @@ def test_modefilter(mode, expected):
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"mode,expected",
|
"mode, expected",
|
||||||
(
|
(
|
||||||
("1", (0, 4, 8)),
|
("1", (0, 4, 8)),
|
||||||
("L", (0, 4, 8)),
|
("L", (0, 4, 8)),
|
||||||
|
|
|
@ -39,7 +39,7 @@ gradients_image.load()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"size,expected",
|
"size, expected",
|
||||||
(
|
(
|
||||||
(3, (4, 4)),
|
(3, (4, 4)),
|
||||||
((3, 1), (4, 10)),
|
((3, 1), (4, 10)),
|
||||||
|
@ -52,16 +52,16 @@ def test_args_factor(size, expected):
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"size,error", ((0, ValueError), (2.0, TypeError), ((0, 10), ValueError))
|
"size, expected_error", ((0, ValueError), (2.0, TypeError), ((0, 10), ValueError))
|
||||||
)
|
)
|
||||||
def test_args_factor_error(size, error):
|
def test_args_factor_error(size, expected_error):
|
||||||
im = Image.new("L", (10, 10))
|
im = Image.new("L", (10, 10))
|
||||||
with pytest.raises(error):
|
with pytest.raises(expected_error):
|
||||||
im.reduce(size)
|
im.reduce(size)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"size,expected",
|
"size, expected",
|
||||||
(
|
(
|
||||||
((0, 0, 10, 10), (5, 5)),
|
((0, 0, 10, 10), (5, 5)),
|
||||||
((5, 5, 6, 6), (1, 1)),
|
((5, 5, 6, 6), (1, 1)),
|
||||||
|
@ -73,7 +73,7 @@ def test_args_box(size, expected):
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"size,error",
|
"size, expected_error",
|
||||||
(
|
(
|
||||||
("stri", TypeError),
|
("stri", TypeError),
|
||||||
((0, 0, 11, 10), ValueError),
|
((0, 0, 11, 10), ValueError),
|
||||||
|
@ -84,9 +84,9 @@ def test_args_box(size, expected):
|
||||||
((5, 0, 5, 10), ValueError),
|
((5, 0, 5, 10), ValueError),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
def test_args_box_error(size, error):
|
def test_args_box_error(size, expected_error):
|
||||||
im = Image.new("L", (10, 10))
|
im = Image.new("L", (10, 10))
|
||||||
with pytest.raises(error):
|
with pytest.raises(expected_error):
|
||||||
im.reduce(2, size).size
|
im.reduce(2, size).size
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -76,14 +76,14 @@ class TestImageTransform:
|
||||||
assert_image_equal(transformed, scaled)
|
assert_image_equal(transformed, scaled)
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"mode,pixel",
|
"mode, expected_pixel",
|
||||||
(
|
(
|
||||||
("RGB", (255, 0, 0)),
|
("RGB", (255, 0, 0)),
|
||||||
("RGBA", (255, 0, 0, 255)),
|
("RGBA", (255, 0, 0, 255)),
|
||||||
("LA", (76, 0)),
|
("LA", (76, 0)),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
def test_fill(self, mode, pixel):
|
def test_fill(self, mode, expected_pixel):
|
||||||
im = hopper(mode)
|
im = hopper(mode)
|
||||||
(w, h) = im.size
|
(w, h) = im.size
|
||||||
transformed = im.transform(
|
transformed = im.transform(
|
||||||
|
@ -93,7 +93,7 @@ class TestImageTransform:
|
||||||
Image.Resampling.BILINEAR,
|
Image.Resampling.BILINEAR,
|
||||||
fillcolor="red",
|
fillcolor="red",
|
||||||
)
|
)
|
||||||
assert transformed.getpixel((w - 1, h - 1)) == pixel
|
assert transformed.getpixel((w - 1, h - 1)) == expected_pixel
|
||||||
|
|
||||||
def test_mesh(self):
|
def test_mesh(self):
|
||||||
# this should be a checkerboard of halfsized hoppers in ul, lr
|
# this should be a checkerboard of halfsized hoppers in ul, lr
|
||||||
|
@ -240,7 +240,7 @@ class TestImageTransformAffine:
|
||||||
return im.crop((10, 20, im.width - 10, im.height - 20))
|
return im.crop((10, 20, im.width - 10, im.height - 20))
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"deg,transpose",
|
"deg, transpose",
|
||||||
(
|
(
|
||||||
(0, None),
|
(0, None),
|
||||||
(90, Image.Transpose.ROTATE_90),
|
(90, Image.Transpose.ROTATE_90),
|
||||||
|
@ -281,7 +281,7 @@ class TestImageTransformAffine:
|
||||||
assert_image_equal(transposed, transformed)
|
assert_image_equal(transposed, transformed)
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"scale,epsilonscale",
|
"scale, epsilon_scale",
|
||||||
(
|
(
|
||||||
(1.1, 6.9),
|
(1.1, 6.9),
|
||||||
(1.5, 5.5),
|
(1.5, 5.5),
|
||||||
|
@ -298,7 +298,7 @@ class TestImageTransformAffine:
|
||||||
(Image.Resampling.BICUBIC, 1),
|
(Image.Resampling.BICUBIC, 1),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
def test_resize(self, scale, epsilonscale, resample, epsilon):
|
def test_resize(self, scale, epsilon_scale, resample, epsilon):
|
||||||
im = self._test_image()
|
im = self._test_image()
|
||||||
|
|
||||||
size_up = int(round(im.width * scale)), int(round(im.height * scale))
|
size_up = int(round(im.width * scale)), int(round(im.height * scale))
|
||||||
|
@ -309,10 +309,10 @@ class TestImageTransformAffine:
|
||||||
transformed = transformed.transform(
|
transformed = transformed.transform(
|
||||||
im.size, self.transform, matrix_down, resample
|
im.size, self.transform, matrix_down, resample
|
||||||
)
|
)
|
||||||
assert_image_similar(transformed, im, epsilon * epsilonscale)
|
assert_image_similar(transformed, im, epsilon * epsilon_scale)
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"x,y,epsilonscale",
|
"x, y, epsilon_scale",
|
||||||
(
|
(
|
||||||
(0.1, 0, 3.7),
|
(0.1, 0, 3.7),
|
||||||
(0.6, 0, 9.1),
|
(0.6, 0, 9.1),
|
||||||
|
@ -320,14 +320,14 @@ class TestImageTransformAffine:
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"resample,epsilon",
|
"resample, epsilon",
|
||||||
(
|
(
|
||||||
(Image.Resampling.NEAREST, 0),
|
(Image.Resampling.NEAREST, 0),
|
||||||
(Image.Resampling.BILINEAR, 1.5),
|
(Image.Resampling.BILINEAR, 1.5),
|
||||||
(Image.Resampling.BICUBIC, 1),
|
(Image.Resampling.BICUBIC, 1),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
def test_translate(self, x, y, epsilonscale, resample, epsilon):
|
def test_translate(self, x, y, epsilon_scale, resample, epsilon):
|
||||||
im = self._test_image()
|
im = self._test_image()
|
||||||
|
|
||||||
size_up = int(round(im.width + x)), int(round(im.height + y))
|
size_up = int(round(im.width + x)), int(round(im.height + y))
|
||||||
|
@ -338,7 +338,7 @@ class TestImageTransformAffine:
|
||||||
transformed = transformed.transform(
|
transformed = transformed.transform(
|
||||||
im.size, self.transform, matrix_down, resample
|
im.size, self.transform, matrix_down, resample
|
||||||
)
|
)
|
||||||
assert_image_similar(transformed, im, epsilon * epsilonscale)
|
assert_image_similar(transformed, im, epsilon * epsilon_scale)
|
||||||
|
|
||||||
|
|
||||||
class TestImageTransformPerspective(TestImageTransformAffine):
|
class TestImageTransformPerspective(TestImageTransformAffine):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user