diff --git a/Tests/test_file_icns.py b/Tests/test_file_icns.py deleted file mode 100644 index 3e31f8879..000000000 --- a/Tests/test_file_icns.py +++ /dev/null @@ -1,66 +0,0 @@ -from tester import * - -from PIL import Image - -# sample icon file -file = "Images/pillow.icns" -data = open(file, "rb").read() - -enable_jpeg2k = hasattr(Image.core, 'jp2klib_version') - -def test_sanity(): - # Loading this icon by default should result in the largest size - # (512x512@2x) being loaded - im = Image.open(file) - im.load() - assert_equal(im.mode, "RGBA") - assert_equal(im.size, (1024, 1024)) - assert_equal(im.format, "ICNS") - -def test_sizes(): - # Check that we can load all of the sizes, and that the final pixel - # dimensions are as expected - im = Image.open(file) - for w,h,r in im.info['sizes']: - wr = w * r - hr = h * r - im2 = Image.open(file) - im2.size = (w, h, r) - im2.load() - assert_equal(im2.mode, 'RGBA') - assert_equal(im2.size, (wr, hr)) - -def test_older_icon(): - # This icon was made with Icon Composer rather than iconutil; it still - # uses PNG rather than JP2, however (since it was made on 10.9). - im = Image.open('Tests/images/pillow2.icns') - for w,h,r in im.info['sizes']: - wr = w * r - hr = h * r - im2 = Image.open('Tests/images/pillow2.icns') - im2.size = (w, h, r) - im2.load() - assert_equal(im2.mode, 'RGBA') - assert_equal(im2.size, (wr, hr)) - -def test_jp2_icon(): - # This icon was made by using Uli Kusterer's oldiconutil to replace - # the PNG images with JPEG 2000 ones. The advantage of doing this is - # that OS X 10.5 supports JPEG 2000 but not PNG; some commercial - # software therefore does just this. - - # (oldiconutil is here: https://github.com/uliwitness/oldiconutil) - - if not enable_jpeg2k: - return - - im = Image.open('Tests/images/pillow3.icns') - for w,h,r in im.info['sizes']: - wr = w * r - hr = h * r - im2 = Image.open('Tests/images/pillow3.icns') - im2.size = (w, h, r) - im2.load() - assert_equal(im2.mode, 'RGBA') - assert_equal(im2.size, (wr, hr)) - diff --git a/Tests/test_image_resize.py b/Tests/test_image_resize.py deleted file mode 100644 index 4e228a396..000000000 --- a/Tests/test_image_resize.py +++ /dev/null @@ -1,12 +0,0 @@ -from tester import * - -from PIL import Image - -def test_resize(): - def resize(mode, size): - out = lena(mode).resize(size) - assert_equal(out.mode, mode) - assert_equal(out.size, size) - for mode in "1", "P", "L", "RGB", "I", "F": - yield_test(resize, mode, (100, 100)) - yield_test(resize, mode, (200, 200)) diff --git a/Tests/test_imagefileio.py b/Tests/test_imagefileio.py deleted file mode 100644 index c63f07bb0..000000000 --- a/Tests/test_imagefileio.py +++ /dev/null @@ -1,24 +0,0 @@ -from tester import * - -from PIL import Image -from PIL import ImageFileIO - -def test_fileio(): - - class DumbFile: - def __init__(self, data): - self.data = data - def read(self, bytes=None): - assert_equal(bytes, None) - return self.data - def close(self): - pass - - im1 = lena() - - io = ImageFileIO.ImageFileIO(DumbFile(tostring(im1, "PPM"))) - - im2 = Image.open(io) - assert_image_equal(im1, im2) - - diff --git a/Tests/test_imagetransform.py b/Tests/test_imagetransform.py deleted file mode 100644 index 884e6bb1c..000000000 --- a/Tests/test_imagetransform.py +++ /dev/null @@ -1,18 +0,0 @@ -from tester import * - -from PIL import Image -from PIL import ImageTransform - -im = Image.new("L", (100, 100)) - -seq = tuple(range(10)) - -def test_sanity(): - transform = ImageTransform.AffineTransform(seq[:6]) - assert_no_exception(lambda: im.transform((100, 100), transform)) - transform = ImageTransform.ExtentTransform(seq[:4]) - assert_no_exception(lambda: im.transform((100, 100), transform)) - transform = ImageTransform.QuadTransform(seq[:8]) - assert_no_exception(lambda: im.transform((100, 100), transform)) - transform = ImageTransform.MeshTransform([(seq[:4], seq[:8])]) - assert_no_exception(lambda: im.transform((100, 100), transform)) diff --git a/Tests/test_locale.py b/Tests/test_locale.py deleted file mode 100644 index 6b2b95201..000000000 --- a/Tests/test_locale.py +++ /dev/null @@ -1,31 +0,0 @@ -from tester import * -from PIL import Image - -import locale - -# ref https://github.com/python-pillow/Pillow/issues/272 -## on windows, in polish locale: - -## import locale -## print locale.setlocale(locale.LC_ALL, 'polish') -## import string -## print len(string.whitespace) -## print ord(string.whitespace[6]) - -## Polish_Poland.1250 -## 7 -## 160 - -# one of string.whitespace is not freely convertable into ascii. - -path = "Images/lena.jpg" - -def test_sanity(): - assert_no_exception(lambda: Image.open(path)) - try: - locale.setlocale(locale.LC_ALL, "polish") - except: - skip('polish locale not available') - import string - assert_no_exception(lambda: Image.open(path)) - diff --git a/test/helper.py b/test/helper.py index f97faf4d1..ebe651120 100644 --- a/test/helper.py +++ b/test/helper.py @@ -171,7 +171,8 @@ def tostring(im, format, **options): def lena(mode="RGB", cache={}): from PIL import Image - im = cache.get(mode) + im = None + # im = cache.get(mode) if im is None: if mode == "RGB": im = Image.open("Images/lena.ppm") @@ -181,10 +182,8 @@ def lena(mode="RGB", cache={}): im = lena("I").convert(mode) else: im = lena("RGB").convert(mode) - cache[mode] = im - import copy - duplicate = copy.copy(im) - return duplicate + # cache[mode] = im + return im # def assert_image_completely_equal(a, b, msg=None): diff --git a/test/test_file_icns.py b/test/test_file_icns.py new file mode 100644 index 000000000..9d838620b --- /dev/null +++ b/test/test_file_icns.py @@ -0,0 +1,74 @@ +from helper import unittest, PillowTestCase + +from PIL import Image + +# sample icon file +file = "Images/pillow.icns" +data = open(file, "rb").read() + +enable_jpeg2k = hasattr(Image.core, 'jp2klib_version') + + +class TestFileIcns(PillowTestCase): + + def test_sanity(self): + # Loading this icon by default should result in the largest size + # (512x512@2x) being loaded + im = Image.open(file) + im.load() + self.assertEqual(im.mode, "RGBA") + self.assertEqual(im.size, (1024, 1024)) + self.assertEqual(im.format, "ICNS") + + def test_sizes(self): + # Check that we can load all of the sizes, and that the final pixel + # dimensions are as expected + im = Image.open(file) + for w, h, r in im.info['sizes']: + wr = w * r + hr = h * r + im2 = Image.open(file) + im2.size = (w, h, r) + im2.load() + self.assertEqual(im2.mode, 'RGBA') + self.assertEqual(im2.size, (wr, hr)) + + def test_older_icon(self): + # This icon was made with Icon Composer rather than iconutil; it still + # uses PNG rather than JP2, however (since it was made on 10.9). + im = Image.open('Tests/images/pillow2.icns') + for w, h, r in im.info['sizes']: + wr = w * r + hr = h * r + im2 = Image.open('Tests/images/pillow2.icns') + im2.size = (w, h, r) + im2.load() + self.assertEqual(im2.mode, 'RGBA') + self.assertEqual(im2.size, (wr, hr)) + + def test_jp2_icon(self): + # This icon was made by using Uli Kusterer's oldiconutil to replace + # the PNG images with JPEG 2000 ones. The advantage of doing this is + # that OS X 10.5 supports JPEG 2000 but not PNG; some commercial + # software therefore does just this. + + # (oldiconutil is here: https://github.com/uliwitness/oldiconutil) + + if not enable_jpeg2k: + return + + im = Image.open('Tests/images/pillow3.icns') + for w, h, r in im.info['sizes']: + wr = w * r + hr = h * r + im2 = Image.open('Tests/images/pillow3.icns') + im2.size = (w, h, r) + im2.load() + self.assertEqual(im2.mode, 'RGBA') + self.assertEqual(im2.size, (wr, hr)) + + +if __name__ == '__main__': + unittest.main() + +# End of file diff --git a/test/test_image_resize.py b/test/test_image_resize.py new file mode 100644 index 000000000..6c9932e45 --- /dev/null +++ b/test/test_image_resize.py @@ -0,0 +1,19 @@ +from helper import unittest, PillowTestCase, lena + + +class TestImageResize(PillowTestCase): + + def test_resize(self): + def resize(mode, size): + out = lena(mode).resize(size) + self.assertEqual(out.mode, mode) + self.assertEqual(out.size, size) + for mode in "1", "P", "L", "RGB", "I", "F": + resize(mode, (100, 100)) + resize(mode, (200, 200)) + + +if __name__ == '__main__': + unittest.main() + +# End of file diff --git a/test/test_imagefileio.py b/test/test_imagefileio.py new file mode 100644 index 000000000..73f660361 --- /dev/null +++ b/test/test_imagefileio.py @@ -0,0 +1,31 @@ +from helper import unittest, PillowTestCase, lena, tostring + +from PIL import Image +from PIL import ImageFileIO + + +class TestImageFileIo(PillowTestCase): + + def test_fileio(self): + + class DumbFile: + def __init__(self, data): + self.data = data + def read(self, bytes=None): + self.assertEqual(bytes, None) + return self.data + def close(self): + pass + + im1 = lena() + + io = ImageFileIO.ImageFileIO(DumbFile(tostring(im1, "PPM"))) + + im2 = Image.open(io) + self.assert_image_equal(im1, im2) + + +if __name__ == '__main__': + unittest.main() + +# End of file diff --git a/test/test_imagetransform.py b/test/test_imagetransform.py new file mode 100644 index 000000000..f5741df32 --- /dev/null +++ b/test/test_imagetransform.py @@ -0,0 +1,27 @@ +from helper import unittest, PillowTestCase + +from PIL import Image +from PIL import ImageTransform + + +class TestImageTransform(PillowTestCase): + + def test_sanity(self): + im = Image.new("L", (100, 100)) + + seq = tuple(range(10)) + + transform = ImageTransform.AffineTransform(seq[:6]) + im.transform((100, 100), transform) + transform = ImageTransform.ExtentTransform(seq[:4]) + im.transform((100, 100), transform) + transform = ImageTransform.QuadTransform(seq[:8]) + im.transform((100, 100), transform) + transform = ImageTransform.MeshTransform([(seq[:4], seq[:8])]) + im.transform((100, 100), transform) + + +if __name__ == '__main__': + unittest.main() + +# End of file diff --git a/test/test_locale.py b/test/test_locale.py new file mode 100644 index 000000000..599e46266 --- /dev/null +++ b/test/test_locale.py @@ -0,0 +1,39 @@ +from helper import unittest, PillowTestCase, lena + +from PIL import Image + +import locale + +# ref https://github.com/python-pillow/Pillow/issues/272 +# on windows, in polish locale: + +# import locale +# print locale.setlocale(locale.LC_ALL, 'polish') +# import string +# print len(string.whitespace) +# print ord(string.whitespace[6]) + +# Polish_Poland.1250 +# 7 +# 160 + +# one of string.whitespace is not freely convertable into ascii. + +path = "Images/lena.jpg" + + +class TestLocale(PillowTestCase): + + def test_sanity(self): + Image.open(path) + try: + locale.setlocale(locale.LC_ALL, "polish") + except: + unittest.skip('Polish locale not available') + Image.open(path) + + +if __name__ == '__main__': + unittest.main() + +# End of file