mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-11-04 09:57:43 +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"
 | 
					test_file = "Images/lena.jpg"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def roundtrip(im, **options):
 | 
					def roundtrip(im, **options):
 | 
				
			||||||
    out = BytesIO()
 | 
					    out = BytesIO()
 | 
				
			||||||
    im.save(out, "JPEG", **options)
 | 
					    im.save(out, "JPEG", **options)
 | 
				
			||||||
    bytes = out.tell()
 | 
					    bytes = out.tell()
 | 
				
			||||||
    out.seek(0)
 | 
					    out.seek(0)
 | 
				
			||||||
    im = Image.open(out)
 | 
					    im = Image.open(out)
 | 
				
			||||||
    im.bytes = bytes # for testing only
 | 
					    im.bytes = bytes  # for testing only
 | 
				
			||||||
    return im
 | 
					    return im
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# --------------------------------------------------------------------
 | 
					# --------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_sanity():
 | 
					def test_sanity():
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # internal version number
 | 
					    # internal version number
 | 
				
			||||||
| 
						 | 
					@ -34,6 +36,7 @@ def test_sanity():
 | 
				
			||||||
    assert_equal(im.size, (128, 128))
 | 
					    assert_equal(im.size, (128, 128))
 | 
				
			||||||
    assert_equal(im.format, "JPEG")
 | 
					    assert_equal(im.format, "JPEG")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# --------------------------------------------------------------------
 | 
					# --------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_app():
 | 
					def test_app():
 | 
				
			||||||
| 
						 | 
					@ -44,6 +47,7 @@ def test_app():
 | 
				
			||||||
    assert_equal(im.applist[1], ("COM", b"Python Imaging Library"))
 | 
					    assert_equal(im.applist[1], ("COM", b"Python Imaging Library"))
 | 
				
			||||||
    assert_equal(len(im.applist), 2)
 | 
					    assert_equal(len(im.applist), 2)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_cmyk():
 | 
					def test_cmyk():
 | 
				
			||||||
    # Test CMYK handling.  Thanks to Tim and Charlie for test data,
 | 
					    # Test CMYK handling.  Thanks to Tim and Charlie for test data,
 | 
				
			||||||
    # Michael for getting me to look one more time.
 | 
					    # 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))]
 | 
					    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)
 | 
					    assert_true(k > 0.9)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_dpi():
 | 
					def test_dpi():
 | 
				
			||||||
    def test(xdpi, ydpi=None):
 | 
					    def test(xdpi, ydpi=None):
 | 
				
			||||||
        im = Image.open(test_file)
 | 
					        im = Image.open(test_file)
 | 
				
			||||||
| 
						 | 
					@ -70,7 +75,8 @@ def test_dpi():
 | 
				
			||||||
    assert_equal(test(72), (72, 72))
 | 
					    assert_equal(test(72), (72, 72))
 | 
				
			||||||
    assert_equal(test(300), (300, 300))
 | 
					    assert_equal(test(300), (300, 300))
 | 
				
			||||||
    assert_equal(test(100, 200), (100, 200))
 | 
					    assert_equal(test(100, 200), (100, 200))
 | 
				
			||||||
    assert_equal(test(0), None) # square pixels
 | 
					    assert_equal(test(0), None)  # square pixels
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_icc():
 | 
					def test_icc():
 | 
				
			||||||
    # Test ICC support
 | 
					    # Test ICC support
 | 
				
			||||||
| 
						 | 
					@ -89,6 +95,7 @@ def test_icc():
 | 
				
			||||||
    assert_false(im1.info.get("icc_profile"))
 | 
					    assert_false(im1.info.get("icc_profile"))
 | 
				
			||||||
    assert_true(im2.info.get("icc_profile"))
 | 
					    assert_true(im2.info.get("icc_profile"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_icc_big():
 | 
					def test_icc_big():
 | 
				
			||||||
    # Make sure that the "extra" support handles large blocks
 | 
					    # Make sure that the "extra" support handles large blocks
 | 
				
			||||||
    def test(n):
 | 
					    def test(n):
 | 
				
			||||||
| 
						 | 
					@ -96,16 +103,20 @@ def test_icc_big():
 | 
				
			||||||
        # using a 4-byte test code should allow us to detect out of
 | 
					        # using a 4-byte test code should allow us to detect out of
 | 
				
			||||||
        # order issues.
 | 
					        # order issues.
 | 
				
			||||||
        icc_profile = (b"Test"*int(n/4+1))[:n]
 | 
					        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)
 | 
					        im1 = roundtrip(lena(), icc_profile=icc_profile)
 | 
				
			||||||
        assert_equal(im1.info.get("icc_profile"), icc_profile or None)
 | 
					        assert_equal(im1.info.get("icc_profile"), icc_profile or None)
 | 
				
			||||||
    test(0); test(1)
 | 
					    test(0)
 | 
				
			||||||
    test(3); test(4); test(5)
 | 
					    test(1)
 | 
				
			||||||
    test(65533-14) # full JPEG marker block
 | 
					    test(3)
 | 
				
			||||||
    test(65533-14+1) # full block plus one byte
 | 
					    test(4)
 | 
				
			||||||
    test(ImageFile.MAXBLOCK) # full buffer block
 | 
					    test(5)
 | 
				
			||||||
    test(ImageFile.MAXBLOCK+1) # full buffer block plus one byte
 | 
					    test(65533-14)  # full JPEG marker block
 | 
				
			||||||
    test(ImageFile.MAXBLOCK*4+3) # large 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():
 | 
					def test_optimize():
 | 
				
			||||||
    im1 = roundtrip(lena())
 | 
					    im1 = roundtrip(lena())
 | 
				
			||||||
| 
						 | 
					@ -113,25 +124,29 @@ def test_optimize():
 | 
				
			||||||
    assert_image_equal(im1, im2)
 | 
					    assert_image_equal(im1, im2)
 | 
				
			||||||
    assert_true(im1.bytes >= im2.bytes)
 | 
					    assert_true(im1.bytes >= im2.bytes)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_optimize_large_buffer():
 | 
					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')
 | 
					    f = tempfile('temp.jpg')
 | 
				
			||||||
    # this requires ~ 1.5x Image.MAXBLOCK
 | 
					    # 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)
 | 
					    im.save(f, format="JPEG", optimize=True)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_progressive():
 | 
					def test_progressive():
 | 
				
			||||||
    im1 = roundtrip(lena())
 | 
					    im1 = roundtrip(lena())
 | 
				
			||||||
    im2 = roundtrip(lena(), progressive=True)
 | 
					    im2 = roundtrip(lena(), progressive=True)
 | 
				
			||||||
    assert_image_equal(im1, im2)
 | 
					    assert_image_equal(im1, im2)
 | 
				
			||||||
    assert_true(im1.bytes >= im2.bytes)
 | 
					    assert_true(im1.bytes >= im2.bytes)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_progressive_large_buffer():
 | 
					def test_progressive_large_buffer():
 | 
				
			||||||
    f = tempfile('temp.jpg')
 | 
					    f = tempfile('temp.jpg')
 | 
				
			||||||
    # this requires ~ 1.5x Image.MAXBLOCK
 | 
					    # 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)
 | 
					    im.save(f, format="JPEG", progressive=True)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_progressive_large_buffer_highest_quality():
 | 
					def test_progressive_large_buffer_highest_quality():
 | 
				
			||||||
    f = tempfile('temp.jpg')
 | 
					    f = tempfile('temp.jpg')
 | 
				
			||||||
    if py3:
 | 
					    if py3:
 | 
				
			||||||
| 
						 | 
					@ -142,16 +157,18 @@ def test_progressive_large_buffer_highest_quality():
 | 
				
			||||||
    # this requires more bytes than pixels in the image
 | 
					    # this requires more bytes than pixels in the image
 | 
				
			||||||
    im.save(f, format="JPEG", progressive=True, quality=100)
 | 
					    im.save(f, format="JPEG", progressive=True, quality=100)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_large_exif():
 | 
					def test_large_exif():
 | 
				
			||||||
    #https://github.com/python-imaging/Pillow/issues/148
 | 
					    # https://github.com/python-imaging/Pillow/issues/148
 | 
				
			||||||
    f = tempfile('temp.jpg')
 | 
					    f = tempfile('temp.jpg')
 | 
				
			||||||
    im = lena()
 | 
					    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():
 | 
					def test_progressive_compat():
 | 
				
			||||||
    im1 = roundtrip(lena())
 | 
					    im1 = roundtrip(lena())
 | 
				
			||||||
    im2 = roundtrip(lena(), progressive=1)
 | 
					    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, im2)
 | 
				
			||||||
    assert_image_equal(im1, im3)
 | 
					    assert_image_equal(im1, im3)
 | 
				
			||||||
    assert_false(im1.info.get("progressive"))
 | 
					    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("progressive"))
 | 
				
			||||||
    assert_true(im3.info.get("progression"))
 | 
					    assert_true(im3.info.get("progression"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_quality():
 | 
					def test_quality():
 | 
				
			||||||
    im1 = roundtrip(lena())
 | 
					    im1 = roundtrip(lena())
 | 
				
			||||||
    im2 = roundtrip(lena(), quality=50)
 | 
					    im2 = roundtrip(lena(), quality=50)
 | 
				
			||||||
    assert_image(im1, im2.mode, im2.size)
 | 
					    assert_image(im1, im2.mode, im2.size)
 | 
				
			||||||
    assert_true(im1.bytes >= im2.bytes)
 | 
					    assert_true(im1.bytes >= im2.bytes)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_smooth():
 | 
					def test_smooth():
 | 
				
			||||||
    im1 = roundtrip(lena())
 | 
					    im1 = roundtrip(lena())
 | 
				
			||||||
    im2 = roundtrip(lena(), smooth=100)
 | 
					    im2 = roundtrip(lena(), smooth=100)
 | 
				
			||||||
    assert_image(im1, im2.mode, im2.size)
 | 
					    assert_image(im1, im2.mode, im2.size)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_subsampling():
 | 
					def test_subsampling():
 | 
				
			||||||
    def getsampling(im):
 | 
					    def getsampling(im):
 | 
				
			||||||
        layer = im.layer
 | 
					        layer = im.layer
 | 
				
			||||||
        return layer[0][1:3] + layer[1][1:3] + layer[2][1:3]
 | 
					        return layer[0][1:3] + layer[1][1:3] + layer[2][1:3]
 | 
				
			||||||
    # experimental API
 | 
					    # experimental API
 | 
				
			||||||
    im = roundtrip(lena(), subsampling=-1) # default
 | 
					    im = roundtrip(lena(), subsampling=-1)  # default
 | 
				
			||||||
    assert_equal(getsampling(im), (2, 2, 1, 1, 1, 1))
 | 
					    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))
 | 
					    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))
 | 
					    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))
 | 
					    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))
 | 
					    assert_equal(getsampling(im), (2, 2, 1, 1, 1, 1))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    im = roundtrip(lena(), subsampling="4:4:4")
 | 
					    im = roundtrip(lena(), subsampling="4:4:4")
 | 
				
			||||||
| 
						 | 
					@ -197,6 +217,7 @@ def test_subsampling():
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    assert_exception(TypeError, lambda: roundtrip(lena(), subsampling="1:1:1"))
 | 
					    assert_exception(TypeError, lambda: roundtrip(lena(), subsampling="1:1:1"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_exif():
 | 
					def test_exif():
 | 
				
			||||||
    im = Image.open("Tests/images/pil_sample_rgb.jpg")
 | 
					    im = Image.open("Tests/images/pil_sample_rgb.jpg")
 | 
				
			||||||
    info = im._getexif()
 | 
					    info = im._getexif()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user