mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-13 10:46:16 +03:00
added tests for functionality in ImageTk
This commit is contained in:
parent
ca3f6a25f4
commit
e66271d464
|
@ -1,22 +1,29 @@
|
|||
from helper import unittest, PillowTestCase
|
||||
from helper import unittest, PillowTestCase, hopper
|
||||
from PIL import Image
|
||||
|
||||
|
||||
try:
|
||||
from PIL import ImageTk
|
||||
import Tkinter as tk
|
||||
dir(ImageTk)
|
||||
HAS_TK = True
|
||||
except (OSError, ImportError) as v:
|
||||
# Skipped via setUp()
|
||||
pass
|
||||
|
||||
HAS_TK = False
|
||||
|
||||
TK_MODES = ('1', 'L', 'P', 'RGB', 'RGBA')
|
||||
|
||||
class TestImageTk(PillowTestCase):
|
||||
|
||||
def setUp(self):
|
||||
if not HAS_TK:
|
||||
self.skipTest("Tk not installed")
|
||||
try:
|
||||
from PIL import ImageTk
|
||||
dir(ImageTk)
|
||||
except (OSError, ImportError) as v:
|
||||
self.skipTest(v)
|
||||
# setup tk
|
||||
app = tk.Frame()
|
||||
#root = tk.Tk()
|
||||
except (tk.TclError) as v:
|
||||
self.skipTest("TCL Error: %s" % v)
|
||||
|
||||
def test_kw(self):
|
||||
TEST_JPG = "Tests/images/hopper.jpg"
|
||||
|
@ -40,5 +47,47 @@ class TestImageTk(PillowTestCase):
|
|||
self.assertEqual(im, None)
|
||||
|
||||
|
||||
def test_photoimage(self):
|
||||
for mode in TK_MODES:
|
||||
# test as image:
|
||||
im = hopper(mode)
|
||||
|
||||
# this should not crash
|
||||
im_tk = ImageTk.PhotoImage(im)
|
||||
|
||||
self.assertEqual(im_tk.width(), im.width)
|
||||
self.assertEqual(im_tk.height(), im.height)
|
||||
|
||||
# _tkinter.TclError: this function is not yet supported
|
||||
#reloaded = ImageTk.getimage(im_tk)
|
||||
#self.assert_image_equal(reloaded, im)
|
||||
|
||||
|
||||
|
||||
def test_photoimage_blank(self):
|
||||
# test a image using mode/size:
|
||||
for mode in TK_MODES:
|
||||
im_tk = ImageTk.PhotoImage(mode, (100,100))
|
||||
|
||||
self.assertEqual(im_tk.width(), 100)
|
||||
self.assertEqual(im_tk.height(), 100)
|
||||
|
||||
#reloaded = ImageTk.getimage(im_tk)
|
||||
#self.assert_image_equal(reloaded, im)
|
||||
|
||||
def test_bitmapimage(self):
|
||||
im = hopper('1')
|
||||
|
||||
# this should not crash
|
||||
im_tk = ImageTk.BitmapImage(im)
|
||||
|
||||
self.assertEqual(im_tk.width(), im.width)
|
||||
self.assertEqual(im_tk.height(), im.height)
|
||||
|
||||
#reloaded = ImageTk.getimage(im_tk)
|
||||
#self.assert_image_equal(reloaded, im)
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
Loading…
Reference in New Issue
Block a user