Parametrized test

This commit is contained in:
Andrew Murray 2024-04-22 18:45:41 +10:00
parent c7bb152ed9
commit 0df8796e19

View File

@ -242,7 +242,24 @@ class TestFileLibTiff(LibTiffTestCase):
im.save(out, tiffinfo=new_ifd)
def test_custom_metadata(self, tmp_path: Path) -> None:
@pytest.mark.parametrize(
"libtiff",
(
pytest.param(
True,
marks=pytest.mark.skipif(
not getattr(Image.core, "libtiff_support_custom_tags", False),
reason="Custom tags not supported by older libtiff",
),
),
False,
),
)
def test_custom_metadata(
self, monkeypatch: pytest.MonkeyPatch, tmp_path: Path, libtiff: bool
) -> None:
monkeypatch.setattr(TiffImagePlugin, "WRITE_LIBTIFF", libtiff)
class Tc(NamedTuple):
value: Any
type: int
@ -281,13 +298,6 @@ class TestFileLibTiff(LibTiffTestCase):
)
}
libtiffs = [False]
if Image.core.libtiff_support_custom_tags:
libtiffs.append(True)
for libtiff in libtiffs:
TiffImagePlugin.WRITE_LIBTIFF = libtiff
def check_tags(
tiffinfo: TiffImagePlugin.ImageFileDirectory_v2 | dict[int, str]
) -> None:
@ -304,9 +314,7 @@ class TestFileLibTiff(LibTiffTestCase):
and libtiff
):
# libtiff does not support real RATIONALS
assert (
round(abs(float(reloaded_value) - float(value)), 7) == 0
)
assert round(abs(float(reloaded_value) - float(value)), 7) == 0
continue
assert reloaded_value == value
@ -327,7 +335,6 @@ class TestFileLibTiff(LibTiffTestCase):
if tagdata.supported_by_default
}
)
TiffImagePlugin.WRITE_LIBTIFF = False
def test_osubfiletype(self, tmp_path: Path) -> None:
outfile = str(tmp_path / "temp.tif")