From 2e52f3ab46d98b7978f3d145c20dc38fbd84d90f Mon Sep 17 00:00:00 2001 From: hugovk Date: Wed, 4 Jun 2014 00:05:48 +0300 Subject: [PATCH] Move more tests; remove some redundant helpers --- Tests/test_000_sanity.py | 24 --------- Tests/test_image_histogram.py | 19 ------- Tests/test_imageenhance.py | 19 ------- Tests/test_lib_image.py | 30 ----------- test/test_000_sanity.py | 32 ++++++++++++ test/test_image_histogram.py | 26 ++++++++++ test/test_imageenhance.py | 28 +++++++++++ test/test_lib_image.py | 39 +++++++++++++++ test/tester.py | 94 ----------------------------------- 9 files changed, 125 insertions(+), 186 deletions(-) delete mode 100644 Tests/test_000_sanity.py delete mode 100644 Tests/test_image_histogram.py delete mode 100644 Tests/test_imageenhance.py delete mode 100644 Tests/test_lib_image.py create mode 100644 test/test_000_sanity.py create mode 100644 test/test_image_histogram.py create mode 100644 test/test_imageenhance.py create mode 100644 test/test_lib_image.py diff --git a/Tests/test_000_sanity.py b/Tests/test_000_sanity.py deleted file mode 100644 index a30786458..000000000 --- a/Tests/test_000_sanity.py +++ /dev/null @@ -1,24 +0,0 @@ -from __future__ import print_function -from tester import * - -import PIL -import PIL.Image - -# Make sure we have the binary extension -im = PIL.Image.core.new("L", (100, 100)) - -assert PIL.Image.VERSION[:3] == '1.1' - -# Create an image and do stuff with it. -im = PIL.Image.new("1", (100, 100)) -assert (im.mode, im.size) == ('1', (100, 100)) -assert len(im.tobytes()) == 1300 - -# Create images in all remaining major modes. -im = PIL.Image.new("L", (100, 100)) -im = PIL.Image.new("P", (100, 100)) -im = PIL.Image.new("RGB", (100, 100)) -im = PIL.Image.new("I", (100, 100)) -im = PIL.Image.new("F", (100, 100)) - -print("ok") diff --git a/Tests/test_image_histogram.py b/Tests/test_image_histogram.py deleted file mode 100644 index c86cb578a..000000000 --- a/Tests/test_image_histogram.py +++ /dev/null @@ -1,19 +0,0 @@ -from tester import * - -from PIL import Image - -def test_histogram(): - - def histogram(mode): - h = lena(mode).histogram() - return len(h), min(h), max(h) - - assert_equal(histogram("1"), (256, 0, 8872)) - assert_equal(histogram("L"), (256, 0, 199)) - assert_equal(histogram("I"), (256, 0, 199)) - assert_equal(histogram("F"), (256, 0, 199)) - assert_equal(histogram("P"), (256, 0, 2912)) - assert_equal(histogram("RGB"), (768, 0, 285)) - assert_equal(histogram("RGBA"), (1024, 0, 16384)) - assert_equal(histogram("CMYK"), (1024, 0, 16384)) - assert_equal(histogram("YCbCr"), (768, 0, 741)) diff --git a/Tests/test_imageenhance.py b/Tests/test_imageenhance.py deleted file mode 100644 index 04f16bfa5..000000000 --- a/Tests/test_imageenhance.py +++ /dev/null @@ -1,19 +0,0 @@ -from tester import * - -from PIL import Image -from PIL import ImageEnhance - -def test_sanity(): - - # FIXME: assert_image - assert_no_exception(lambda: ImageEnhance.Color(lena()).enhance(0.5)) - assert_no_exception(lambda: ImageEnhance.Contrast(lena()).enhance(0.5)) - assert_no_exception(lambda: ImageEnhance.Brightness(lena()).enhance(0.5)) - assert_no_exception(lambda: ImageEnhance.Sharpness(lena()).enhance(0.5)) - -def test_crash(): - - # crashes on small images - im = Image.new("RGB", (1, 1)) - assert_no_exception(lambda: ImageEnhance.Sharpness(im).enhance(0.5)) - diff --git a/Tests/test_lib_image.py b/Tests/test_lib_image.py deleted file mode 100644 index 93aa694d8..000000000 --- a/Tests/test_lib_image.py +++ /dev/null @@ -1,30 +0,0 @@ -from tester import * - -from PIL import Image - -def test_setmode(): - - im = Image.new("L", (1, 1), 255) - im.im.setmode("1") - assert_equal(im.im.getpixel((0, 0)), 255) - im.im.setmode("L") - assert_equal(im.im.getpixel((0, 0)), 255) - - im = Image.new("1", (1, 1), 1) - im.im.setmode("L") - assert_equal(im.im.getpixel((0, 0)), 255) - im.im.setmode("1") - assert_equal(im.im.getpixel((0, 0)), 255) - - im = Image.new("RGB", (1, 1), (1, 2, 3)) - im.im.setmode("RGB") - assert_equal(im.im.getpixel((0, 0)), (1, 2, 3)) - im.im.setmode("RGBA") - assert_equal(im.im.getpixel((0, 0)), (1, 2, 3, 255)) - im.im.setmode("RGBX") - assert_equal(im.im.getpixel((0, 0)), (1, 2, 3, 255)) - im.im.setmode("RGB") - assert_equal(im.im.getpixel((0, 0)), (1, 2, 3)) - - assert_exception(ValueError, lambda: im.im.setmode("L")) - assert_exception(ValueError, lambda: im.im.setmode("RGBABCDE")) diff --git a/test/test_000_sanity.py b/test/test_000_sanity.py new file mode 100644 index 000000000..b536dd96a --- /dev/null +++ b/test/test_000_sanity.py @@ -0,0 +1,32 @@ +from tester import unittest, PillowTestCase + +import PIL +import PIL.Image + + +class TestSanity(PillowTestCase): + + def test_sanity(self): + + # Make sure we have the binary extension + im = PIL.Image.core.new("L", (100, 100)) + + self.assertEqual(PIL.Image.VERSION[:3], '1.1') + + # Create an image and do stuff with it. + im = PIL.Image.new("1", (100, 100)) + self.assertEqual((im.mode, im.size), ('1', (100, 100))) + self.assertEqual(len(im.tobytes()), 1300) + + # Create images in all remaining major modes. + im = PIL.Image.new("L", (100, 100)) + im = PIL.Image.new("P", (100, 100)) + im = PIL.Image.new("RGB", (100, 100)) + im = PIL.Image.new("I", (100, 100)) + im = PIL.Image.new("F", (100, 100)) + + +if __name__ == '__main__': + unittest.main() + +# End of file diff --git a/test/test_image_histogram.py b/test/test_image_histogram.py new file mode 100644 index 000000000..8a46149ff --- /dev/null +++ b/test/test_image_histogram.py @@ -0,0 +1,26 @@ +from tester import unittest, PillowTestCase, lena + + +class TestImageHistogram(PillowTestCase): + + def test_histogram(self): + + def histogram(mode): + h = lena(mode).histogram() + return len(h), min(h), max(h) + + self.assertEqual(histogram("1"), (256, 0, 8872)) + self.assertEqual(histogram("L"), (256, 0, 199)) + self.assertEqual(histogram("I"), (256, 0, 199)) + self.assertEqual(histogram("F"), (256, 0, 199)) + self.assertEqual(histogram("P"), (256, 0, 2912)) + self.assertEqual(histogram("RGB"), (768, 0, 285)) + self.assertEqual(histogram("RGBA"), (1024, 0, 16384)) + self.assertEqual(histogram("CMYK"), (1024, 0, 16384)) + self.assertEqual(histogram("YCbCr"), (768, 0, 741)) + + +if __name__ == '__main__': + unittest.main() + +# End of file diff --git a/test/test_imageenhance.py b/test/test_imageenhance.py new file mode 100644 index 000000000..c126bf344 --- /dev/null +++ b/test/test_imageenhance.py @@ -0,0 +1,28 @@ +from tester import unittest, PillowTestCase, lena + +from PIL import Image +from PIL import ImageEnhance + + +class TestImageEnhance(PillowTestCase): + + def test_sanity(self): + + # FIXME: assert_image + # Implicit asserts no exception: + ImageEnhance.Color(lena()).enhance(0.5) + ImageEnhance.Contrast(lena()).enhance(0.5) + ImageEnhance.Brightness(lena()).enhance(0.5) + ImageEnhance.Sharpness(lena()).enhance(0.5) + + def test_crash(self): + + # crashes on small images + im = Image.new("RGB", (1, 1)) + ImageEnhance.Sharpness(im).enhance(0.5) + + +if __name__ == '__main__': + unittest.main() + +# End of file diff --git a/test/test_lib_image.py b/test/test_lib_image.py new file mode 100644 index 000000000..8694c1d51 --- /dev/null +++ b/test/test_lib_image.py @@ -0,0 +1,39 @@ +from tester import unittest, PillowTestCase + +from PIL import Image + + +class TestSanity(PillowTestCase): + + def test_setmode(self): + + im = Image.new("L", (1, 1), 255) + im.im.setmode("1") + self.assertEqual(im.im.getpixel((0, 0)), 255) + im.im.setmode("L") + self.assertEqual(im.im.getpixel((0, 0)), 255) + + im = Image.new("1", (1, 1), 1) + im.im.setmode("L") + self.assertEqual(im.im.getpixel((0, 0)), 255) + im.im.setmode("1") + self.assertEqual(im.im.getpixel((0, 0)), 255) + + im = Image.new("RGB", (1, 1), (1, 2, 3)) + im.im.setmode("RGB") + self.assertEqual(im.im.getpixel((0, 0)), (1, 2, 3)) + im.im.setmode("RGBA") + self.assertEqual(im.im.getpixel((0, 0)), (1, 2, 3, 255)) + im.im.setmode("RGBX") + self.assertEqual(im.im.getpixel((0, 0)), (1, 2, 3, 255)) + im.im.setmode("RGB") + self.assertEqual(im.im.getpixel((0, 0)), (1, 2, 3)) + + self.assertRaises(ValueError, lambda: im.im.setmode("L")) + self.assertRaises(ValueError, lambda: im.im.setmode("RGBABCDE")) + + +if __name__ == '__main__': + unittest.main() + +# End of file diff --git a/test/tester.py b/test/tester.py index 894d37883..8df32e317 100644 --- a/test/tester.py +++ b/test/tester.py @@ -112,51 +112,6 @@ py3 = (sys.version_info >= (3, 0)) # assert_equal(a, b, msg) # # -# def assert_greater(a, b, msg=None): -# if a > b: -# success() -# else: -# failure(msg or "%r unexpectedly not greater than %r" % (a, b)) -# -# -# def assert_greater_equal(a, b, msg=None): -# if a >= b: -# success() -# else: -# failure( -# msg or "%r unexpectedly not greater than or equal to %r" -# % (a, b)) -# -# -# def assert_less(a, b, msg=None): -# if a < b: -# success() -# else: -# failure(msg or "%r unexpectedly not less than %r" % (a, b)) -# -# -# def assert_less_equal(a, b, msg=None): -# if a <= b: -# success() -# else: -# failure( -# msg or "%r unexpectedly not less than or equal to %r" % (a, b)) -# -# -# def assert_is_instance(a, b, msg=None): -# if isinstance(a, b): -# success() -# else: -# failure(msg or "got %r, expected %r" % (type(a), b)) -# -# -# def assert_in(a, b, msg=None): -# if a in b: -# success() -# else: -# failure(msg or "%r unexpectedly not in %r" % (a, b)) -# -# # def assert_match(v, pattern, msg=None): # import re # if re.match(pattern, v): @@ -165,55 +120,6 @@ py3 = (sys.version_info >= (3, 0)) # failure(msg or "got %r, doesn't match pattern %r" % (v, pattern)) # # -# def assert_exception(exc_class, func): -# import sys -# import traceback -# try: -# func() -# except exc_class: -# success() -# except: -# failure("expected %r exception, got %r" % ( -# exc_class.__name__, sys.exc_info()[0].__name__)) -# traceback.print_exc() -# else: -# failure( -# "expected %r exception, got no exception" % exc_class.__name__) -# -# -# def assert_no_exception(func): -# import sys -# import traceback -# try: -# func() -# except: -# failure("expected no exception, got %r" % sys.exc_info()[0].__name__) -# traceback.print_exc() -# else: -# success() -# -# -# def assert_warning(warn_class, func): -# # note: this assert calls func three times! -# import warnings -# -# def warn_error(message, category=UserWarning, **options): -# raise category(message) -# -# def warn_ignore(message, category=UserWarning, **options): -# pass -# warn = warnings.warn -# result = None -# try: -# warnings.warn = warn_ignore -# assert_no_exception(func) -# result = func() -# warnings.warn = warn_error -# assert_exception(warn_class, func) -# finally: -# warnings.warn = warn # restore -# return result -# # # helpers # # from io import BytesIO