mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-06-30 01:43:17 +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
|
from PIL import Image
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from PIL import ImageTk
|
from PIL import ImageTk
|
||||||
|
import Tkinter as tk
|
||||||
dir(ImageTk)
|
dir(ImageTk)
|
||||||
|
HAS_TK = True
|
||||||
except (OSError, ImportError) as v:
|
except (OSError, ImportError) as v:
|
||||||
# Skipped via setUp()
|
# Skipped via setUp()
|
||||||
pass
|
HAS_TK = False
|
||||||
|
|
||||||
|
TK_MODES = ('1', 'L', 'P', 'RGB', 'RGBA')
|
||||||
|
|
||||||
class TestImageTk(PillowTestCase):
|
class TestImageTk(PillowTestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
if not HAS_TK:
|
||||||
|
self.skipTest("Tk not installed")
|
||||||
try:
|
try:
|
||||||
from PIL import ImageTk
|
# setup tk
|
||||||
dir(ImageTk)
|
app = tk.Frame()
|
||||||
except (OSError, ImportError) as v:
|
#root = tk.Tk()
|
||||||
self.skipTest(v)
|
except (tk.TclError) as v:
|
||||||
|
self.skipTest("TCL Error: %s" % v)
|
||||||
|
|
||||||
def test_kw(self):
|
def test_kw(self):
|
||||||
TEST_JPG = "Tests/images/hopper.jpg"
|
TEST_JPG = "Tests/images/hopper.jpg"
|
||||||
|
@ -40,5 +47,47 @@ class TestImageTk(PillowTestCase):
|
||||||
self.assertEqual(im, None)
|
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__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user