From 184c380e106a48aac92f3fd58b70c8b3a82b6d28 Mon Sep 17 00:00:00 2001 From: hugovk Date: Wed, 4 Jun 2014 16:18:04 +0300 Subject: [PATCH] Convert more tests, including a method to skip on ImportError --- Tests/test_image_copy.py | 12 ------------ Tests/test_imagegrab.py | 13 ------------- test/helper.py | 20 +++++++++++--------- test/test_image_copy.py | 20 ++++++++++++++++++++ test/test_imagegrab.py | 25 +++++++++++++++++++++++++ 5 files changed, 56 insertions(+), 34 deletions(-) delete mode 100644 Tests/test_image_copy.py delete mode 100644 Tests/test_imagegrab.py create mode 100644 test/test_image_copy.py create mode 100644 test/test_imagegrab.py diff --git a/Tests/test_image_copy.py b/Tests/test_image_copy.py deleted file mode 100644 index 40a3dc496..000000000 --- a/Tests/test_image_copy.py +++ /dev/null @@ -1,12 +0,0 @@ -from tester import * - -from PIL import Image - -def test_copy(): - def copy(mode): - im = lena(mode) - out = im.copy() - assert_equal(out.mode, mode) - assert_equal(out.size, im.size) - for mode in "1", "P", "L", "RGB", "I", "F": - yield_test(copy, mode) diff --git a/Tests/test_imagegrab.py b/Tests/test_imagegrab.py deleted file mode 100644 index 67ff71960..000000000 --- a/Tests/test_imagegrab.py +++ /dev/null @@ -1,13 +0,0 @@ -from tester import * - -from PIL import Image -try: - from PIL import ImageGrab -except ImportError as v: - skip(v) - -def test_grab(): - im = ImageGrab.grab() - assert_image(im, im.mode, im.size) - - diff --git a/test/helper.py b/test/helper.py index 418f1261f..8c45858b6 100644 --- a/test/helper.py +++ b/test/helper.py @@ -12,6 +12,17 @@ else: class PillowTestCase(unittest.TestCase): + def assert_image(self, im, mode, size, msg=None): + if mode is not None: + self.assertEqual( + im.mode, mode, + msg or "got mode %r, expected %r" % (im.mode, mode)) + + if size is not None: + self.assertEqual( + im.size, size, + msg or "got size %r, expected %r" % (im.size, size)) + def assert_image_equal(self, a, b, msg=None): self.assertEqual( a.mode, b.mode, @@ -152,15 +163,6 @@ def lena(mode="RGB", cache={}): return im -# def assert_image(im, mode, size, msg=None): -# if mode is not None and im.mode != mode: -# failure(msg or "got mode %r, expected %r" % (im.mode, mode)) -# elif size is not None and im.size != size: -# failure(msg or "got size %r, expected %r" % (im.size, size)) -# else: -# success() -# -# # def assert_image_completely_equal(a, b, msg=None): # if a != b: # failure(msg or "images different") diff --git a/test/test_image_copy.py b/test/test_image_copy.py new file mode 100644 index 000000000..a7882db94 --- /dev/null +++ b/test/test_image_copy.py @@ -0,0 +1,20 @@ +from helper import unittest, PillowTestCase, lena + +from PIL import Image + + +class TestImageCopy(PillowTestCase): + + def test_copy(self): + def copy(mode): + im = lena(mode) + out = im.copy() + self.assertEqual(out.mode, mode) + self.assertEqual(out.size, im.size) + for mode in "1", "P", "L", "RGB", "I", "F": + copy(mode) + +if __name__ == '__main__': + unittest.main() + +# End of file diff --git a/test/test_imagegrab.py b/test/test_imagegrab.py new file mode 100644 index 000000000..fb953f435 --- /dev/null +++ b/test/test_imagegrab.py @@ -0,0 +1,25 @@ +from helper import unittest, PillowTestCase + +try: + from PIL import ImageGrab + + class TestImageCopy(PillowTestCase): + + def test_grab(self): + im = ImageGrab.grab() + self.assert_image(im, im.mode, im.size) + + def test_grab2(self): + im = ImageGrab.grab() + self.assert_image(im, im.mode, im.size) + +except ImportError as v: + class TestImageCopy(PillowTestCase): + def test_skip(self): + self.skipTest(v) + + +if __name__ == '__main__': + unittest.main() + +# End of file