Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions Tests/test_tiff_ifdrational.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
from fractions import Fraction
from pathlib import Path

from PIL import Image, TiffImagePlugin, features
import pytest

from PIL import Image, TiffImagePlugin
from PIL.TiffImagePlugin import IFDRational

from .helper import hopper
from .helper import hopper, skip_unless_feature


def _test_equal(num, denom, target) -> None:
Expand Down Expand Up @@ -52,18 +54,17 @@ def test_nonetype() -> None:
assert xres and yres


def test_ifd_rational_save(tmp_path: Path) -> None:
methods = [True]
if features.check("libtiff"):
methods.append(False)

for libtiff in methods:
TiffImagePlugin.WRITE_LIBTIFF = libtiff
@pytest.mark.parametrize(
"libtiff", (pytest.param(True, marks=skip_unless_feature("libtiff")), False)
)
def test_ifd_rational_save(tmp_path: Path, libtiff: bool) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def test_ifd_rational_save(tmp_path: Path, libtiff: bool) -> None:
def test_ifd_rational_save(monkeypatch: pytest.MonkeyPatch, tmp_path: Path, libtiff: bool) -> None:

im = hopper()
out = str(tmp_path / "temp.tiff")
res = IFDRational(301, 1)

im = hopper()
out = str(tmp_path / "temp.tiff")
res = IFDRational(301, 1)
im.save(out, dpi=(res, res), compression="raw")
TiffImagePlugin.WRITE_LIBTIFF = libtiff
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
TiffImagePlugin.WRITE_LIBTIFF = libtiff
monkeypatch.setattr(TiffImagePlugin, "WRITE_LIBTIFF", libtiff)

im.save(out, dpi=(res, res), compression="raw")
TiffImagePlugin.WRITE_LIBTIFF = False
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
TiffImagePlugin.WRITE_LIBTIFF = False


with Image.open(out) as reloaded:
assert float(IFDRational(301, 1)) == float(reloaded.tag_v2[282])
with Image.open(out) as reloaded:
assert float(IFDRational(301, 1)) == float(reloaded.tag_v2[282])