|
3 | 3 | from fractions import Fraction |
4 | 4 | from pathlib import Path |
5 | 5 |
|
6 | | -from PIL import Image, TiffImagePlugin, features |
| 6 | +import pytest |
| 7 | + |
| 8 | +from PIL import Image, TiffImagePlugin |
7 | 9 | from PIL.TiffImagePlugin import IFDRational |
8 | 10 |
|
9 | | -from .helper import hopper |
| 11 | +from .helper import hopper, skip_unless_feature |
10 | 12 |
|
11 | 13 |
|
12 | 14 | def _test_equal(num, denom, target) -> None: |
@@ -52,18 +54,17 @@ def test_nonetype() -> None: |
52 | 54 | assert xres and yres |
53 | 55 |
|
54 | 56 |
|
55 | | -def test_ifd_rational_save(tmp_path: Path) -> None: |
56 | | - methods = [True] |
57 | | - if features.check("libtiff"): |
58 | | - methods.append(False) |
59 | | - |
60 | | - for libtiff in methods: |
61 | | - TiffImagePlugin.WRITE_LIBTIFF = libtiff |
| 57 | +@pytest.mark.parametrize( |
| 58 | + "libtiff", (pytest.param(True, marks=skip_unless_feature("libtiff")), False) |
| 59 | +) |
| 60 | +def test_ifd_rational_save(tmp_path: Path, libtiff: bool) -> None: |
| 61 | + im = hopper() |
| 62 | + out = str(tmp_path / "temp.tiff") |
| 63 | + res = IFDRational(301, 1) |
62 | 64 |
|
63 | | - im = hopper() |
64 | | - out = str(tmp_path / "temp.tiff") |
65 | | - res = IFDRational(301, 1) |
66 | | - im.save(out, dpi=(res, res), compression="raw") |
| 65 | + TiffImagePlugin.WRITE_LIBTIFF = libtiff |
| 66 | + im.save(out, dpi=(res, res), compression="raw") |
| 67 | + TiffImagePlugin.WRITE_LIBTIFF = False |
67 | 68 |
|
68 | | - with Image.open(out) as reloaded: |
69 | | - assert float(IFDRational(301, 1)) == float(reloaded.tag_v2[282]) |
| 69 | + with Image.open(out) as reloaded: |
| 70 | + assert float(IFDRational(301, 1)) == float(reloaded.tag_v2[282]) |
0 commit comments