pep8/pyflakes

This commit is contained in:
hugovk 2014-06-02 12:41:48 +03:00
parent 4c2b3a6afc
commit e983057294

View File

@ -9,12 +9,13 @@ except ImportError:
SRGB = "Tests/icc/sRGB.icm" SRGB = "Tests/icc/sRGB.icm"
def test_sanity(): def test_sanity():
# basic smoke test. # basic smoke test.
# this mostly follows the cms_test outline. # this mostly follows the cms_test outline.
v = ImageCms.versions() # should return four strings v = ImageCms.versions() # should return four strings
assert_equal(v[0], '1.0.0 pil') assert_equal(v[0], '1.0.0 pil')
assert_equal(list(map(type, v)), [str, str, str, str]) assert_equal(list(map(type, v)), [str, str, str, str])
@ -41,12 +42,15 @@ def test_sanity():
assert_image(i, "RGB", (128, 128)) assert_image(i, "RGB", (128, 128))
# test PointTransform convenience API # test PointTransform convenience API
im = lena().point(t) lena().point(t)
def test_name(): def test_name():
# get profile information for file # get profile information for file
assert_equal(ImageCms.getProfileName(SRGB).strip(), assert_equal(ImageCms.getProfileName(SRGB).strip(),
'IEC 61966-2.1 Default RGB colour space - sRGB') 'IEC 61966-2.1 Default RGB colour space - sRGB')
def x_test_info(): def x_test_info():
assert_equal(ImageCms.getProfileInfo(SRGB).splitlines(), assert_equal(ImageCms.getProfileInfo(SRGB).splitlines(),
['sRGB IEC61966-2.1', '', ['sRGB IEC61966-2.1', '',
@ -54,11 +58,13 @@ def x_test_info():
'WhitePoint : D65 (daylight)', '', 'WhitePoint : D65 (daylight)', '',
'Tests/icc/sRGB.icm']) 'Tests/icc/sRGB.icm'])
def test_intent(): def test_intent():
assert_equal(ImageCms.getDefaultIntent(SRGB), 0) assert_equal(ImageCms.getDefaultIntent(SRGB), 0)
assert_equal(ImageCms.isIntentSupported( assert_equal(ImageCms.isIntentSupported(
SRGB, ImageCms.INTENT_ABSOLUTE_COLORIMETRIC, SRGB, ImageCms.INTENT_ABSOLUTE_COLORIMETRIC,
ImageCms.DIRECTION_INPUT), 1) ImageCms.DIRECTION_INPUT), 1)
def test_profile_object(): def test_profile_object():
# same, using profile object # same, using profile object
@ -69,8 +75,9 @@ def test_profile_object():
# ['sRGB built-in', '', 'WhitePoint : D65 (daylight)', '', '']) # ['sRGB built-in', '', 'WhitePoint : D65 (daylight)', '', ''])
assert_equal(ImageCms.getDefaultIntent(p), 0) assert_equal(ImageCms.getDefaultIntent(p), 0)
assert_equal(ImageCms.isIntentSupported( assert_equal(ImageCms.isIntentSupported(
p, ImageCms.INTENT_ABSOLUTE_COLORIMETRIC, p, ImageCms.INTENT_ABSOLUTE_COLORIMETRIC,
ImageCms.DIRECTION_INPUT), 1) ImageCms.DIRECTION_INPUT), 1)
def test_extensions(): def test_extensions():
# extensions # extensions
@ -79,12 +86,21 @@ def test_extensions():
assert_equal(ImageCms.getProfileName(p).strip(), assert_equal(ImageCms.getProfileName(p).strip(),
'IEC 61966-2.1 Default RGB colour space - sRGB') 'IEC 61966-2.1 Default RGB colour space - sRGB')
def test_exceptions(): def test_exceptions():
# the procedural pyCMS API uses PyCMSError for all sorts of errors # the procedural pyCMS API uses PyCMSError for all sorts of errors
assert_exception(ImageCms.PyCMSError, lambda: ImageCms.profileToProfile(lena(), "foo", "bar")) assert_exception(
assert_exception(ImageCms.PyCMSError, lambda: ImageCms.buildTransform("foo", "bar", "RGB", "RGB")) ImageCms.PyCMSError,
assert_exception(ImageCms.PyCMSError, lambda: ImageCms.getProfileName(None)) lambda: ImageCms.profileToProfile(lena(), "foo", "bar"))
assert_exception(ImageCms.PyCMSError, lambda: ImageCms.isIntentSupported(SRGB, None, None)) 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(): def test_display_profile():
@ -93,61 +109,63 @@ def test_display_profile():
def test_lab_color_profile(): def test_lab_color_profile():
pLab = ImageCms.createProfile("LAB", 5000) ImageCms.createProfile("LAB", 5000)
pLab = ImageCms.createProfile("LAB", 6500) ImageCms.createProfile("LAB", 6500)
def test_simple_lab(): def test_simple_lab():
i = Image.new('RGB', (10,10), (128,128,128)) i = Image.new('RGB', (10, 10), (128, 128, 128))
pLab = ImageCms.createProfile("LAB") pLab = ImageCms.createProfile("LAB")
t = ImageCms.buildTransform(SRGB, pLab, "RGB", "LAB") t = ImageCms.buildTransform(SRGB, pLab, "RGB", "LAB")
i_lab = ImageCms.applyTransform(i, t) i_lab = ImageCms.applyTransform(i, t)
assert_equal(i_lab.mode, 'LAB') assert_equal(i_lab.mode, 'LAB')
k = i_lab.getpixel((0,0)) k = i_lab.getpixel((0, 0))
assert_equal(k, (137,128,128)) # not a linear luminance map. so L != 128 assert_equal(k, (137, 128, 128)) # not a linear luminance map. so L != 128
L = i_lab.getdata(0) L = i_lab.getdata(0)
a = i_lab.getdata(1) a = i_lab.getdata(1)
b = i_lab.getdata(2) b = i_lab.getdata(2)
assert_equal(list(L), [137]*100) assert_equal(list(L), [137] * 100)
assert_equal(list(a), [128]*100) assert_equal(list(a), [128] * 100)
assert_equal(list(b), [128]*100) assert_equal(list(b), [128] * 100)
def test_lab_color(): def test_lab_color():
pLab = ImageCms.createProfile("LAB") pLab = ImageCms.createProfile("LAB")
t = ImageCms.buildTransform(SRGB, pLab, "RGB", "LAB") t = ImageCms.buildTransform(SRGB, pLab, "RGB", "LAB")
# need to add a type mapping for some PIL type to TYPE_Lab_8 in findLCMSType, # Need to add a type mapping for some PIL type to TYPE_Lab_8 in
# and have that mapping work back to a PIL mode. (likely RGB) # findLCMSType, and have that mapping work back to a PIL mode (likely RGB).
i = ImageCms.applyTransform(lena(), t) i = ImageCms.applyTransform(lena(), t)
assert_image(i, "LAB", (128, 128)) assert_image(i, "LAB", (128, 128))
# i.save('temp.lab.tif') # visually verified vs PS. # i.save('temp.lab.tif') # visually verified vs PS.
target = Image.open('Tests/images/lena.Lab.tif') target = Image.open('Tests/images/lena.Lab.tif')
assert_image_similar(i, target, 30) assert_image_similar(i, target, 30)
def test_lab_srgb(): def test_lab_srgb():
pLab = ImageCms.createProfile("LAB") pLab = ImageCms.createProfile("LAB")
t = ImageCms.buildTransform(pLab, SRGB, "LAB", "RGB") t = ImageCms.buildTransform(pLab, SRGB, "LAB", "RGB")
img = Image.open('Tests/images/lena.Lab.tif') img = Image.open('Tests/images/lena.Lab.tif')
img_srgb = ImageCms.applyTransform(img, t) img_srgb = ImageCms.applyTransform(img, t)
# img_srgb.save('temp.srgb.tif') # visually verified vs ps. # img_srgb.save('temp.srgb.tif') # visually verified vs ps.
assert_image_similar(lena(), img_srgb, 30) assert_image_similar(lena(), img_srgb, 30)
def test_lab_roundtrip(): def test_lab_roundtrip():
# check to see if we're at least internally consistent. # check to see if we're at least internally consistent.
pLab = ImageCms.createProfile("LAB") pLab = ImageCms.createProfile("LAB")
t = ImageCms.buildTransform(SRGB, pLab, "RGB", "LAB") t = ImageCms.buildTransform(SRGB, pLab, "RGB", "LAB")
t2 = ImageCms.buildTransform(pLab, SRGB, "LAB", "RGB") t2 = ImageCms.buildTransform(pLab, SRGB, "LAB", "RGB")
@ -156,5 +174,3 @@ def test_lab_roundtrip():
out = ImageCms.applyTransform(i, t2) out = ImageCms.applyTransform(i, t2)
assert_image_similar(lena(), out, 2) assert_image_similar(lena(), out, 2)