Merge pull request #3 from uploadcare/tiff-ifd-tests

Tiff ifd tests
This commit is contained in:
wiredfool 2015-09-15 07:23:18 +01:00
commit b1066bdf75
9 changed files with 19 additions and 9 deletions

View File

@ -217,7 +217,7 @@ def getiptcinfo(im):
while app[offset:offset+4] == b"8BIM": while app[offset:offset+4] == b"8BIM":
offset += 4 offset += 4
# resource code # resource code
code = JpegImagePlugin.i16(app, offset) code = i16(app, offset)
offset += 2 offset += 2
# resource name (usually empty) # resource name (usually empty)
name_len = i8(app[offset]) name_len = i8(app[offset])
@ -226,7 +226,7 @@ def getiptcinfo(im):
if offset & 1: if offset & 1:
offset += 1 offset += 1
# resource data block # resource data block
size = JpegImagePlugin.i32(app, offset) size = i32(app, offset)
offset += 4 offset += 4
if code == 0x0404: if code == 0x0404:
# 0x0404 contains IPTC/NAA data # 0x0404 contains IPTC/NAA data

View File

@ -27,7 +27,6 @@ __version__ = "0.1"
# helpers # helpers
i16 = _binary.i16le i16 = _binary.i16le
i32 = _binary.i32le
## ##

View File

@ -24,7 +24,6 @@ __version__ = "0.2"
i8 = _binary.i8 i8 = _binary.i8
i16 = _binary.i16be i16 = _binary.i16be
i32 = _binary.i32be
def _accept(prefix): def _accept(prefix):

View File

@ -21,7 +21,6 @@ from PIL import Image, ImageFile, ImagePalette, _binary
__version__ = "0.3" __version__ = "0.3"
i16 = _binary.i16be
i32 = _binary.i32be i32 = _binary.i32be

View File

@ -28,7 +28,6 @@ __version__ = "0.3"
i8 = _binary.i8 i8 = _binary.i8
i16 = _binary.i16le i16 = _binary.i16le
i32 = _binary.i32le
MODES = { MODES = {

View File

@ -370,7 +370,8 @@ class TestFileJpeg(PillowTestCase):
# Act # Act
# Shouldn't raise error # Shouldn't raise error
im = Image.open("Tests/images/sugarshack_bad_mpo_header.jpg") fn = "Tests/images/sugarshack_bad_mpo_header.jpg"
im = self.assert_warning(UserWarning, lambda: Image.open(fn))
# Assert # Assert
self.assertEqual(im.format, "JPEG") self.assertEqual(im.format, "JPEG")

View File

@ -103,8 +103,9 @@ class TestFileTiff(PillowTestCase):
lambda: TiffImagePlugin.TiffImageFile(invalid_file)) lambda: TiffImagePlugin.TiffImageFile(invalid_file))
def test_bad_exif(self): def test_bad_exif(self):
i = Image.open('Tests/images/hopper_bad_exif.jpg')
try: try:
Image.open('Tests/images/hopper_bad_exif.jpg')._getexif() self.assert_warning(UserWarning, lambda: i._getexif())
except struct.error: except struct.error:
self.fail( self.fail(
"Bad EXIF data passed incorrect values to _binary unpack") "Bad EXIF data passed incorrect values to _binary unpack")

View File

@ -1,5 +1,8 @@
from __future__ import division from __future__ import division
import io
import struct
from helper import unittest, PillowTestCase, hopper from helper import unittest, PillowTestCase, hopper
from PIL import Image, TiffImagePlugin, TiffTags from PIL import Image, TiffImagePlugin, TiffTags
@ -136,6 +139,15 @@ class TestFileTiffMetadata(PillowTestCase):
self.assertEqual(tag_ids['MakerNoteSafety'], 50741) self.assertEqual(tag_ids['MakerNoteSafety'], 50741)
self.assertEqual(tag_ids['BestQualityScale'], 50780) self.assertEqual(tag_ids['BestQualityScale'], 50780)
def test_empty_metadata(self):
f = io.BytesIO(b'II*\x00\x08\x00\x00\x00')
head = f.read(8)
info = TiffImagePlugin.ImageFileDirectory(head)
try:
self.assert_warning(UserWarning, lambda: info.load(f))
except struct.error:
self.fail("Should not be struct errors there.")
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()