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,17 +12,19 @@ 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)
|
||||
bytes = out.tell()
|
||||
out.seek(0)
|
||||
im = Image.open(out)
|
||||
im.bytes = bytes # for testing only
|
||||
im.bytes = bytes # for testing only
|
||||
return im
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
|
||||
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)
|
||||
|
@ -70,7 +75,8 @@ def test_dpi():
|
|||
assert_equal(test(72), (72, 72))
|
||||
assert_equal(test(300), (300, 300))
|
||||
assert_equal(test(100, 200), (100, 200))
|
||||
assert_equal(test(0), None) # square pixels
|
||||
assert_equal(test(0), None) # square pixels
|
||||
|
||||
|
||||
def test_icc():
|
||||
# Test ICC support
|
||||
|
@ -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):
|
||||
|
@ -96,16 +103,20 @@ def test_icc_big():
|
|||
# using a 4-byte test code should allow us to detect out of
|
||||
# order issues.
|
||||
icc_profile = (b"Test"*int(n/4+1))[:n]
|
||||
assert len(icc_profile) == n # sanity
|
||||
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(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
|
||||
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())
|
||||
|
@ -113,25 +124,29 @@ def test_optimize():
|
|||
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,16 +157,18 @@ 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())
|
||||
im2 = roundtrip(lena(), progressive=1)
|
||||
im3 = roundtrip(lena(), progression=1) # compatibility
|
||||
im3 = roundtrip(lena(), progression=1) # compatibility
|
||||
assert_image_equal(im1, im2)
|
||||
assert_image_equal(im1, im3)
|
||||
assert_false(im1.info.get("progressive"))
|
||||
|
@ -161,31 +178,34 @@ 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
|
||||
return layer[0][1:3] + layer[1][1:3] + layer[2][1:3]
|
||||
# experimental API
|
||||
im = roundtrip(lena(), subsampling=-1) # default
|
||||
im = roundtrip(lena(), subsampling=-1) # default
|
||||
assert_equal(getsampling(im), (2, 2, 1, 1, 1, 1))
|
||||
im = roundtrip(lena(), subsampling=0) # 4:4:4
|
||||
im = roundtrip(lena(), subsampling=0) # 4:4:4
|
||||
assert_equal(getsampling(im), (1, 1, 1, 1, 1, 1))
|
||||
im = roundtrip(lena(), subsampling=1) # 4:2:2
|
||||
im = roundtrip(lena(), subsampling=1) # 4:2:2
|
||||
assert_equal(getsampling(im), (2, 1, 1, 1, 1, 1))
|
||||
im = roundtrip(lena(), subsampling=2) # 4:1:1
|
||||
im = roundtrip(lena(), subsampling=2) # 4:1:1
|
||||
assert_equal(getsampling(im), (2, 2, 1, 1, 1, 1))
|
||||
im = roundtrip(lena(), subsampling=3) # default (undefined)
|
||||
im = roundtrip(lena(), subsampling=3) # default (undefined)
|
||||
assert_equal(getsampling(im), (2, 2, 1, 1, 1, 1))
|
||||
|
||||
im = roundtrip(lena(), subsampling="4:4:4")
|
||||
|
@ -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