Health fixes

This commit is contained in:
Andrew Murray 2016-02-05 09:57:13 +11:00
parent 0129c50933
commit 677b958a7f
20 changed files with 116 additions and 125 deletions

View File

@ -256,7 +256,6 @@ class DdsImageFile(ImageFile.ImageFile):
self.fp = BytesIO(decoded_data) self.fp = BytesIO(decoded_data)
def load_seek(self, pos): def load_seek(self, pos):
pass pass

View File

@ -83,7 +83,6 @@ class FtexImageFile(ImageFile.ImageFile):
self.fp.close() self.fp.close()
self.fp = BytesIO(data) self.fp = BytesIO(data)
def load_seek(self, pos): def load_seek(self, pos):
pass pass

View File

@ -57,7 +57,7 @@ import struct
import sys import sys
import warnings import warnings
from .TiffTags import TYPES, TagInfo from .TiffTags import TYPES
__version__ = "1.3.5" __version__ = "1.3.5"
@ -227,6 +227,7 @@ def _limit_rational(val, max_val):
_load_dispatch = {} _load_dispatch = {}
_write_dispatch = {} _write_dispatch = {}
class IFDRational(Rational): class IFDRational(Rational):
""" Implements a rational class where 0/0 is a legal value to match """ Implements a rational class where 0/0 is a legal value to match
the in the wild use of exif rationals. the in the wild use of exif rationals.
@ -266,7 +267,6 @@ class IFDRational(Rational):
self._val = float('nan') self._val = float('nan')
return return
elif denominator == 1: elif denominator == 1:
if sys.hexversion < 0x2070000 and type(value) == float: if sys.hexversion < 0x2070000 and type(value) == float:
# python 2.6 is different. # python 2.6 is different.
@ -284,7 +284,6 @@ class IFDRational(Rational):
def denominator(a): def denominator(a):
return a._denominator return a._denominator
def limit_rational(self, max_denominator): def limit_rational(self, max_denominator):
""" """
@ -350,7 +349,6 @@ class IFDRational(Rational):
__round__ = _delegate('__round__') __round__ = _delegate('__round__')
class ImageFileDirectory_v2(collections.MutableMapping): class ImageFileDirectory_v2(collections.MutableMapping):
"""This class represents a TIFF tag directory. To speed things up, we """This class represents a TIFF tag directory. To speed things up, we
don't decode tags unless they're asked for. don't decode tags unless they're asked for.
@ -1423,7 +1421,8 @@ def _save(im, fp, filename):
# to add a custom tag without the dictionary entry # to add a custom tag without the dictionary entry
# #
# UNDONE -- add code for the custom dictionary # UNDONE -- add code for the custom dictionary
if tag not in TiffTags.LIBTIFF_CORE: continue if tag not in TiffTags.LIBTIFF_CORE:
continue
if tag not in atts and tag not in blocklist: if tag not in atts and tag not in blocklist:
if isinstance(value, unicode if bytes is str else str): if isinstance(value, unicode if bytes is str else str):
atts[tag] = value.encode('ascii', 'replace') + b"\0" atts[tag] = value.encode('ascii', 'replace') + b"\0"

View File

@ -30,6 +30,7 @@ class TagInfo(namedtuple("_TagInfo", "value name type length enum")):
def cvt_enum(self, value): def cvt_enum(self, value):
return self.enum.get(value, value) return self.enum.get(value, value)
def lookup(tag): def lookup(tag):
""" """
:param tag: Integer tag number :param tag: Integer tag number

View File

@ -3,6 +3,7 @@ from PIL import Image
TEST_FILE = "Tests/images/libtiff_segfault.tif" TEST_FILE = "Tests/images/libtiff_segfault.tif"
class TestLibtiffSegfault(PillowTestCase): class TestLibtiffSegfault(PillowTestCase):
def test_segfault(self): def test_segfault(self):
""" This test should not segfault. It will on Pillow <= 3.1.0 and """ This test should not segfault. It will on Pillow <= 3.1.0 and
@ -18,6 +19,5 @@ class TestLibtiffSegfault(PillowTestCase):
self.fail("Should have returned IOError") self.fail("Should have returned IOError")
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@ -78,7 +78,7 @@ class TestFileDds(PillowTestCase):
img_file = f.read() img_file = f.read()
def short_header(): def short_header():
im = Image.open(BytesIO(img_file[:119])) Image.open(BytesIO(img_file[:119]))
self.assertRaises(IOError, short_header) self.assertRaises(IOError, short_header)
@ -89,7 +89,7 @@ class TestFileDds(PillowTestCase):
img_file = f.read() img_file = f.read()
def short_file(): def short_file():
im = Image.open(BytesIO(img_file[:-100])) Image.open(BytesIO(img_file[:-100]))
self.assertRaises(IOError, short_file) self.assertRaises(IOError, short_file)

View File

@ -1,6 +1,7 @@
from helper import unittest, PillowTestCase from helper import PillowTestCase
from PIL import Image from PIL import Image
class TestFileFtex(PillowTestCase): class TestFileFtex(PillowTestCase):
def test_load_raw(self): def test_load_raw(self):

View File

@ -11,7 +11,6 @@ class TestFileGbr(PillowTestCase):
self.assertRaises(SyntaxError, self.assertRaises(SyntaxError,
lambda: GbrImagePlugin.GbrImageFile(invalid_file)) lambda: GbrImagePlugin.GbrImageFile(invalid_file))
def test_gbr_file(self): def test_gbr_file(self):
im = Image.open('Tests/images/gbr.gbr') im = Image.open('Tests/images/gbr.gbr')

View File

@ -219,7 +219,6 @@ class TestFileJpeg(PillowTestCase):
for tag, value in expected_exif.items(): for tag, value in expected_exif.items():
self.assertEqual(value, exif[tag]) self.assertEqual(value, exif[tag])
def test_exif_gps_typeerror(self): def test_exif_gps_typeerror(self):
im = Image.open('Tests/images/exif_gps_typeerror.jpg') im = Image.open('Tests/images/exif_gps_typeerror.jpg')

View File

@ -188,7 +188,8 @@ class TestFileLibTiff(LibTiffTestCase):
for tag in im.tag_v2.keys(): for tag in im.tag_v2.keys():
try: try:
del(core_items[tag]) del(core_items[tag])
except: pass except:
pass
# Type codes: # Type codes:
# 2: "ascii", # 2: "ascii",
@ -203,7 +204,6 @@ class TestFileLibTiff(LibTiffTestCase):
5: TiffImagePlugin.IFDRational(100, 1), 5: TiffImagePlugin.IFDRational(100, 1),
12: 1.05} 12: 1.05}
new_ifd = TiffImagePlugin.ImageFileDirectory_v2() new_ifd = TiffImagePlugin.ImageFileDirectory_v2()
for tag, info in core_items.items(): for tag, info in core_items.items():
if info.length == 1: if info.length == 1:
@ -223,8 +223,6 @@ class TestFileLibTiff(LibTiffTestCase):
TiffImagePlugin.WRITE_LIBTIFF = False TiffImagePlugin.WRITE_LIBTIFF = False
def test_g3_compression(self): def test_g3_compression(self):
i = Image.open('Tests/images/hopper_g4_500.tif') i = Image.open('Tests/images/hopper_g4_500.tif')
out = self.tempfile("temp.tif") out = self.tempfile("temp.tif")
@ -459,7 +457,6 @@ class TestFileLibTiff(LibTiffTestCase):
TiffImagePlugin.WRITE_LIBTIFF = False TiffImagePlugin.WRITE_LIBTIFF = False
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@ -1,6 +1,7 @@
from helper import unittest, PillowTestCase, hopper from helper import unittest, PillowTestCase
from PIL import Image from PIL import Image
class TestFilePcd(PillowTestCase): class TestFilePcd(PillowTestCase):
def test_load_raw(self): def test_load_raw(self):
@ -19,4 +20,3 @@ class TestFilePcd(PillowTestCase):
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@ -134,7 +134,8 @@ class TestFileTiffMetadata(PillowTestCase):
'PageNumber', 'StripOffsets'] 'PageNumber', 'StripOffsets']
for tag, value in reloaded.items(): for tag, value in reloaded.items():
if tag in ignored: continue if tag in ignored:
continue
if (type(original[tag]) == tuple if (type(original[tag]) == tuple
and type(original[tag][0]) == IFDRational): and type(original[tag][0]) == IFDRational):
# Need to compare element by element in the tuple, # Need to compare element by element in the tuple,
@ -198,8 +199,6 @@ class TestFileTiffMetadata(PillowTestCase):
self.assertEqual(0, reloaded.tag_v2[41988][0].denominator) self.assertEqual(0, reloaded.tag_v2[41988][0].denominator)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@ -1,6 +1,7 @@
from helper import unittest, PillowTestCase, hopper, py3 from helper import unittest, PillowTestCase, hopper, py3
import sys import sys
class TestImageGetIm(PillowTestCase): class TestImageGetIm(PillowTestCase):
def test_sanity(self): def test_sanity(self):
@ -10,7 +11,6 @@ class TestImageGetIm(PillowTestCase):
if py3: if py3:
self.assertIn("PyCapsule", type_repr) self.assertIn("PyCapsule", type_repr)
if sys.hexversion < 0x2070000: if sys.hexversion < 0x2070000:
# py2.6 x64, windows # py2.6 x64, windows
target_types = (int, long) target_types = (int, long)

View File

@ -1,6 +1,7 @@
from helper import unittest, PillowTestCase, hopper from helper import unittest, PillowTestCase, hopper
from PIL import Image from PIL import Image
class TestImagingCoreResize(PillowTestCase): class TestImagingCoreResize(PillowTestCase):
# see https://github.com/python-pillow/Pillow/issues/1710 # see https://github.com/python-pillow/Pillow/issues/1710
def test_overflow(self): def test_overflow(self):

View File

@ -7,8 +7,8 @@ from PIL.TiffImagePlugin import IFDRational
from fractions import Fraction from fractions import Fraction
class Test_IFDRational(PillowTestCase):
class Test_IFDRational(PillowTestCase):
def _test_equal(self, num, denom, target): def _test_equal(self, num, denom, target):
@ -28,7 +28,6 @@ class Test_IFDRational(PillowTestCase):
self._test_equal(Fraction(1, 1), 1, Fraction(1, 1)) self._test_equal(Fraction(1, 1), 1, Fraction(1, 1))
self._test_equal(IFDRational(1, 1), 1, 1) self._test_equal(IFDRational(1, 1), 1, 1)
self._test_equal(1, 2, Fraction(1, 2)) self._test_equal(1, 2, Fraction(1, 2))
self._test_equal(1, 2, IFDRational(1, 2)) self._test_equal(1, 2, IFDRational(1, 2))
@ -45,7 +44,6 @@ class Test_IFDRational(PillowTestCase):
self.assertTrue(xres and 1) self.assertTrue(xres and 1)
self.assertTrue(xres and yres) self.assertTrue(xres and yres)
def test_ifd_rational_save(self): def test_ifd_rational_save(self):
for libtiff in (True, False): for libtiff in (True, False):
TiffImagePlugin.WRITE_LIBTIFF = libtiff TiffImagePlugin.WRITE_LIBTIFF = libtiff
@ -58,4 +56,3 @@ class Test_IFDRational(PillowTestCase):
reloaded = Image.open(out) reloaded = Image.open(out)
self.assertEqual(float(IFDRational(301, 1)), self.assertEqual(float(IFDRational(301, 1)),
float(reloaded.tag_v2[282])) float(reloaded.tag_v2[282]))