mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-25 00:34:14 +03:00
Convert more tests
This commit is contained in:
parent
cbb2f9dce9
commit
c4d3898006
|
@ -1,14 +0,0 @@
|
|||
from tester import *
|
||||
|
||||
from PIL import Image
|
||||
|
||||
# sample ppm stream
|
||||
file = "Images/lena.ico"
|
||||
data = open(file, "rb").read()
|
||||
|
||||
def test_sanity():
|
||||
im = Image.open(file)
|
||||
im.load()
|
||||
assert_equal(im.mode, "RGBA")
|
||||
assert_equal(im.size, (16, 16))
|
||||
assert_equal(im.format, "ICO")
|
|
@ -1,13 +0,0 @@
|
|||
from tester import *
|
||||
|
||||
from PIL import Image, FontFile, BdfFontFile
|
||||
|
||||
filename = "Images/courB08.bdf"
|
||||
|
||||
def test_sanity():
|
||||
|
||||
file = open(filename, "rb")
|
||||
font = BdfFontFile.BdfFontFile(file)
|
||||
|
||||
assert_true(isinstance(font, FontFile.FontFile))
|
||||
assert_equal(len([_f for _f in font.glyph if _f]), 190)
|
|
@ -1,16 +0,0 @@
|
|||
from tester import *
|
||||
|
||||
from PIL import Image
|
||||
|
||||
def test_offset():
|
||||
|
||||
im1 = lena()
|
||||
|
||||
im2 = assert_warning(DeprecationWarning, lambda: im1.offset(10))
|
||||
assert_equal(im1.getpixel((0, 0)), im2.getpixel((10, 10)))
|
||||
|
||||
im2 = assert_warning(DeprecationWarning, lambda: im1.offset(10, 20))
|
||||
assert_equal(im1.getpixel((0, 0)), im2.getpixel((10, 20)))
|
||||
|
||||
im2 = assert_warning(DeprecationWarning, lambda: im1.offset(20, 20))
|
||||
assert_equal(im1.getpixel((0, 0)), im2.getpixel((20, 20)))
|
|
@ -1,203 +0,0 @@
|
|||
from tester import *
|
||||
|
||||
from PIL import Image
|
||||
try:
|
||||
from PIL import ImageCms
|
||||
ImageCms.core.profile_open
|
||||
except ImportError:
|
||||
skip()
|
||||
|
||||
SRGB = "Tests/icc/sRGB.icm"
|
||||
|
||||
|
||||
def test_sanity():
|
||||
|
||||
# basic smoke test.
|
||||
# this mostly follows the cms_test outline.
|
||||
|
||||
v = ImageCms.versions() # should return four strings
|
||||
assert_equal(v[0], '1.0.0 pil')
|
||||
assert_equal(list(map(type, v)), [str, str, str, str])
|
||||
|
||||
# internal version number
|
||||
assert_match(ImageCms.core.littlecms_version, "\d+\.\d+$")
|
||||
|
||||
i = ImageCms.profileToProfile(lena(), SRGB, SRGB)
|
||||
assert_image(i, "RGB", (128, 128))
|
||||
|
||||
i = lena()
|
||||
ImageCms.profileToProfile(i, SRGB, SRGB, inPlace=True)
|
||||
assert_image(i, "RGB", (128, 128))
|
||||
|
||||
t = ImageCms.buildTransform(SRGB, SRGB, "RGB", "RGB")
|
||||
i = ImageCms.applyTransform(lena(), t)
|
||||
assert_image(i, "RGB", (128, 128))
|
||||
|
||||
i = lena()
|
||||
t = ImageCms.buildTransform(SRGB, SRGB, "RGB", "RGB")
|
||||
ImageCms.applyTransform(lena(), t, inPlace=True)
|
||||
assert_image(i, "RGB", (128, 128))
|
||||
|
||||
p = ImageCms.createProfile("sRGB")
|
||||
o = ImageCms.getOpenProfile(SRGB)
|
||||
t = ImageCms.buildTransformFromOpenProfiles(p, o, "RGB", "RGB")
|
||||
i = ImageCms.applyTransform(lena(), t)
|
||||
assert_image(i, "RGB", (128, 128))
|
||||
|
||||
t = ImageCms.buildProofTransform(SRGB, SRGB, SRGB, "RGB", "RGB")
|
||||
assert_equal(t.inputMode, "RGB")
|
||||
assert_equal(t.outputMode, "RGB")
|
||||
i = ImageCms.applyTransform(lena(), t)
|
||||
assert_image(i, "RGB", (128, 128))
|
||||
|
||||
# test PointTransform convenience API
|
||||
lena().point(t)
|
||||
|
||||
|
||||
def test_name():
|
||||
# get profile information for file
|
||||
assert_equal(ImageCms.getProfileName(SRGB).strip(),
|
||||
'IEC 61966-2.1 Default RGB colour space - sRGB')
|
||||
|
||||
|
||||
def test_info():
|
||||
assert_equal(ImageCms.getProfileInfo(SRGB).splitlines(),
|
||||
['sRGB IEC61966-2.1', '',
|
||||
'Copyright (c) 1998 Hewlett-Packard Company', ''])
|
||||
|
||||
|
||||
def test_copyright():
|
||||
assert_equal(ImageCms.getProfileCopyright(SRGB).strip(),
|
||||
'Copyright (c) 1998 Hewlett-Packard Company')
|
||||
|
||||
|
||||
def test_manufacturer():
|
||||
assert_equal(ImageCms.getProfileManufacturer(SRGB).strip(),
|
||||
'IEC http://www.iec.ch')
|
||||
|
||||
|
||||
def test_model():
|
||||
assert_equal(ImageCms.getProfileModel(SRGB).strip(),
|
||||
'IEC 61966-2.1 Default RGB colour space - sRGB')
|
||||
|
||||
|
||||
def test_description():
|
||||
assert_equal(ImageCms.getProfileDescription(SRGB).strip(),
|
||||
'sRGB IEC61966-2.1')
|
||||
|
||||
|
||||
def test_intent():
|
||||
assert_equal(ImageCms.getDefaultIntent(SRGB), 0)
|
||||
assert_equal(ImageCms.isIntentSupported(
|
||||
SRGB, ImageCms.INTENT_ABSOLUTE_COLORIMETRIC,
|
||||
ImageCms.DIRECTION_INPUT), 1)
|
||||
|
||||
|
||||
def test_profile_object():
|
||||
# same, using profile object
|
||||
p = ImageCms.createProfile("sRGB")
|
||||
# assert_equal(ImageCms.getProfileName(p).strip(),
|
||||
# 'sRGB built-in - (lcms internal)')
|
||||
# assert_equal(ImageCms.getProfileInfo(p).splitlines(),
|
||||
# ['sRGB built-in', '', 'WhitePoint : D65 (daylight)', '', ''])
|
||||
assert_equal(ImageCms.getDefaultIntent(p), 0)
|
||||
assert_equal(ImageCms.isIntentSupported(
|
||||
p, ImageCms.INTENT_ABSOLUTE_COLORIMETRIC,
|
||||
ImageCms.DIRECTION_INPUT), 1)
|
||||
|
||||
|
||||
def test_extensions():
|
||||
# extensions
|
||||
i = Image.open("Tests/images/rgb.jpg")
|
||||
p = ImageCms.getOpenProfile(BytesIO(i.info["icc_profile"]))
|
||||
assert_equal(ImageCms.getProfileName(p).strip(),
|
||||
'IEC 61966-2.1 Default RGB colour space - sRGB')
|
||||
|
||||
|
||||
def test_exceptions():
|
||||
# the procedural pyCMS API uses PyCMSError for all sorts of errors
|
||||
assert_exception(
|
||||
ImageCms.PyCMSError,
|
||||
lambda: ImageCms.profileToProfile(lena(), "foo", "bar"))
|
||||
assert_exception(
|
||||
ImageCms.PyCMSError,
|
||||
lambda: ImageCms.buildTransform("foo", "bar", "RGB", "RGB"))
|
||||
assert_exception(
|
||||
ImageCms.PyCMSError,
|
||||
lambda: ImageCms.getProfileName(None))
|
||||
assert_exception(
|
||||
ImageCms.PyCMSError,
|
||||
lambda: ImageCms.isIntentSupported(SRGB, None, None))
|
||||
|
||||
|
||||
def test_display_profile():
|
||||
# try fetching the profile for the current display device
|
||||
assert_no_exception(lambda: ImageCms.get_display_profile())
|
||||
|
||||
|
||||
def test_lab_color_profile():
|
||||
ImageCms.createProfile("LAB", 5000)
|
||||
ImageCms.createProfile("LAB", 6500)
|
||||
|
||||
|
||||
def test_simple_lab():
|
||||
i = Image.new('RGB', (10, 10), (128, 128, 128))
|
||||
|
||||
pLab = ImageCms.createProfile("LAB")
|
||||
t = ImageCms.buildTransform(SRGB, pLab, "RGB", "LAB")
|
||||
|
||||
i_lab = ImageCms.applyTransform(i, t)
|
||||
|
||||
assert_equal(i_lab.mode, 'LAB')
|
||||
|
||||
k = i_lab.getpixel((0, 0))
|
||||
assert_equal(k, (137, 128, 128)) # not a linear luminance map. so L != 128
|
||||
|
||||
L = i_lab.getdata(0)
|
||||
a = i_lab.getdata(1)
|
||||
b = i_lab.getdata(2)
|
||||
|
||||
assert_equal(list(L), [137] * 100)
|
||||
assert_equal(list(a), [128] * 100)
|
||||
assert_equal(list(b), [128] * 100)
|
||||
|
||||
|
||||
def test_lab_color():
|
||||
pLab = ImageCms.createProfile("LAB")
|
||||
t = ImageCms.buildTransform(SRGB, pLab, "RGB", "LAB")
|
||||
# Need to add a type mapping for some PIL type to TYPE_Lab_8 in
|
||||
# findLCMSType, and have that mapping work back to a PIL mode (likely RGB).
|
||||
i = ImageCms.applyTransform(lena(), t)
|
||||
assert_image(i, "LAB", (128, 128))
|
||||
|
||||
# i.save('temp.lab.tif') # visually verified vs PS.
|
||||
|
||||
target = Image.open('Tests/images/lena.Lab.tif')
|
||||
|
||||
assert_image_similar(i, target, 30)
|
||||
|
||||
|
||||
def test_lab_srgb():
|
||||
pLab = ImageCms.createProfile("LAB")
|
||||
t = ImageCms.buildTransform(pLab, SRGB, "LAB", "RGB")
|
||||
|
||||
img = Image.open('Tests/images/lena.Lab.tif')
|
||||
|
||||
img_srgb = ImageCms.applyTransform(img, t)
|
||||
|
||||
# img_srgb.save('temp.srgb.tif') # visually verified vs ps.
|
||||
|
||||
assert_image_similar(lena(), img_srgb, 30)
|
||||
|
||||
|
||||
def test_lab_roundtrip():
|
||||
# check to see if we're at least internally consistent.
|
||||
pLab = ImageCms.createProfile("LAB")
|
||||
t = ImageCms.buildTransform(SRGB, pLab, "RGB", "LAB")
|
||||
|
||||
t2 = ImageCms.buildTransform(pLab, SRGB, "LAB", "RGB")
|
||||
|
||||
i = ImageCms.applyTransform(lena(), t)
|
||||
out = ImageCms.applyTransform(i, t2)
|
||||
|
||||
assert_image_similar(lena(), out, 2)
|
|
@ -1,23 +0,0 @@
|
|||
from tester import *
|
||||
|
||||
from PIL import Image
|
||||
from PIL import ImageMode
|
||||
|
||||
ImageMode.getmode("1")
|
||||
ImageMode.getmode("L")
|
||||
ImageMode.getmode("P")
|
||||
ImageMode.getmode("RGB")
|
||||
ImageMode.getmode("I")
|
||||
ImageMode.getmode("F")
|
||||
|
||||
m = ImageMode.getmode("1")
|
||||
assert_equal(m.mode, "1")
|
||||
assert_equal(m.bands, ("1",))
|
||||
assert_equal(m.basemode, "L")
|
||||
assert_equal(m.basetype, "L")
|
||||
|
||||
m = ImageMode.getmode("RGB")
|
||||
assert_equal(m.mode, "RGB")
|
||||
assert_equal(m.bands, ("R", "G", "B"))
|
||||
assert_equal(m.basemode, "RGB")
|
||||
assert_equal(m.basetype, "L")
|
|
@ -1,6 +0,0 @@
|
|||
from tester import *
|
||||
|
||||
from PIL import Image
|
||||
from PIL import ImageShow
|
||||
|
||||
success()
|
|
@ -1,9 +0,0 @@
|
|||
from tester import *
|
||||
|
||||
from PIL import Image
|
||||
try:
|
||||
from PIL import ImageTk
|
||||
except (OSError, ImportError) as v:
|
||||
skip(v)
|
||||
|
||||
success()
|
|
@ -1,6 +0,0 @@
|
|||
from tester import *
|
||||
|
||||
from PIL import Image
|
||||
from PIL import ImageWin
|
||||
|
||||
success()
|
|
@ -60,18 +60,19 @@ class PillowTestCase(unittest.TestCase):
|
|||
def assert_warning(self, warn_class, func):
|
||||
import warnings
|
||||
|
||||
result = None
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
# Cause all warnings to always be triggered.
|
||||
warnings.simplefilter("always")
|
||||
|
||||
# Hopefully trigger a warning.
|
||||
func()
|
||||
result = func()
|
||||
|
||||
# Verify some things.
|
||||
self.assertEqual(len(w), 1)
|
||||
assert issubclass(w[-1].category, warn_class)
|
||||
self.assertIn("deprecated", str(w[-1].message))
|
||||
|
||||
return result
|
||||
|
||||
# # require that deprecation warnings are triggered
|
||||
# import warnings
|
||||
|
|
23
test/test_file_ico.py
Normal file
23
test/test_file_ico.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
from helper import unittest, PillowTestCase
|
||||
|
||||
from PIL import Image
|
||||
|
||||
# sample ppm stream
|
||||
file = "Images/lena.ico"
|
||||
data = open(file, "rb").read()
|
||||
|
||||
|
||||
class TestFileIco(PillowTestCase):
|
||||
|
||||
def test_sanity(self):
|
||||
im = Image.open(file)
|
||||
im.load()
|
||||
self.assertEqual(im.mode, "RGBA")
|
||||
self.assertEqual(im.size, (16, 16))
|
||||
self.assertEqual(im.format, "ICO")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
# End of file
|
22
test/test_font_bdf.py
Normal file
22
test/test_font_bdf.py
Normal file
|
@ -0,0 +1,22 @@
|
|||
from helper import unittest, PillowTestCase
|
||||
|
||||
from PIL import FontFile, BdfFontFile
|
||||
|
||||
filename = "Images/courB08.bdf"
|
||||
|
||||
|
||||
class TestImage(PillowTestCase):
|
||||
|
||||
def test_sanity(self):
|
||||
|
||||
file = open(filename, "rb")
|
||||
font = BdfFontFile.BdfFontFile(file)
|
||||
|
||||
self.assertIsInstance(font, FontFile.FontFile)
|
||||
self.assertEqual(len([_f for _f in font.glyph if _f]), 190)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
# End of file
|
25
test/test_image_offset.py
Normal file
25
test/test_image_offset.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
from helper import unittest, PillowTestCase, lena
|
||||
|
||||
|
||||
class TestImage(PillowTestCase):
|
||||
|
||||
def test_offset(self):
|
||||
|
||||
im1 = lena()
|
||||
|
||||
im2 = self.assert_warning(DeprecationWarning, lambda: im1.offset(10))
|
||||
self.assertEqual(im1.getpixel((0, 0)), im2.getpixel((10, 10)))
|
||||
|
||||
im2 = self.assert_warning(
|
||||
DeprecationWarning, lambda: im1.offset(10, 20))
|
||||
self.assertEqual(im1.getpixel((0, 0)), im2.getpixel((10, 20)))
|
||||
|
||||
im2 = self.assert_warning(
|
||||
DeprecationWarning, lambda: im1.offset(20, 20))
|
||||
self.assertEqual(im1.getpixel((0, 0)), im2.getpixel((20, 20)))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
# End of file
|
214
test/test_imagecms.py
Normal file
214
test/test_imagecms.py
Normal file
|
@ -0,0 +1,214 @@
|
|||
from helper import unittest, PillowTestCase, lena
|
||||
|
||||
from PIL import Image
|
||||
|
||||
try:
|
||||
from PIL import ImageCms
|
||||
ImageCms.core.profile_open
|
||||
except ImportError as v:
|
||||
# Skipped via setUp()
|
||||
pass
|
||||
|
||||
|
||||
SRGB = "Tests/icc/sRGB.icm"
|
||||
|
||||
|
||||
class TestImage(PillowTestCase):
|
||||
|
||||
def setUp(self):
|
||||
try:
|
||||
from PIL import ImageCms
|
||||
except ImportError as v:
|
||||
self.skipTest(v)
|
||||
|
||||
def test_sanity(self):
|
||||
|
||||
# basic smoke test.
|
||||
# this mostly follows the cms_test outline.
|
||||
|
||||
v = ImageCms.versions() # should return four strings
|
||||
self.assertEqual(v[0], '1.0.0 pil')
|
||||
self.assertEqual(list(map(type, v)), [str, str, str, str])
|
||||
|
||||
# internal version number
|
||||
self.assertRegexpMatches(ImageCms.core.littlecms_version, "\d+\.\d+$")
|
||||
|
||||
i = ImageCms.profileToProfile(lena(), SRGB, SRGB)
|
||||
self.assert_image(i, "RGB", (128, 128))
|
||||
|
||||
i = lena()
|
||||
ImageCms.profileToProfile(i, SRGB, SRGB, inPlace=True)
|
||||
self.assert_image(i, "RGB", (128, 128))
|
||||
|
||||
t = ImageCms.buildTransform(SRGB, SRGB, "RGB", "RGB")
|
||||
i = ImageCms.applyTransform(lena(), t)
|
||||
self.assert_image(i, "RGB", (128, 128))
|
||||
|
||||
i = lena()
|
||||
t = ImageCms.buildTransform(SRGB, SRGB, "RGB", "RGB")
|
||||
ImageCms.applyTransform(lena(), t, inPlace=True)
|
||||
self.assert_image(i, "RGB", (128, 128))
|
||||
|
||||
p = ImageCms.createProfile("sRGB")
|
||||
o = ImageCms.getOpenProfile(SRGB)
|
||||
t = ImageCms.buildTransformFromOpenProfiles(p, o, "RGB", "RGB")
|
||||
i = ImageCms.applyTransform(lena(), t)
|
||||
self.assert_image(i, "RGB", (128, 128))
|
||||
|
||||
t = ImageCms.buildProofTransform(SRGB, SRGB, SRGB, "RGB", "RGB")
|
||||
self.assertEqual(t.inputMode, "RGB")
|
||||
self.assertEqual(t.outputMode, "RGB")
|
||||
i = ImageCms.applyTransform(lena(), t)
|
||||
self.assert_image(i, "RGB", (128, 128))
|
||||
|
||||
# test PointTransform convenience API
|
||||
lena().point(t)
|
||||
|
||||
def test_name(self):
|
||||
# get profile information for file
|
||||
self.assertEqual(
|
||||
ImageCms.getProfileName(SRGB).strip(),
|
||||
'IEC 61966-2.1 Default RGB colour space - sRGB')
|
||||
|
||||
def test_info(self):
|
||||
self.assertEqual(
|
||||
ImageCms.getProfileInfo(SRGB).splitlines(), [
|
||||
'sRGB IEC61966-2.1', '',
|
||||
'Copyright (c) 1998 Hewlett-Packard Company', ''])
|
||||
|
||||
def test_copyright(self):
|
||||
self.assertEqual(
|
||||
ImageCms.getProfileCopyright(SRGB).strip(),
|
||||
'Copyright (c) 1998 Hewlett-Packard Company')
|
||||
|
||||
def test_manufacturer(self):
|
||||
self.assertEqual(
|
||||
ImageCms.getProfileManufacturer(SRGB).strip(),
|
||||
'IEC http://www.iec.ch')
|
||||
|
||||
def test_model(self):
|
||||
self.assertEqual(
|
||||
ImageCms.getProfileModel(SRGB).strip(),
|
||||
'IEC 61966-2.1 Default RGB colour space - sRGB')
|
||||
|
||||
def test_description(self):
|
||||
self.assertEqual(
|
||||
ImageCms.getProfileDescription(SRGB).strip(),
|
||||
'sRGB IEC61966-2.1')
|
||||
|
||||
def test_intent(self):
|
||||
self.assertEqual(ImageCms.getDefaultIntent(SRGB), 0)
|
||||
self.assertEqual(ImageCms.isIntentSupported(
|
||||
SRGB, ImageCms.INTENT_ABSOLUTE_COLORIMETRIC,
|
||||
ImageCms.DIRECTION_INPUT), 1)
|
||||
|
||||
def test_profile_object(self):
|
||||
# same, using profile object
|
||||
p = ImageCms.createProfile("sRGB")
|
||||
# self.assertEqual(ImageCms.getProfileName(p).strip(),
|
||||
# 'sRGB built-in - (lcms internal)')
|
||||
# self.assertEqual(ImageCms.getProfileInfo(p).splitlines(),
|
||||
# ['sRGB built-in', '', 'WhitePoint : D65 (daylight)', '', ''])
|
||||
self.assertEqual(ImageCms.getDefaultIntent(p), 0)
|
||||
self.assertEqual(ImageCms.isIntentSupported(
|
||||
p, ImageCms.INTENT_ABSOLUTE_COLORIMETRIC,
|
||||
ImageCms.DIRECTION_INPUT), 1)
|
||||
|
||||
def test_extensions(self):
|
||||
# extensions
|
||||
from io import BytesIO
|
||||
i = Image.open("Tests/images/rgb.jpg")
|
||||
p = ImageCms.getOpenProfile(BytesIO(i.info["icc_profile"]))
|
||||
self.assertEqual(
|
||||
ImageCms.getProfileName(p).strip(),
|
||||
'IEC 61966-2.1 Default RGB colour space - sRGB')
|
||||
|
||||
def test_exceptions(self):
|
||||
# the procedural pyCMS API uses PyCMSError for all sorts of errors
|
||||
self.assertRaises(
|
||||
ImageCms.PyCMSError,
|
||||
lambda: ImageCms.profileToProfile(lena(), "foo", "bar"))
|
||||
self.assertRaises(
|
||||
ImageCms.PyCMSError,
|
||||
lambda: ImageCms.buildTransform("foo", "bar", "RGB", "RGB"))
|
||||
self.assertRaises(
|
||||
ImageCms.PyCMSError,
|
||||
lambda: ImageCms.getProfileName(None))
|
||||
self.assertRaises(
|
||||
ImageCms.PyCMSError,
|
||||
lambda: ImageCms.isIntentSupported(SRGB, None, None))
|
||||
|
||||
def test_display_profile(self):
|
||||
# try fetching the profile for the current display device
|
||||
ImageCms.get_display_profile()
|
||||
|
||||
def test_lab_color_profile(self):
|
||||
ImageCms.createProfile("LAB", 5000)
|
||||
ImageCms.createProfile("LAB", 6500)
|
||||
|
||||
def test_simple_lab(self):
|
||||
i = Image.new('RGB', (10, 10), (128, 128, 128))
|
||||
|
||||
pLab = ImageCms.createProfile("LAB")
|
||||
t = ImageCms.buildTransform(SRGB, pLab, "RGB", "LAB")
|
||||
|
||||
i_lab = ImageCms.applyTransform(i, t)
|
||||
|
||||
self.assertEqual(i_lab.mode, 'LAB')
|
||||
|
||||
k = i_lab.getpixel((0, 0))
|
||||
# not a linear luminance map. so L != 128:
|
||||
self.assertEqual(k, (137, 128, 128))
|
||||
|
||||
L = i_lab.getdata(0)
|
||||
a = i_lab.getdata(1)
|
||||
b = i_lab.getdata(2)
|
||||
|
||||
self.assertEqual(list(L), [137] * 100)
|
||||
self.assertEqual(list(a), [128] * 100)
|
||||
self.assertEqual(list(b), [128] * 100)
|
||||
|
||||
def test_lab_color(self):
|
||||
pLab = ImageCms.createProfile("LAB")
|
||||
t = ImageCms.buildTransform(SRGB, pLab, "RGB", "LAB")
|
||||
# Need to add a type mapping for some PIL type to TYPE_Lab_8 in
|
||||
# findLCMSType, and have that mapping work back to a PIL mode
|
||||
# (likely RGB).
|
||||
i = ImageCms.applyTransform(lena(), t)
|
||||
self.assert_image(i, "LAB", (128, 128))
|
||||
|
||||
# i.save('temp.lab.tif') # visually verified vs PS.
|
||||
|
||||
target = Image.open('Tests/images/lena.Lab.tif')
|
||||
|
||||
self.assert_image_similar(i, target, 30)
|
||||
|
||||
def test_lab_srgb(self):
|
||||
pLab = ImageCms.createProfile("LAB")
|
||||
t = ImageCms.buildTransform(pLab, SRGB, "LAB", "RGB")
|
||||
|
||||
img = Image.open('Tests/images/lena.Lab.tif')
|
||||
|
||||
img_srgb = ImageCms.applyTransform(img, t)
|
||||
|
||||
# img_srgb.save('temp.srgb.tif') # visually verified vs ps.
|
||||
|
||||
self.assert_image_similar(lena(), img_srgb, 30)
|
||||
|
||||
def test_lab_roundtrip(self):
|
||||
# check to see if we're at least internally consistent.
|
||||
pLab = ImageCms.createProfile("LAB")
|
||||
t = ImageCms.buildTransform(SRGB, pLab, "RGB", "LAB")
|
||||
|
||||
t2 = ImageCms.buildTransform(pLab, SRGB, "LAB", "RGB")
|
||||
|
||||
i = ImageCms.applyTransform(lena(), t)
|
||||
out = ImageCms.applyTransform(i, t2)
|
||||
|
||||
self.assert_image_similar(lena(), out, 2)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
# End of file
|
32
test/test_imagemode.py
Normal file
32
test/test_imagemode.py
Normal file
|
@ -0,0 +1,32 @@
|
|||
from helper import unittest, PillowTestCase
|
||||
|
||||
from PIL import ImageMode
|
||||
|
||||
|
||||
class TestImage(PillowTestCase):
|
||||
|
||||
def test_sanity(self):
|
||||
ImageMode.getmode("1")
|
||||
ImageMode.getmode("L")
|
||||
ImageMode.getmode("P")
|
||||
ImageMode.getmode("RGB")
|
||||
ImageMode.getmode("I")
|
||||
ImageMode.getmode("F")
|
||||
|
||||
m = ImageMode.getmode("1")
|
||||
self.assertEqual(m.mode, "1")
|
||||
self.assertEqual(m.bands, ("1",))
|
||||
self.assertEqual(m.basemode, "L")
|
||||
self.assertEqual(m.basetype, "L")
|
||||
|
||||
m = ImageMode.getmode("RGB")
|
||||
self.assertEqual(m.mode, "RGB")
|
||||
self.assertEqual(m.bands, ("R", "G", "B"))
|
||||
self.assertEqual(m.basemode, "RGB")
|
||||
self.assertEqual(m.basetype, "L")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
# End of file
|
18
test/test_imageshow.py
Normal file
18
test/test_imageshow.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
from helper import unittest, PillowTestCase
|
||||
|
||||
from PIL import Image
|
||||
from PIL import ImageShow
|
||||
|
||||
|
||||
class TestImage(PillowTestCase):
|
||||
|
||||
def test_sanity(self):
|
||||
dir(Image)
|
||||
dir(ImageShow)
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
# End of file
|
17
test/test_imagetk.py
Normal file
17
test/test_imagetk.py
Normal file
|
@ -0,0 +1,17 @@
|
|||
from helper import unittest, PillowTestCase
|
||||
|
||||
|
||||
class TestImageTk(PillowTestCase):
|
||||
|
||||
def test_import(self):
|
||||
try:
|
||||
from PIL import ImageTk
|
||||
dir(ImageTk)
|
||||
except (OSError, ImportError) as v:
|
||||
self.skipTest(v)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
# End of file
|
18
test/test_imagewin.py
Normal file
18
test/test_imagewin.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
from helper import unittest, PillowTestCase, lena
|
||||
|
||||
from PIL import Image
|
||||
from PIL import ImageWin
|
||||
|
||||
|
||||
class TestImage(PillowTestCase):
|
||||
|
||||
def test_sanity(self):
|
||||
dir(Image)
|
||||
dir(ImageShow)
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
# End of file
|
Loading…
Reference in New Issue
Block a user