mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 09:26:16 +03:00
pep8/pyflakes
This commit is contained in:
parent
9c048e44d1
commit
aed2646dc2
|
@ -12,6 +12,7 @@ if "jpeg_encoder" not in codecs or "jpeg_decoder" not in codecs:
|
|||
|
||||
test_file = "Images/lena.jpg"
|
||||
|
||||
|
||||
def roundtrip(im, **options):
|
||||
out = BytesIO()
|
||||
im.save(out, "JPEG", **options)
|
||||
|
@ -23,6 +24,7 @@ def roundtrip(im, **options):
|
|||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_sanity():
|
||||
|
||||
# internal version number
|
||||
|
@ -34,6 +36,7 @@ def test_sanity():
|
|||
assert_equal(im.size, (128, 128))
|
||||
assert_equal(im.format, "JPEG")
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def test_app():
|
||||
|
@ -44,6 +47,7 @@ def test_app():
|
|||
assert_equal(im.applist[1], ("COM", b"Python Imaging Library"))
|
||||
assert_equal(len(im.applist), 2)
|
||||
|
||||
|
||||
def test_cmyk():
|
||||
# Test CMYK handling. Thanks to Tim and Charlie for test data,
|
||||
# Michael for getting me to look one more time.
|
||||
|
@ -62,6 +66,7 @@ def test_cmyk():
|
|||
c, m, y, k = [x / 255.0 for x in im.getpixel((im.size[0]-1, im.size[1]-1))]
|
||||
assert_true(k > 0.9)
|
||||
|
||||
|
||||
def test_dpi():
|
||||
def test(xdpi, ydpi=None):
|
||||
im = Image.open(test_file)
|
||||
|
@ -72,6 +77,7 @@ def test_dpi():
|
|||
assert_equal(test(100, 200), (100, 200))
|
||||
assert_equal(test(0), None) # square pixels
|
||||
|
||||
|
||||
def test_icc():
|
||||
# Test ICC support
|
||||
im1 = Image.open("Tests/images/rgb.jpg")
|
||||
|
@ -89,6 +95,7 @@ def test_icc():
|
|||
assert_false(im1.info.get("icc_profile"))
|
||||
assert_true(im2.info.get("icc_profile"))
|
||||
|
||||
|
||||
def test_icc_big():
|
||||
# Make sure that the "extra" support handles large blocks
|
||||
def test(n):
|
||||
|
@ -99,39 +106,47 @@ def test_icc_big():
|
|||
assert len(icc_profile) == n # sanity
|
||||
im1 = roundtrip(lena(), icc_profile=icc_profile)
|
||||
assert_equal(im1.info.get("icc_profile"), icc_profile or None)
|
||||
test(0); test(1)
|
||||
test(3); test(4); test(5)
|
||||
test(0)
|
||||
test(1)
|
||||
test(3)
|
||||
test(4)
|
||||
test(5)
|
||||
test(65533-14) # full JPEG marker block
|
||||
test(65533-14+1) # full block plus one byte
|
||||
test(ImageFile.MAXBLOCK) # full buffer block
|
||||
test(ImageFile.MAXBLOCK+1) # full buffer block plus one byte
|
||||
test(ImageFile.MAXBLOCK*4+3) # large block
|
||||
|
||||
|
||||
def test_optimize():
|
||||
im1 = roundtrip(lena())
|
||||
im2 = roundtrip(lena(), optimize=1)
|
||||
assert_image_equal(im1, im2)
|
||||
assert_true(im1.bytes >= im2.bytes)
|
||||
|
||||
|
||||
def test_optimize_large_buffer():
|
||||
#https://github.com/python-imaging/Pillow/issues/148
|
||||
# https://github.com/python-imaging/Pillow/issues/148
|
||||
f = tempfile('temp.jpg')
|
||||
# this requires ~ 1.5x Image.MAXBLOCK
|
||||
im = Image.new("RGB", (4096,4096), 0xff3333)
|
||||
im = Image.new("RGB", (4096, 4096), 0xff3333)
|
||||
im.save(f, format="JPEG", optimize=True)
|
||||
|
||||
|
||||
def test_progressive():
|
||||
im1 = roundtrip(lena())
|
||||
im2 = roundtrip(lena(), progressive=True)
|
||||
assert_image_equal(im1, im2)
|
||||
assert_true(im1.bytes >= im2.bytes)
|
||||
|
||||
|
||||
def test_progressive_large_buffer():
|
||||
f = tempfile('temp.jpg')
|
||||
# this requires ~ 1.5x Image.MAXBLOCK
|
||||
im = Image.new("RGB", (4096,4096), 0xff3333)
|
||||
im = Image.new("RGB", (4096, 4096), 0xff3333)
|
||||
im.save(f, format="JPEG", progressive=True)
|
||||
|
||||
|
||||
def test_progressive_large_buffer_highest_quality():
|
||||
f = tempfile('temp.jpg')
|
||||
if py3:
|
||||
|
@ -142,11 +157,13 @@ def test_progressive_large_buffer_highest_quality():
|
|||
# this requires more bytes than pixels in the image
|
||||
im.save(f, format="JPEG", progressive=True, quality=100)
|
||||
|
||||
|
||||
def test_large_exif():
|
||||
#https://github.com/python-imaging/Pillow/issues/148
|
||||
# https://github.com/python-imaging/Pillow/issues/148
|
||||
f = tempfile('temp.jpg')
|
||||
im = lena()
|
||||
im.save(f,'JPEG', quality=90, exif=b"1"*65532)
|
||||
im.save(f, 'JPEG', quality=90, exif=b"1"*65532)
|
||||
|
||||
|
||||
def test_progressive_compat():
|
||||
im1 = roundtrip(lena())
|
||||
|
@ -161,17 +178,20 @@ def test_progressive_compat():
|
|||
assert_true(im3.info.get("progressive"))
|
||||
assert_true(im3.info.get("progression"))
|
||||
|
||||
|
||||
def test_quality():
|
||||
im1 = roundtrip(lena())
|
||||
im2 = roundtrip(lena(), quality=50)
|
||||
assert_image(im1, im2.mode, im2.size)
|
||||
assert_true(im1.bytes >= im2.bytes)
|
||||
|
||||
|
||||
def test_smooth():
|
||||
im1 = roundtrip(lena())
|
||||
im2 = roundtrip(lena(), smooth=100)
|
||||
assert_image(im1, im2.mode, im2.size)
|
||||
|
||||
|
||||
def test_subsampling():
|
||||
def getsampling(im):
|
||||
layer = im.layer
|
||||
|
@ -197,6 +217,7 @@ def test_subsampling():
|
|||
|
||||
assert_exception(TypeError, lambda: roundtrip(lena(), subsampling="1:1:1"))
|
||||
|
||||
|
||||
def test_exif():
|
||||
im = Image.open("Tests/images/pil_sample_rgb.jpg")
|
||||
info = im._getexif()
|
||||
|
|
Loading…
Reference in New Issue
Block a user