From e66271d46477cedca2ffb18a1206e3436f7710d8 Mon Sep 17 00:00:00 2001 From: Eric Soroos Date: Tue, 24 Jan 2017 05:43:58 -0800 Subject: [PATCH] added tests for functionality in ImageTk --- Tests/test_imagetk.py | 63 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 56 insertions(+), 7 deletions(-) diff --git a/Tests/test_imagetk.py b/Tests/test_imagetk.py index f56333a59..1d5a281a6 100644 --- a/Tests/test_imagetk.py +++ b/Tests/test_imagetk.py @@ -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()