Merge pull request #4888 from radarhere/bugfix/ifdrational-equality

Fix IFDRational __eq__ bug
This commit is contained in:
Andrew Murray 2020-08-29 08:28:55 +10:00 committed by GitHub
commit 9b86da9c26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 0 deletions

View File

@ -242,6 +242,16 @@ class TestFileJpeg:
# Assert # Assert
assert exif[gps_index] == expected_exif_gps assert exif[gps_index] == expected_exif_gps
def test_exif_equality(self):
# In 7.2.0, Exif rationals were changed to be read as
# TiffImagePlugin.IFDRational. This class had a bug in __eq__,
# breaking the self-equality of Exif data
exifs = []
for i in range(2):
with Image.open("Tests/images/exif-200dpcm.jpg") as im:
exifs.append(im._getexif())
assert exifs[0] == exifs[1]
def test_exif_rollback(self): def test_exif_rollback(self):
# rolling back exif support in 3.1 to pre-3.0 formatting. # rolling back exif support in 3.1 to pre-3.0 formatting.
# expected from 2.9, with b/u qualifiers switched for 3.2 compatibility # expected from 2.9, with b/u qualifiers switched for 3.2 compatibility

View File

@ -29,6 +29,12 @@ def test_sanity():
_test_equal(1, 2, IFDRational(1, 2)) _test_equal(1, 2, IFDRational(1, 2))
def test_ranges():
for num in range(1, 10):
for denom in range(1, 10):
assert IFDRational(num, denom) == IFDRational(num, denom)
def test_nonetype(): def test_nonetype():
# Fails if the _delegate function doesn't return a valid function # Fails if the _delegate function doesn't return a valid function

View File

@ -353,6 +353,8 @@ class IFDRational(Rational):
return self._val.__hash__() return self._val.__hash__()
def __eq__(self, other): def __eq__(self, other):
if isinstance(other, IFDRational):
other = other._val
return self._val == other return self._val == other
def _delegate(op): def _delegate(op):