Pillow/Tests/test_file_tga.py

69 lines
1.7 KiB
Python
Raw Normal View History

2014-08-20 10:32:06 +04:00
from helper import unittest, PillowTestCase
from PIL import Image
2014-08-20 10:39:11 +04:00
class TestFileTga(PillowTestCase):
2014-08-20 10:32:06 +04:00
2014-08-20 10:39:11 +04:00
def test_id_field(self):
2014-08-20 10:32:06 +04:00
# tga file with id field
test_file = "Tests/images/tga_id_field.tga"
# Act
im = Image.open(test_file)
# Assert
self.assertEqual(im.size, (100, 100))
2016-04-21 17:40:20 +03:00
def test_id_field_rle(self):
# tga file with id field
test_file = "Tests/images/rgb32rle.tga"
# Act
im = Image.open(test_file)
# Assert
self.assertEqual(im.size, (199, 199))
2015-07-03 08:03:25 +03:00
def test_save(self):
test_file = "Tests/images/tga_id_field.tga"
im = Image.open(test_file)
test_file = self.tempfile("temp.tga")
# Save
im.save(test_file)
test_im = Image.open(test_file)
self.assertEqual(test_im.size, (100, 100))
# RGBA save
im.convert("RGBA").save(test_file)
test_im = Image.open(test_file)
self.assertEqual(test_im.size, (100, 100))
2015-07-03 09:22:56 +03:00
2015-07-03 08:03:25 +03:00
# Unsupported mode save
self.assertRaises(IOError, lambda: im.convert("LA").save(test_file))
2016-04-21 17:40:20 +03:00
def test_save_rle(self):
test_file = "Tests/images/rgb32rle.tga"
im = Image.open(test_file)
test_file = self.tempfile("temp.tga")
# Save
im.save(test_file)
test_im = Image.open(test_file)
self.assertEqual(test_im.size, (199, 199))
# RGBA save
im.convert("RGBA").save(test_file)
test_im = Image.open(test_file)
self.assertEqual(test_im.size, (199, 199))
# Unsupported mode save
self.assertRaises(IOError, lambda: im.convert("LA").save(test_file))
2014-08-20 10:32:06 +04:00
if __name__ == '__main__':
unittest.main()