2014-07-07 21:03:50 +04:00
|
|
|
from helper import unittest, PillowTestCase
|
2012-10-25 16:57:39 +04:00
|
|
|
|
|
|
|
from PIL import Image, TarIO
|
|
|
|
|
2013-04-21 12:04:58 +04:00
|
|
|
codecs = dir(Image.core)
|
|
|
|
|
2014-09-04 13:21:19 +04:00
|
|
|
# Sample tar archive
|
|
|
|
TEST_TAR_FILE = "Tests/images/hopper.tar"
|
2012-10-25 16:57:39 +04:00
|
|
|
|
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
class TestFileTar(PillowTestCase):
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
if "zip_decoder" not in codecs and "jpeg_decoder" not in codecs:
|
2018-08-17 12:40:13 +03:00
|
|
|
self.skipTest("neither jpeg nor zip support available")
|
2014-06-10 13:10:47 +04:00
|
|
|
|
|
|
|
def test_sanity(self):
|
2018-11-11 08:00:17 +03:00
|
|
|
for codec, test_path, format in [
|
|
|
|
['zip_decoder', 'hopper.png', 'PNG'],
|
|
|
|
['jpeg_decoder', 'hopper.jpg', 'JPEG']
|
|
|
|
]:
|
|
|
|
if codec in codecs:
|
|
|
|
tar = TarIO.TarIO(TEST_TAR_FILE, test_path)
|
|
|
|
im = Image.open(tar)
|
|
|
|
im.load()
|
|
|
|
self.assertEqual(im.mode, "RGB")
|
|
|
|
self.assertEqual(im.size, (128, 128))
|
|
|
|
self.assertEqual(im.format, format)
|
|
|
|
|
|
|
|
def test_close(self):
|
|
|
|
tar = TarIO.TarIO(TEST_TAR_FILE, 'hopper.jpg')
|
|
|
|
tar.close()
|
|
|
|
|
|
|
|
def test_contextmanager(self):
|
2018-10-18 21:49:14 +03:00
|
|
|
with TarIO.TarIO(TEST_TAR_FILE, 'hopper.jpg'):
|
2018-11-11 08:00:17 +03:00
|
|
|
pass
|
2014-06-10 13:10:47 +04:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|