2014-07-07 21:03:50 +04:00
|
|
|
from helper import unittest, PillowTestCase
|
2016-05-01 15:19:52 +03:00
|
|
|
from PIL import Image
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2016-05-01 15:19:52 +03:00
|
|
|
try:
|
|
|
|
from PIL import ImageTk
|
|
|
|
dir(ImageTk)
|
|
|
|
except (OSError, ImportError) as v:
|
|
|
|
# Skipped via setUp()
|
|
|
|
pass
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
class TestImageTk(PillowTestCase):
|
|
|
|
|
2016-05-01 15:19:52 +03:00
|
|
|
def setUp(self):
|
2014-06-10 13:10:47 +04:00
|
|
|
try:
|
|
|
|
from PIL import ImageTk
|
|
|
|
dir(ImageTk)
|
|
|
|
except (OSError, ImportError) as v:
|
|
|
|
self.skipTest(v)
|
|
|
|
|
2016-05-01 15:19:52 +03:00
|
|
|
def test_kw(self):
|
|
|
|
TEST_JPG = "Tests/images/hopper.jpg"
|
|
|
|
TEST_PNG = "Tests/images/hopper.png"
|
|
|
|
im1 = Image.open(TEST_JPG)
|
|
|
|
im2 = Image.open(TEST_PNG)
|
|
|
|
with open(TEST_PNG, 'rb') as fp:
|
|
|
|
data = fp.read()
|
|
|
|
kw = {"file":TEST_JPG, "data":data}
|
|
|
|
|
|
|
|
# Test "file"
|
|
|
|
im = ImageTk._get_image_from_kw(kw)
|
|
|
|
self.assert_image_equal(im, im1)
|
|
|
|
|
|
|
|
# Test "data"
|
|
|
|
im = ImageTk._get_image_from_kw(kw)
|
|
|
|
self.assert_image_equal(im, im2)
|
|
|
|
|
|
|
|
# Test no relevant entry
|
|
|
|
im = ImageTk._get_image_from_kw(kw)
|
|
|
|
self.assertEqual(im, None)
|
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|
|
|
|
|
|
|
|
# End of file
|