pep8/pyflakes

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

View File

@ -9,6 +9,7 @@ except ImportError:
SRGB = "Tests/icc/sRGB.icm" SRGB = "Tests/icc/sRGB.icm"
def test_sanity(): def test_sanity():
# basic smoke test. # basic smoke test.
@ -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,12 +58,14 @@ 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
p = ImageCms.createProfile("sRGB") p = ImageCms.createProfile("sRGB")
@ -72,6 +78,7 @@ def test_profile_object():
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
i = Image.open("Tests/images/rgb.jpg") i = Image.open("Tests/images/rgb.jpg")
@ -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,37 +109,37 @@ 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))
@ -133,6 +149,7 @@ def test_lab_color():
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")
@ -145,6 +162,7 @@ def test_lab_srgb():
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")
@ -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)