More tests for TiffImagePlugin.py

This commit is contained in:
hugovk 2014-07-27 22:18:42 +03:00
parent c9859ddf9c
commit 659b8c2f6f

View File

@ -141,6 +141,137 @@ class TestFileTiff(PillowTestCase):
self.assertEqual(
im.getextrema(), (-3.140936851501465, 3.140684127807617))
def test___str__(self):
# Arrange
file = "Tests/images/pil136.tiff"
im = Image.open(file)
# Act
ret = str(im.ifd)
# Assert
self.assertIsInstance(ret, str)
self.assertEqual(
ret,
'{256: (55,), 257: (43,), 258: (8, 8, 8, 8), 259: (1,), '
'262: (2,), 296: (2,), 273: (8,), 338: (1,), 277: (4,), '
'279: (9460,), 282: ((720000, 10000),), '
'283: ((720000, 10000),), 284: (1,)}')
def test__delitem__(self):
# Arrange
file = "Tests/images/pil136.tiff"
im = Image.open(file)
len_before = len(im.ifd.as_dict())
# Act
del im.ifd[256]
# Assert
len_after = len(im.ifd.as_dict())
self.assertEqual(len_before, len_after + 1)
def test_load_byte(self):
# Arrange
from PIL import TiffImagePlugin
ifd = TiffImagePlugin.ImageFileDirectory()
data = b"abc"
# Act
ret = ifd.load_byte(data)
# Assert
self.assertEqual(ret, b"abc")
def test_load_string(self):
# Arrange
from PIL import TiffImagePlugin
ifd = TiffImagePlugin.ImageFileDirectory()
data = b"abc\0"
# Act
ret = ifd.load_string(data)
# Assert
self.assertEqual(ret, "abc")
def test_load_float(self):
# Arrange
from PIL import TiffImagePlugin
ifd = TiffImagePlugin.ImageFileDirectory()
data = b"abcdabcd"
# Act
ret = ifd.load_float(data)
# Assert
self.assertEqual(ret, (1.6777999408082104e+22, 1.6777999408082104e+22))
def test_load_double(self):
# Arrange
from PIL import TiffImagePlugin
ifd = TiffImagePlugin.ImageFileDirectory()
data = b"abcdefghabcdefgh"
# Act
ret = ifd.load_double(data)
# Assert
self.assertEqual(ret, (8.540883223036124e+194, 8.540883223036124e+194))
def test_seek(self):
# Arrange
file = "Tests/images/pil136.tiff"
im = Image.open(file)
# Act
im.seek(-1)
# Assert
self.assertEqual(im.tell(), 0)
def test_seek_eof(self):
# Arrange
file = "Tests/images/pil136.tiff"
im = Image.open(file)
self.assertEqual(im.tell(), 0)
# Act / Assert
self.assertRaises(EOFError, lambda: im.seek(1))
def test__cvt_res_int(self):
# Arrange
from PIL.TiffImagePlugin import _cvt_res
value = 34
# Act
ret = _cvt_res(value)
# Assert
self.assertEqual(ret, (34, 1))
def test__cvt_res_float(self):
# Arrange
from PIL.TiffImagePlugin import _cvt_res
value = 22.3
# Act
ret = _cvt_res(value)
# Assert
self.assertEqual(ret, (1461452, 65536))
def test__cvt_res_sequence(self):
# Arrange
from PIL.TiffImagePlugin import _cvt_res
value = [0, 1]
# Act
ret = _cvt_res(value)
# Assert
self.assertEqual(ret, [0, 1])
if __name__ == '__main__':
unittest.main()