mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-11 04:07:21 +03:00
Disable lena() caching for now, convert more tests
This commit is contained in:
parent
c45f20119c
commit
3ff2ea4883
|
@ -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))
|
|
||||||
|
|
|
@ -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))
|
|
|
@ -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)
|
|
||||||
|
|
||||||
|
|
|
@ -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))
|
|
|
@ -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))
|
|
||||||
|
|
|
@ -171,7 +171,8 @@ def tostring(im, format, **options):
|
||||||
|
|
||||||
def lena(mode="RGB", cache={}):
|
def lena(mode="RGB", cache={}):
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
im = cache.get(mode)
|
im = None
|
||||||
|
# im = cache.get(mode)
|
||||||
if im is None:
|
if im is None:
|
||||||
if mode == "RGB":
|
if mode == "RGB":
|
||||||
im = Image.open("Images/lena.ppm")
|
im = Image.open("Images/lena.ppm")
|
||||||
|
@ -181,10 +182,8 @@ def lena(mode="RGB", cache={}):
|
||||||
im = lena("I").convert(mode)
|
im = lena("I").convert(mode)
|
||||||
else:
|
else:
|
||||||
im = lena("RGB").convert(mode)
|
im = lena("RGB").convert(mode)
|
||||||
cache[mode] = im
|
# cache[mode] = im
|
||||||
import copy
|
return im
|
||||||
duplicate = copy.copy(im)
|
|
||||||
return duplicate
|
|
||||||
|
|
||||||
|
|
||||||
# def assert_image_completely_equal(a, b, msg=None):
|
# def assert_image_completely_equal(a, b, msg=None):
|
||||||
|
|
74
test/test_file_icns.py
Normal file
74
test/test_file_icns.py
Normal file
|
@ -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
|
19
test/test_image_resize.py
Normal file
19
test/test_image_resize.py
Normal file
|
@ -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
|
31
test/test_imagefileio.py
Normal file
31
test/test_imagefileio.py
Normal file
|
@ -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
|
27
test/test_imagetransform.py
Normal file
27
test/test_imagetransform.py
Normal file
|
@ -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
|
39
test/test_locale.py
Normal file
39
test/test_locale.py
Normal file
|
@ -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
|
Loading…
Reference in New Issue
Block a user