mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 17:36:18 +03:00
Parametrize tests
This commit is contained in:
parent
0f3e8e5573
commit
0ed03d4a58
|
@ -325,8 +325,9 @@ def test_apng_syntax_errors():
|
|||
pytest.warns(UserWarning, open)
|
||||
|
||||
|
||||
def test_apng_sequence_errors():
|
||||
test_files = [
|
||||
@pytest.mark.parametrize(
|
||||
"f",
|
||||
(
|
||||
"sequence_start.png",
|
||||
"sequence_gap.png",
|
||||
"sequence_repeat.png",
|
||||
|
@ -334,8 +335,9 @@ def test_apng_sequence_errors():
|
|||
"sequence_reorder.png",
|
||||
"sequence_reorder_chunk.png",
|
||||
"sequence_fdat_fctl.png",
|
||||
]
|
||||
for f in test_files:
|
||||
),
|
||||
)
|
||||
def test_apng_sequence_errors(f):
|
||||
with pytest.raises(SyntaxError):
|
||||
with Image.open(f"Tests/images/apng/{f}") as im:
|
||||
im.seek(im.n_frames - 1)
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import pytest
|
||||
|
||||
from PIL import ContainerIO, Image
|
||||
|
||||
from .helper import hopper
|
||||
|
@ -59,9 +61,9 @@ def test_seek_mode_2():
|
|||
assert container.tell() == 100
|
||||
|
||||
|
||||
def test_read_n0():
|
||||
@pytest.mark.parametrize("bytesmode", (True, False))
|
||||
def test_read_n0(bytesmode):
|
||||
# Arrange
|
||||
for bytesmode in (True, False):
|
||||
with open(TEST_FILE, "rb" if bytesmode else "r") as fh:
|
||||
container = ContainerIO.ContainerIO(fh, 22, 100)
|
||||
|
||||
|
@ -75,9 +77,9 @@ def test_read_n0():
|
|||
assert data == "7\nThis is line 8\n"
|
||||
|
||||
|
||||
def test_read_n():
|
||||
@pytest.mark.parametrize("bytesmode", (True, False))
|
||||
def test_read_n(bytesmode):
|
||||
# Arrange
|
||||
for bytesmode in (True, False):
|
||||
with open(TEST_FILE, "rb" if bytesmode else "r") as fh:
|
||||
container = ContainerIO.ContainerIO(fh, 22, 100)
|
||||
|
||||
|
@ -91,9 +93,9 @@ def test_read_n():
|
|||
assert data == "7\nT"
|
||||
|
||||
|
||||
def test_read_eof():
|
||||
@pytest.mark.parametrize("bytesmode", (True, False))
|
||||
def test_read_eof(bytesmode):
|
||||
# Arrange
|
||||
for bytesmode in (True, False):
|
||||
with open(TEST_FILE, "rb" if bytesmode else "r") as fh:
|
||||
container = ContainerIO.ContainerIO(fh, 22, 100)
|
||||
|
||||
|
@ -107,9 +109,9 @@ def test_read_eof():
|
|||
assert data == ""
|
||||
|
||||
|
||||
def test_readline():
|
||||
@pytest.mark.parametrize("bytesmode", (True, False))
|
||||
def test_readline(bytesmode):
|
||||
# Arrange
|
||||
for bytesmode in (True, False):
|
||||
with open(TEST_FILE, "rb" if bytesmode else "r") as fh:
|
||||
container = ContainerIO.ContainerIO(fh, 0, 120)
|
||||
|
||||
|
@ -122,9 +124,9 @@ def test_readline():
|
|||
assert data == "This is line 1\n"
|
||||
|
||||
|
||||
def test_readlines():
|
||||
@pytest.mark.parametrize("bytesmode", (True, False))
|
||||
def test_readlines(bytesmode):
|
||||
# Arrange
|
||||
for bytesmode in (True, False):
|
||||
expected = [
|
||||
"This is line 1\n",
|
||||
"This is line 2\n",
|
||||
|
|
|
@ -78,16 +78,13 @@ def test_eoferror():
|
|||
im.seek(n_frames - 1)
|
||||
|
||||
|
||||
def test_roundtrip(tmp_path):
|
||||
def roundtrip(mode):
|
||||
@pytest.mark.parametrize("mode", ("RGB", "P", "PA"))
|
||||
def test_roundtrip(mode, tmp_path):
|
||||
out = str(tmp_path / "temp.im")
|
||||
im = hopper(mode)
|
||||
im.save(out)
|
||||
assert_image_equal_tofile(im, out)
|
||||
|
||||
for mode in ["RGB", "P", "PA"]:
|
||||
roundtrip(mode)
|
||||
|
||||
|
||||
def test_save_unsupported_mode(tmp_path):
|
||||
out = str(tmp_path / "temp.im")
|
||||
|
|
|
@ -135,9 +135,9 @@ class TestFileLibTiff(LibTiffTestCase):
|
|||
|
||||
assert_image_equal_tofile(im, "Tests/images/tiff_adobe_deflate.png")
|
||||
|
||||
def test_write_metadata(self, tmp_path):
|
||||
@pytest.mark.parametrize("legacy_api", (False, True))
|
||||
def test_write_metadata(self, legacy_api, tmp_path):
|
||||
"""Test metadata writing through libtiff"""
|
||||
for legacy_api in [False, True]:
|
||||
f = str(tmp_path / "temp.tiff")
|
||||
with Image.open("Tests/images/hopper_g4.tif") as img:
|
||||
img.save(f, tiffinfo=img.tag)
|
||||
|
|
|
@ -27,8 +27,8 @@ def roundtrip(im, **options):
|
|||
return im
|
||||
|
||||
|
||||
def test_sanity():
|
||||
for test_file in test_files:
|
||||
@pytest.mark.parametrize("test_file", test_files)
|
||||
def test_sanity(test_file):
|
||||
with Image.open(test_file) as im:
|
||||
im.load()
|
||||
assert im.mode == "RGB"
|
||||
|
@ -66,21 +66,20 @@ def test_context_manager():
|
|||
im.load()
|
||||
|
||||
|
||||
def test_app():
|
||||
for test_file in test_files:
|
||||
@pytest.mark.parametrize("test_file", test_files)
|
||||
def test_app(test_file):
|
||||
# Test APP/COM reader (@PIL135)
|
||||
with Image.open(test_file) as im:
|
||||
assert im.applist[0][0] == "APP1"
|
||||
assert im.applist[1][0] == "APP2"
|
||||
assert (
|
||||
im.applist[1][1][:16]
|
||||
== b"MPF\x00MM\x00*\x00\x00\x00\x08\x00\x03\xb0\x00"
|
||||
im.applist[1][1][:16] == b"MPF\x00MM\x00*\x00\x00\x00\x08\x00\x03\xb0\x00"
|
||||
)
|
||||
assert len(im.applist) == 2
|
||||
|
||||
|
||||
def test_exif():
|
||||
for test_file in test_files:
|
||||
@pytest.mark.parametrize("test_file", test_files)
|
||||
def test_exif(test_file):
|
||||
with Image.open(test_file) as im:
|
||||
info = im._getexif()
|
||||
assert info[272] == "Nintendo 3DS"
|
||||
|
@ -137,8 +136,8 @@ def test_reload_exif_after_seek():
|
|||
assert 296 in exif
|
||||
|
||||
|
||||
def test_mp():
|
||||
for test_file in test_files:
|
||||
@pytest.mark.parametrize("test_file", test_files)
|
||||
def test_mp(test_file):
|
||||
with Image.open(test_file) as im:
|
||||
mpinfo = im._getmp()
|
||||
assert mpinfo[45056] == b"0100"
|
||||
|
@ -162,8 +161,8 @@ def test_mp_no_data():
|
|||
im.seek(1)
|
||||
|
||||
|
||||
def test_mp_attribute():
|
||||
for test_file in test_files:
|
||||
@pytest.mark.parametrize("test_file", test_files)
|
||||
def test_mp_attribute(test_file):
|
||||
with Image.open(test_file) as im:
|
||||
mpinfo = im._getmp()
|
||||
frame_number = 0
|
||||
|
@ -181,8 +180,8 @@ def test_mp_attribute():
|
|||
frame_number += 1
|
||||
|
||||
|
||||
def test_seek():
|
||||
for test_file in test_files:
|
||||
@pytest.mark.parametrize("test_file", test_files)
|
||||
def test_seek(test_file):
|
||||
with Image.open(test_file) as im:
|
||||
assert im.tell() == 0
|
||||
# prior to first image raises an error, both blatant and borderline
|
||||
|
@ -225,8 +224,8 @@ def test_eoferror():
|
|||
im.seek(n_frames - 1)
|
||||
|
||||
|
||||
def test_image_grab():
|
||||
for test_file in test_files:
|
||||
@pytest.mark.parametrize("test_file", test_files)
|
||||
def test_image_grab(test_file):
|
||||
with Image.open(test_file) as im:
|
||||
assert im.tell() == 0
|
||||
im0 = im.tobytes()
|
||||
|
@ -240,8 +239,8 @@ def test_image_grab():
|
|||
assert im0 != im1
|
||||
|
||||
|
||||
def test_save():
|
||||
for test_file in test_files:
|
||||
@pytest.mark.parametrize("test_file", test_files)
|
||||
def test_save(test_file):
|
||||
with Image.open(test_file) as im:
|
||||
assert im.tell() == 0
|
||||
jpg0 = roundtrip(im)
|
||||
|
|
|
@ -18,18 +18,15 @@ _ORIGINS = ("tl", "bl")
|
|||
_ORIGIN_TO_ORIENTATION = {"tl": 1, "bl": -1}
|
||||
|
||||
|
||||
def test_sanity(tmp_path):
|
||||
for mode in _MODES:
|
||||
|
||||
@pytest.mark.parametrize("mode", _MODES)
|
||||
def test_sanity(mode, tmp_path):
|
||||
def roundtrip(original_im):
|
||||
out = str(tmp_path / "temp.tga")
|
||||
|
||||
original_im.save(out, rle=rle)
|
||||
with Image.open(out) as saved_im:
|
||||
if rle:
|
||||
assert (
|
||||
saved_im.info["compression"] == original_im.info["compression"]
|
||||
)
|
||||
assert saved_im.info["compression"] == original_im.info["compression"]
|
||||
assert saved_im.info["orientation"] == original_im.info["orientation"]
|
||||
if mode == "P":
|
||||
assert saved_im.getpalette() == original_im.getpalette()
|
||||
|
|
|
@ -66,10 +66,10 @@ def test_load_set_dpi():
|
|||
assert_image_similar_tofile(im, "Tests/images/drawing_wmf_ref_144.png", 2.1)
|
||||
|
||||
|
||||
def test_save(tmp_path):
|
||||
@pytest.mark.parametrize("ext", (".wmf", ".emf"))
|
||||
def test_save(ext, tmp_path):
|
||||
im = hopper()
|
||||
|
||||
for ext in [".wmf", ".emf"]:
|
||||
tmpfile = str(tmp_path / ("temp" + ext))
|
||||
with pytest.raises(OSError):
|
||||
im.save(tmpfile)
|
||||
|
|
|
@ -22,8 +22,9 @@ from .helper import (
|
|||
|
||||
|
||||
class TestImage:
|
||||
def test_image_modes_success(self):
|
||||
for mode in [
|
||||
@pytest.mark.parametrize(
|
||||
"mode",
|
||||
(
|
||||
"1",
|
||||
"P",
|
||||
"PA",
|
||||
|
@ -44,19 +45,15 @@ class TestImage:
|
|||
"YCbCr",
|
||||
"LAB",
|
||||
"HSV",
|
||||
]:
|
||||
),
|
||||
)
|
||||
def test_image_modes_success(self, mode):
|
||||
Image.new(mode, (1, 1))
|
||||
|
||||
def test_image_modes_fail(self):
|
||||
for mode in [
|
||||
"",
|
||||
"bad",
|
||||
"very very long",
|
||||
"BGR;15",
|
||||
"BGR;16",
|
||||
"BGR;24",
|
||||
"BGR;32",
|
||||
]:
|
||||
@pytest.mark.parametrize(
|
||||
"mode", ("", "bad", "very very long", "BGR;15", "BGR;16", "BGR;24", "BGR;32")
|
||||
)
|
||||
def test_image_modes_fail(self, mode):
|
||||
with pytest.raises(ValueError) as e:
|
||||
Image.new(mode, (1, 1))
|
||||
assert str(e.value) == "unrecognized image mode"
|
||||
|
@ -539,11 +536,10 @@ class TestImage:
|
|||
with pytest.raises(ValueError):
|
||||
Image.linear_gradient(wrong_mode)
|
||||
|
||||
def test_linear_gradient(self):
|
||||
|
||||
@pytest.mark.parametrize("mode", ("L", "P", "I", "F"))
|
||||
def test_linear_gradient(self, mode):
|
||||
# Arrange
|
||||
target_file = "Tests/images/linear_gradient.png"
|
||||
for mode in ["L", "P", "I", "F"]:
|
||||
|
||||
# Act
|
||||
im = Image.linear_gradient(mode)
|
||||
|
@ -565,11 +561,10 @@ class TestImage:
|
|||
with pytest.raises(ValueError):
|
||||
Image.radial_gradient(wrong_mode)
|
||||
|
||||
def test_radial_gradient(self):
|
||||
|
||||
@pytest.mark.parametrize("mode", ("L", "P", "I", "F"))
|
||||
def test_radial_gradient(self, mode):
|
||||
# Arrange
|
||||
target_file = "Tests/images/radial_gradient.png"
|
||||
for mode in ["L", "P", "I", "F"]:
|
||||
|
||||
# Act
|
||||
im = Image.radial_gradient(mode)
|
||||
|
|
|
@ -184,8 +184,9 @@ class TestImageGetPixel(AccessTest):
|
|||
with pytest.raises(error):
|
||||
im.getpixel((-1, -1))
|
||||
|
||||
def test_basic(self):
|
||||
for mode in (
|
||||
@pytest.mark.parametrize(
|
||||
"mode",
|
||||
(
|
||||
"1",
|
||||
"L",
|
||||
"LA",
|
||||
|
@ -200,20 +201,22 @@ class TestImageGetPixel(AccessTest):
|
|||
"RGBX",
|
||||
"CMYK",
|
||||
"YCbCr",
|
||||
):
|
||||
),
|
||||
)
|
||||
def test_basic(self, mode):
|
||||
self.check(mode)
|
||||
|
||||
def test_signedness(self):
|
||||
@pytest.mark.parametrize("mode", ("I;16", "I;16B"))
|
||||
def test_signedness(self, mode):
|
||||
# see https://github.com/python-pillow/Pillow/issues/452
|
||||
# pixelaccess is using signed int* instead of uint*
|
||||
for mode in ("I;16", "I;16B"):
|
||||
self.check(mode, 2**15 - 1)
|
||||
self.check(mode, 2**15)
|
||||
self.check(mode, 2**15 + 1)
|
||||
self.check(mode, 2**16 - 1)
|
||||
|
||||
def test_p_putpixel_rgb_rgba(self):
|
||||
for color in [(255, 0, 0), (255, 0, 0, 255)]:
|
||||
@pytest.mark.parametrize("color", ((255, 0, 0), (255, 0, 0, 255)))
|
||||
def test_p_putpixel_rgb_rgba(self, color):
|
||||
im = Image.new("P", (1, 1), 0)
|
||||
im.putpixel((0, 0), color)
|
||||
assert im.convert("RGB").getpixel((0, 0)) == (255, 0, 0)
|
||||
|
|
|
@ -268,8 +268,8 @@ def test_matrix_wrong_mode():
|
|||
im.convert(mode="L", matrix=matrix)
|
||||
|
||||
|
||||
def test_matrix_xyz():
|
||||
def matrix_convert(mode):
|
||||
@pytest.mark.parametrize("mode", ("RGB", "L"))
|
||||
def test_matrix_xyz(mode):
|
||||
# Arrange
|
||||
im = hopper("RGB")
|
||||
im.info["transparency"] = (255, 0, 0)
|
||||
|
@ -296,9 +296,6 @@ def test_matrix_xyz():
|
|||
assert_image_similar(converted_im, target.getchannel(0), 1)
|
||||
assert converted_im.info["transparency"] == 105
|
||||
|
||||
matrix_convert("RGB")
|
||||
matrix_convert("L")
|
||||
|
||||
|
||||
def test_matrix_identity():
|
||||
# Arrange
|
||||
|
|
|
@ -1,14 +1,17 @@
|
|||
import copy
|
||||
|
||||
import pytest
|
||||
|
||||
from PIL import Image
|
||||
|
||||
from .helper import hopper
|
||||
|
||||
|
||||
def test_copy():
|
||||
@pytest.mark.parametrize("mode", ("1", "P", "L", "RGB", "I", "F"))
|
||||
def test_copy(mode):
|
||||
cropped_coordinates = (10, 10, 20, 20)
|
||||
cropped_size = (10, 10)
|
||||
for mode in "1", "P", "L", "RGB", "I", "F":
|
||||
|
||||
# Internal copy method
|
||||
im = hopper(mode)
|
||||
out = im.copy()
|
||||
|
|
|
@ -5,8 +5,8 @@ from PIL import Image
|
|||
from .helper import assert_image_equal, hopper
|
||||
|
||||
|
||||
def test_crop():
|
||||
def crop(mode):
|
||||
@pytest.mark.parametrize("mode", ("1", "P", "L", "RGB", "I", "F"))
|
||||
def test_crop(mode):
|
||||
im = hopper(mode)
|
||||
assert_image_equal(im.crop(), im)
|
||||
|
||||
|
@ -14,9 +14,6 @@ def test_crop():
|
|||
assert cropped.mode == mode
|
||||
assert cropped.size == (50, 50)
|
||||
|
||||
for mode in "1", "P", "L", "RGB", "I", "F":
|
||||
crop(mode)
|
||||
|
||||
|
||||
def test_wide_crop():
|
||||
def crop(*bbox):
|
||||
|
|
|
@ -100,8 +100,8 @@ class TestImagingCoreResampleAccuracy:
|
|||
for y in range(image.size[1])
|
||||
)
|
||||
|
||||
def test_reduce_box(self):
|
||||
for mode in ["RGBX", "RGB", "La", "L"]:
|
||||
@pytest.mark.parametrize("mode", ("RGBX", "RGB", "La", "L"))
|
||||
def test_reduce_box(self, mode):
|
||||
case = self.make_case(mode, (8, 8), 0xE1)
|
||||
case = case.resize((4, 4), Image.Resampling.BOX)
|
||||
# fmt: off
|
||||
|
@ -111,8 +111,8 @@ class TestImagingCoreResampleAccuracy:
|
|||
for channel in case.split():
|
||||
self.check_case(channel, self.make_sample(data, (4, 4)))
|
||||
|
||||
def test_reduce_bilinear(self):
|
||||
for mode in ["RGBX", "RGB", "La", "L"]:
|
||||
@pytest.mark.parametrize("mode", ("RGBX", "RGB", "La", "L"))
|
||||
def test_reduce_bilinear(self, mode):
|
||||
case = self.make_case(mode, (8, 8), 0xE1)
|
||||
case = case.resize((4, 4), Image.Resampling.BILINEAR)
|
||||
# fmt: off
|
||||
|
@ -122,8 +122,8 @@ class TestImagingCoreResampleAccuracy:
|
|||
for channel in case.split():
|
||||
self.check_case(channel, self.make_sample(data, (4, 4)))
|
||||
|
||||
def test_reduce_hamming(self):
|
||||
for mode in ["RGBX", "RGB", "La", "L"]:
|
||||
@pytest.mark.parametrize("mode", ("RGBX", "RGB", "La", "L"))
|
||||
def test_reduce_hamming(self, mode):
|
||||
case = self.make_case(mode, (8, 8), 0xE1)
|
||||
case = case.resize((4, 4), Image.Resampling.HAMMING)
|
||||
# fmt: off
|
||||
|
@ -133,7 +133,8 @@ class TestImagingCoreResampleAccuracy:
|
|||
for channel in case.split():
|
||||
self.check_case(channel, self.make_sample(data, (4, 4)))
|
||||
|
||||
def test_reduce_bicubic(self):
|
||||
@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)
|
||||
|
@ -145,8 +146,8 @@ class TestImagingCoreResampleAccuracy:
|
|||
for channel in case.split():
|
||||
self.check_case(channel, self.make_sample(data, (6, 6)))
|
||||
|
||||
def test_reduce_lanczos(self):
|
||||
for mode in ["RGBX", "RGB", "La", "L"]:
|
||||
@pytest.mark.parametrize("mode", ("RGBX", "RGB", "La", "L"))
|
||||
def test_reduce_lanczos(self, mode):
|
||||
case = self.make_case(mode, (16, 16), 0xE1)
|
||||
case = case.resize((8, 8), Image.Resampling.LANCZOS)
|
||||
# fmt: off
|
||||
|
@ -158,8 +159,8 @@ class TestImagingCoreResampleAccuracy:
|
|||
for channel in case.split():
|
||||
self.check_case(channel, self.make_sample(data, (8, 8)))
|
||||
|
||||
def test_enlarge_box(self):
|
||||
for mode in ["RGBX", "RGB", "La", "L"]:
|
||||
@pytest.mark.parametrize("mode", ("RGBX", "RGB", "La", "L"))
|
||||
def test_enlarge_box(self, mode):
|
||||
case = self.make_case(mode, (2, 2), 0xE1)
|
||||
case = case.resize((4, 4), Image.Resampling.BOX)
|
||||
# fmt: off
|
||||
|
@ -169,8 +170,8 @@ class TestImagingCoreResampleAccuracy:
|
|||
for channel in case.split():
|
||||
self.check_case(channel, self.make_sample(data, (4, 4)))
|
||||
|
||||
def test_enlarge_bilinear(self):
|
||||
for mode in ["RGBX", "RGB", "La", "L"]:
|
||||
@pytest.mark.parametrize("mode", ("RGBX", "RGB", "La", "L"))
|
||||
def test_enlarge_bilinear(self, mode):
|
||||
case = self.make_case(mode, (2, 2), 0xE1)
|
||||
case = case.resize((4, 4), Image.Resampling.BILINEAR)
|
||||
# fmt: off
|
||||
|
@ -180,8 +181,8 @@ class TestImagingCoreResampleAccuracy:
|
|||
for channel in case.split():
|
||||
self.check_case(channel, self.make_sample(data, (4, 4)))
|
||||
|
||||
def test_enlarge_hamming(self):
|
||||
for mode in ["RGBX", "RGB", "La", "L"]:
|
||||
@pytest.mark.parametrize("mode", ("RGBX", "RGB", "La", "L"))
|
||||
def test_enlarge_hamming(self, mode):
|
||||
case = self.make_case(mode, (2, 2), 0xE1)
|
||||
case = case.resize((4, 4), Image.Resampling.HAMMING)
|
||||
# fmt: off
|
||||
|
@ -191,8 +192,8 @@ class TestImagingCoreResampleAccuracy:
|
|||
for channel in case.split():
|
||||
self.check_case(channel, self.make_sample(data, (4, 4)))
|
||||
|
||||
def test_enlarge_bicubic(self):
|
||||
for mode in ["RGBX", "RGB", "La", "L"]:
|
||||
@pytest.mark.parametrize("mode", ("RGBX", "RGB", "La", "L"))
|
||||
def test_enlarge_bicubic(self, mode):
|
||||
case = self.make_case(mode, (4, 4), 0xE1)
|
||||
case = case.resize((8, 8), Image.Resampling.BICUBIC)
|
||||
# fmt: off
|
||||
|
@ -204,8 +205,8 @@ class TestImagingCoreResampleAccuracy:
|
|||
for channel in case.split():
|
||||
self.check_case(channel, self.make_sample(data, (8, 8)))
|
||||
|
||||
def test_enlarge_lanczos(self):
|
||||
for mode in ["RGBX", "RGB", "La", "L"]:
|
||||
@pytest.mark.parametrize("mode", ("RGBX", "RGB", "La", "L"))
|
||||
def test_enlarge_lanczos(self, mode):
|
||||
case = self.make_case(mode, (6, 6), 0xE1)
|
||||
case = case.resize((12, 12), Image.Resampling.LANCZOS)
|
||||
data = (
|
||||
|
@ -419,16 +420,19 @@ class TestCoreResampleCoefficients:
|
|||
|
||||
|
||||
class TestCoreResampleBox:
|
||||
def test_wrong_arguments(self):
|
||||
im = hopper()
|
||||
for resample in (
|
||||
@pytest.mark.parametrize(
|
||||
"resample",
|
||||
(
|
||||
Image.Resampling.NEAREST,
|
||||
Image.Resampling.BOX,
|
||||
Image.Resampling.BILINEAR,
|
||||
Image.Resampling.HAMMING,
|
||||
Image.Resampling.BICUBIC,
|
||||
Image.Resampling.LANCZOS,
|
||||
):
|
||||
),
|
||||
)
|
||||
def test_wrong_arguments(self, resample):
|
||||
im = hopper()
|
||||
im.resize((32, 32), resample, (0, 0, im.width, im.height))
|
||||
im.resize((32, 32), resample, (20, 20, im.width, im.height))
|
||||
im.resize((32, 32), resample, (20, 20, 20, 100))
|
||||
|
@ -509,9 +513,9 @@ class TestCoreResampleBox:
|
|||
with pytest.raises(AssertionError, match=r"difference 29\."):
|
||||
assert_image_similar(reference, without_box, 5)
|
||||
|
||||
def test_formats(self):
|
||||
@pytest.mark.parametrize("mode", ("RGB", "L", "RGBA", "LA", "I", ""))
|
||||
def test_formats(self, mode):
|
||||
for resample in [Image.Resampling.NEAREST, Image.Resampling.BILINEAR]:
|
||||
for mode in ["RGB", "L", "RGBA", "LA", "I", ""]:
|
||||
im = hopper(mode)
|
||||
box = (20, 20, im.size[0] - 20, im.size[1] - 20)
|
||||
with_box = im.resize((32, 32), resample, box)
|
||||
|
|
|
@ -22,19 +22,10 @@ class TestImagingCoreResize:
|
|||
im.load()
|
||||
return im._new(im.im.resize(size, f))
|
||||
|
||||
def test_nearest_mode(self):
|
||||
for mode in [
|
||||
"1",
|
||||
"P",
|
||||
"L",
|
||||
"I",
|
||||
"F",
|
||||
"RGB",
|
||||
"RGBA",
|
||||
"CMYK",
|
||||
"YCbCr",
|
||||
"I;16",
|
||||
]: # exotic mode
|
||||
@pytest.mark.parametrize(
|
||||
"mode", ("1", "P", "L", "I", "F", "RGB", "RGBA", "CMYK", "YCbCr", "I;16")
|
||||
)
|
||||
def test_nearest_mode(self, mode):
|
||||
im = hopper(mode)
|
||||
r = self.resize(im, (15, 12), Image.Resampling.NEAREST)
|
||||
assert r.mode == mode
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import pytest
|
||||
|
||||
from PIL import Image
|
||||
|
||||
from .helper import (
|
||||
|
@ -22,14 +24,14 @@ def rotate(im, mode, angle, center=None, translate=None):
|
|||
assert out.size != im.size
|
||||
|
||||
|
||||
def test_mode():
|
||||
for mode in ("1", "P", "L", "RGB", "I", "F"):
|
||||
@pytest.mark.parametrize("mode", ("1", "P", "L", "RGB", "I", "F"))
|
||||
def test_mode(mode):
|
||||
im = hopper(mode)
|
||||
rotate(im, mode, 45)
|
||||
|
||||
|
||||
def test_angle():
|
||||
for angle in (0, 90, 180, 270):
|
||||
@pytest.mark.parametrize("angle", (0, 90, 180, 270))
|
||||
def test_angle(angle):
|
||||
with Image.open("Tests/images/test-card.png") as im:
|
||||
rotate(im, im.mode, angle)
|
||||
|
||||
|
@ -37,8 +39,8 @@ def test_angle():
|
|||
assert_image_equal(im.rotate(angle), im.rotate(angle, expand=1))
|
||||
|
||||
|
||||
def test_zero():
|
||||
for angle in (0, 45, 90, 180, 270):
|
||||
@pytest.mark.parametrize("angle", (0, 45, 90, 180, 270))
|
||||
def test_zero(angle):
|
||||
im = Image.new("RGB", (0, 0))
|
||||
rotate(im, im.mode, angle)
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import pytest
|
||||
|
||||
from PIL.Image import Transpose
|
||||
|
||||
from . import helper
|
||||
|
@ -9,8 +11,8 @@ HOPPER = {
|
|||
}
|
||||
|
||||
|
||||
def test_flip_left_right():
|
||||
def transpose(mode):
|
||||
@pytest.mark.parametrize("mode", HOPPER)
|
||||
def test_flip_left_right(mode):
|
||||
im = HOPPER[mode]
|
||||
out = im.transpose(Transpose.FLIP_LEFT_RIGHT)
|
||||
assert out.mode == mode
|
||||
|
@ -22,12 +24,9 @@ def test_flip_left_right():
|
|||
assert im.getpixel((1, y - 2)) == out.getpixel((x - 2, y - 2))
|
||||
assert im.getpixel((x - 2, y - 2)) == out.getpixel((1, y - 2))
|
||||
|
||||
for mode in HOPPER:
|
||||
transpose(mode)
|
||||
|
||||
|
||||
def test_flip_top_bottom():
|
||||
def transpose(mode):
|
||||
@pytest.mark.parametrize("mode", HOPPER)
|
||||
def test_flip_top_bottom(mode):
|
||||
im = HOPPER[mode]
|
||||
out = im.transpose(Transpose.FLIP_TOP_BOTTOM)
|
||||
assert out.mode == mode
|
||||
|
@ -39,12 +38,9 @@ def test_flip_top_bottom():
|
|||
assert im.getpixel((1, y - 2)) == out.getpixel((1, 1))
|
||||
assert im.getpixel((x - 2, y - 2)) == out.getpixel((x - 2, 1))
|
||||
|
||||
for mode in HOPPER:
|
||||
transpose(mode)
|
||||
|
||||
|
||||
def test_rotate_90():
|
||||
def transpose(mode):
|
||||
@pytest.mark.parametrize("mode", HOPPER)
|
||||
def test_rotate_90(mode):
|
||||
im = HOPPER[mode]
|
||||
out = im.transpose(Transpose.ROTATE_90)
|
||||
assert out.mode == mode
|
||||
|
@ -56,12 +52,9 @@ def test_rotate_90():
|
|||
assert im.getpixel((1, y - 2)) == out.getpixel((y - 2, x - 2))
|
||||
assert im.getpixel((x - 2, y - 2)) == out.getpixel((y - 2, 1))
|
||||
|
||||
for mode in HOPPER:
|
||||
transpose(mode)
|
||||
|
||||
|
||||
def test_rotate_180():
|
||||
def transpose(mode):
|
||||
@pytest.mark.parametrize("mode", HOPPER)
|
||||
def test_rotate_180(mode):
|
||||
im = HOPPER[mode]
|
||||
out = im.transpose(Transpose.ROTATE_180)
|
||||
assert out.mode == mode
|
||||
|
@ -73,12 +66,9 @@ def test_rotate_180():
|
|||
assert im.getpixel((1, y - 2)) == out.getpixel((x - 2, 1))
|
||||
assert im.getpixel((x - 2, y - 2)) == out.getpixel((1, 1))
|
||||
|
||||
for mode in HOPPER:
|
||||
transpose(mode)
|
||||
|
||||
|
||||
def test_rotate_270():
|
||||
def transpose(mode):
|
||||
@pytest.mark.parametrize("mode", HOPPER)
|
||||
def test_rotate_270(mode):
|
||||
im = HOPPER[mode]
|
||||
out = im.transpose(Transpose.ROTATE_270)
|
||||
assert out.mode == mode
|
||||
|
@ -90,12 +80,9 @@ def test_rotate_270():
|
|||
assert im.getpixel((1, y - 2)) == out.getpixel((1, 1))
|
||||
assert im.getpixel((x - 2, y - 2)) == out.getpixel((1, x - 2))
|
||||
|
||||
for mode in HOPPER:
|
||||
transpose(mode)
|
||||
|
||||
|
||||
def test_transpose():
|
||||
def transpose(mode):
|
||||
@pytest.mark.parametrize("mode", HOPPER)
|
||||
def test_transpose(mode):
|
||||
im = HOPPER[mode]
|
||||
out = im.transpose(Transpose.TRANSPOSE)
|
||||
assert out.mode == mode
|
||||
|
@ -107,12 +94,9 @@ def test_transpose():
|
|||
assert im.getpixel((1, y - 2)) == out.getpixel((y - 2, 1))
|
||||
assert im.getpixel((x - 2, y - 2)) == out.getpixel((y - 2, x - 2))
|
||||
|
||||
for mode in HOPPER:
|
||||
transpose(mode)
|
||||
|
||||
|
||||
def test_tranverse():
|
||||
def transpose(mode):
|
||||
@pytest.mark.parametrize("mode", HOPPER)
|
||||
def test_tranverse(mode):
|
||||
im = HOPPER[mode]
|
||||
out = im.transpose(Transpose.TRANSVERSE)
|
||||
assert out.mode == mode
|
||||
|
@ -124,12 +108,9 @@ def test_tranverse():
|
|||
assert im.getpixel((1, y - 2)) == out.getpixel((1, x - 2))
|
||||
assert im.getpixel((x - 2, y - 2)) == out.getpixel((1, 1))
|
||||
|
||||
for mode in HOPPER:
|
||||
transpose(mode)
|
||||
|
||||
|
||||
def test_roundtrip():
|
||||
for mode in HOPPER:
|
||||
@pytest.mark.parametrize("mode", HOPPER)
|
||||
def test_roundtrip(mode):
|
||||
im = HOPPER[mode]
|
||||
|
||||
def transpose(first, second):
|
||||
|
|
|
@ -625,10 +625,10 @@ def test_polygon2():
|
|||
helper_polygon(POINTS2)
|
||||
|
||||
|
||||
def test_polygon_kite():
|
||||
@pytest.mark.parametrize("mode", ("RGB", "L"))
|
||||
def test_polygon_kite(mode):
|
||||
# Test drawing lines of different gradients (dx>dy, dy>dx) and
|
||||
# vertical (dx==0) and horizontal (dy==0) lines
|
||||
for mode in ["RGB", "L"]:
|
||||
# Arrange
|
||||
im = Image.new(mode, (W, H))
|
||||
draw = ImageDraw.Draw(im)
|
||||
|
|
|
@ -16,8 +16,8 @@ if ImageQt.qt_is_installed:
|
|||
from PIL.ImageQt import QImage
|
||||
|
||||
|
||||
def test_sanity(tmp_path):
|
||||
for mode in ("RGB", "RGBA", "L", "P", "1"):
|
||||
@pytest.mark.parametrize("mode", ("RGB", "RGBA", "L", "P", "1"))
|
||||
def test_sanity(mode, tmp_path):
|
||||
src = hopper(mode)
|
||||
data = ImageQt.toqimage(src)
|
||||
|
||||
|
@ -37,7 +37,7 @@ def test_sanity(tmp_path):
|
|||
# libpng warning: Invalid color type/bit depth combination
|
||||
# in IHDR
|
||||
# libpng error: Invalid IHDR data
|
||||
continue
|
||||
return
|
||||
|
||||
# Test saving the file
|
||||
tempfile = str(tmp_path / f"temp_{mode}.png")
|
||||
|
|
Loading…
Reference in New Issue
Block a user