mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-12 02:06:18 +03:00
flake8
This commit is contained in:
parent
1335006cd7
commit
42610c0ecd
|
@ -117,7 +117,8 @@ def Ghostscript(tile, size, fp, scale=1):
|
|||
"-q", # quiet mode
|
||||
"-g%dx%d" % size, # set output geometry (pixels)
|
||||
"-r%fx%f" % res, # set input DPI (dots per inch)
|
||||
"-dNOPAUSE -dSAFER", # don't pause between pages, safe mode
|
||||
"-dNOPAUSE -dSAFER", # don't pause between pages,
|
||||
# safe mode
|
||||
"-sDEVICE=ppmraw", # ppm driver
|
||||
"-sOutputFile=%s" % outfile, # output file
|
||||
"-c", "%d %d translate" % (-bbox[0], -bbox[1]),
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
import re
|
||||
from PIL._binary import o8
|
||||
|
||||
|
||||
##
|
||||
# File handler for GIMP's palette format.
|
||||
|
||||
|
@ -56,7 +57,6 @@ class GimpPaletteFile:
|
|||
|
||||
self.palette = b"".join(self.palette)
|
||||
|
||||
|
||||
def getpalette(self):
|
||||
|
||||
return self.palette, self.rawmode
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import sys
|
||||
sys.path.insert(0, ".")
|
||||
|
||||
import glob, os
|
||||
import glob
|
||||
import os
|
||||
import traceback
|
||||
|
||||
for file in glob.glob("PIL/*.py"):
|
||||
|
|
|
@ -60,7 +60,8 @@ class TestFileJpeg(PillowTestCase):
|
|||
self.assertGreater(y, 0.8)
|
||||
self.assertEqual(k, 0.0)
|
||||
# the opposite corner is black
|
||||
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))]
|
||||
self.assertGreater(k, 0.9)
|
||||
# roundtrip, and check again
|
||||
im = self.roundtrip(im)
|
||||
|
@ -69,7 +70,8 @@ class TestFileJpeg(PillowTestCase):
|
|||
self.assertGreater(m, 0.8)
|
||||
self.assertGreater(y, 0.8)
|
||||
self.assertEqual(k, 0.0)
|
||||
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))]
|
||||
self.assertGreater(k, 0.9)
|
||||
|
||||
def test_dpi(self):
|
||||
|
@ -150,7 +152,8 @@ class TestFileJpeg(PillowTestCase):
|
|||
if py3:
|
||||
a = bytes(random.randint(0, 255) for _ in range(256 * 256 * 3))
|
||||
else:
|
||||
a = b''.join(chr(random.randint(0, 255)) for _ in range(256 * 256 * 3))
|
||||
a = b''.join(chr(random.randint(0, 255)) for _ in
|
||||
range(256 * 256 * 3))
|
||||
im = Image.frombuffer("RGB", (256, 256), a, "raw", "RGB", 0, 1)
|
||||
# this requires more bytes than pixels in the image
|
||||
im.save(f, format="JPEG", progressive=True, quality=100)
|
||||
|
@ -235,11 +238,13 @@ class TestFileJpeg(PillowTestCase):
|
|||
qtables = im.quantization
|
||||
reloaded = self.roundtrip(im, qtables=qtables, subsampling=0)
|
||||
self.assertEqual(im.quantization, reloaded.quantization)
|
||||
self.assert_image_similar(im, self.roundtrip(im, qtables='web_low'), 30)
|
||||
self.assert_image_similar(im, self.roundtrip(im, qtables='web_high'), 30)
|
||||
self.assert_image_similar(im, self.roundtrip(im, qtables='web_low'),
|
||||
30)
|
||||
self.assert_image_similar(im, self.roundtrip(im, qtables='web_high'),
|
||||
30)
|
||||
self.assert_image_similar(im, self.roundtrip(im, qtables='keep'), 30)
|
||||
|
||||
#values from wizard.txt in jpeg9-a src package.
|
||||
# values from wizard.txt in jpeg9-a src package.
|
||||
standard_l_qtable = [int(s) for s in """
|
||||
16 11 10 16 24 40 51 61
|
||||
12 12 14 19 26 58 60 55
|
||||
|
@ -251,7 +256,7 @@ class TestFileJpeg(PillowTestCase):
|
|||
72 92 95 98 112 100 103 99
|
||||
""".split(None)]
|
||||
|
||||
standard_chrominance_qtable= [int(s) for s in """
|
||||
standard_chrominance_qtable = [int(s) for s in """
|
||||
17 18 24 47 99 99 99 99
|
||||
18 21 26 66 99 99 99 99
|
||||
24 26 56 99 99 99 99 99
|
||||
|
@ -262,23 +267,23 @@ class TestFileJpeg(PillowTestCase):
|
|||
99 99 99 99 99 99 99 99
|
||||
""".split(None)]
|
||||
# list of qtable lists
|
||||
self.assert_image_similar(im,
|
||||
self.roundtrip(im,
|
||||
qtables=[standard_l_qtable,
|
||||
standard_chrominance_qtable]),
|
||||
30)
|
||||
self.assert_image_similar(
|
||||
im, self.roundtrip(
|
||||
im, qtables=[standard_l_qtable, standard_chrominance_qtable]),
|
||||
30)
|
||||
|
||||
# tuple of qtable lists
|
||||
self.assert_image_similar(im,
|
||||
self.roundtrip(im,
|
||||
qtables=(standard_l_qtable,
|
||||
standard_chrominance_qtable)),
|
||||
30)
|
||||
self.assert_image_similar(
|
||||
im, self.roundtrip(
|
||||
im, qtables=(standard_l_qtable, standard_chrominance_qtable)),
|
||||
30)
|
||||
|
||||
# dict of qtable lists
|
||||
self.assert_image_similar(im,
|
||||
self.roundtrip(im,
|
||||
qtables={0:standard_l_qtable,
|
||||
1:standard_chrominance_qtable}),
|
||||
30)
|
||||
self.assert_image_similar(
|
||||
im, self.roundtrip(
|
||||
im, qtables={
|
||||
0: standard_l_qtable, 1: standard_chrominance_qtable}),
|
||||
30)
|
||||
|
||||
@unittest.skipUnless(djpeg_available(), "djpeg not available")
|
||||
def test_load_djpeg(self):
|
||||
|
|
|
@ -15,8 +15,8 @@ class TestFileXpm(PillowTestCase):
|
|||
self.assertEqual(im.size, (128, 128))
|
||||
self.assertEqual(im.format, "XPM")
|
||||
|
||||
#large error due to quantization->44 colors.
|
||||
self.assert_image_similar(im.convert('RGB'), lena('RGB'), 60)
|
||||
# large error due to quantization->44 colors.
|
||||
self.assert_image_similar(im.convert('RGB'), lena('RGB'), 60)
|
||||
|
||||
def test_load_read(self):
|
||||
# Arrange
|
||||
|
|
|
@ -255,7 +255,6 @@ class TestImageDraw(PillowTestCase):
|
|||
self.assert_image_equal(
|
||||
im, Image.open("Tests/images/imagedraw_floodfill2.png"))
|
||||
|
||||
|
||||
def create_base_image_draw(self, size,
|
||||
mode=DEFAULT_MODE,
|
||||
background1=WHITE,
|
||||
|
@ -267,23 +266,25 @@ class TestImageDraw(PillowTestCase):
|
|||
img.putpixel((x, y), background2)
|
||||
return (img, ImageDraw.Draw(img))
|
||||
|
||||
|
||||
def test_square(self):
|
||||
expected = Image.open(os.path.join(IMAGES_PATH, 'square.png'))
|
||||
expected.load()
|
||||
img, draw = self.create_base_image_draw((10, 10))
|
||||
draw.polygon([(2, 2), (2, 7), (7, 7), (7, 2)], BLACK)
|
||||
self.assert_image_equal(img, expected, 'square as normal polygon failed')
|
||||
self.assert_image_equal(img, expected,
|
||||
'square as normal polygon failed')
|
||||
img, draw = self.create_base_image_draw((10, 10))
|
||||
draw.polygon([(7, 7), (7, 2), (2, 2), (2, 7)], BLACK)
|
||||
self.assert_image_equal(img, expected, 'square as inverted polygon failed')
|
||||
self.assert_image_equal(img, expected,
|
||||
'square as inverted polygon failed')
|
||||
img, draw = self.create_base_image_draw((10, 10))
|
||||
draw.rectangle((2, 2, 7, 7), BLACK)
|
||||
self.assert_image_equal(img, expected, 'square as normal rectangle failed')
|
||||
self.assert_image_equal(img, expected,
|
||||
'square as normal rectangle failed')
|
||||
img, draw = self.create_base_image_draw((10, 10))
|
||||
draw.rectangle((7, 7, 2, 2), BLACK)
|
||||
self.assert_image_equal(img, expected, 'square as inverted rectangle failed')
|
||||
|
||||
self.assert_image_equal(
|
||||
img, expected, 'square as inverted rectangle failed')
|
||||
|
||||
def test_triangle_right(self):
|
||||
expected = Image.open(os.path.join(IMAGES_PATH, 'triangle_right.png'))
|
||||
|
@ -292,61 +293,78 @@ class TestImageDraw(PillowTestCase):
|
|||
draw.polygon([(3, 5), (17, 5), (10, 12)], BLACK)
|
||||
self.assert_image_equal(img, expected, 'triangle right failed')
|
||||
|
||||
|
||||
def test_line_horizontal(self):
|
||||
expected = Image.open(os.path.join(IMAGES_PATH, 'line_horizontal_w2px_normal.png'))
|
||||
expected = Image.open(os.path.join(IMAGES_PATH,
|
||||
'line_horizontal_w2px_normal.png'))
|
||||
expected.load()
|
||||
img, draw = self.create_base_image_draw((20, 20))
|
||||
draw.line((5, 5, 14, 5), BLACK, 2)
|
||||
self.assert_image_equal(img, expected, 'line straigth horizontal normal 2px wide failed')
|
||||
expected = Image.open(os.path.join(IMAGES_PATH, 'line_horizontal_w2px_inverted.png'))
|
||||
self.assert_image_equal(
|
||||
img, expected, 'line straigth horizontal normal 2px wide failed')
|
||||
expected = Image.open(os.path.join(IMAGES_PATH,
|
||||
'line_horizontal_w2px_inverted.png'))
|
||||
expected.load()
|
||||
img, draw = self.create_base_image_draw((20, 20))
|
||||
draw.line((14, 5, 5, 5), BLACK, 2)
|
||||
self.assert_image_equal(img, expected, 'line straigth horizontal inverted 2px wide failed')
|
||||
expected = Image.open(os.path.join(IMAGES_PATH, 'line_horizontal_w3px.png'))
|
||||
self.assert_image_equal(
|
||||
img, expected, 'line straigth horizontal inverted 2px wide failed')
|
||||
expected = Image.open(os.path.join(IMAGES_PATH,
|
||||
'line_horizontal_w3px.png'))
|
||||
expected.load()
|
||||
img, draw = self.create_base_image_draw((20, 20))
|
||||
draw.line((5, 5, 14, 5), BLACK, 3)
|
||||
self.assert_image_equal(img, expected, 'line straigth horizontal normal 3px wide failed')
|
||||
self.assert_image_equal(
|
||||
img, expected, 'line straigth horizontal normal 3px wide failed')
|
||||
img, draw = self.create_base_image_draw((20, 20))
|
||||
draw.line((14, 5, 5, 5), BLACK, 3)
|
||||
self.assert_image_equal(img, expected, 'line straigth horizontal inverted 3px wide failed')
|
||||
expected = Image.open(os.path.join(IMAGES_PATH, 'line_horizontal_w101px.png'))
|
||||
self.assert_image_equal(
|
||||
img, expected, 'line straigth horizontal inverted 3px wide failed')
|
||||
expected = Image.open(os.path.join(IMAGES_PATH,
|
||||
'line_horizontal_w101px.png'))
|
||||
expected.load()
|
||||
img, draw = self.create_base_image_draw((200, 110))
|
||||
draw.line((5, 55, 195, 55), BLACK, 101)
|
||||
self.assert_image_equal(img, expected, 'line straigth horizontal 101px wide failed')
|
||||
self.assert_image_equal(
|
||||
img, expected, 'line straigth horizontal 101px wide failed')
|
||||
|
||||
def test_line_h_s1_w2(self):
|
||||
self.skipTest('failing')
|
||||
expected = Image.open(os.path.join(IMAGES_PATH, 'line_horizontal_slope1px_w2px.png'))
|
||||
expected = Image.open(os.path.join(IMAGES_PATH,
|
||||
'line_horizontal_slope1px_w2px.png'))
|
||||
expected.load()
|
||||
img, draw = self.create_base_image_draw((20, 20))
|
||||
draw.line((5, 5, 14, 6), BLACK, 2)
|
||||
self.assert_image_equal(img, expected, 'line horizontal 1px slope 2px wide failed')
|
||||
|
||||
self.assert_image_equal(
|
||||
img, expected, 'line horizontal 1px slope 2px wide failed')
|
||||
|
||||
def test_line_vertical(self):
|
||||
expected = Image.open(os.path.join(IMAGES_PATH, 'line_vertical_w2px_normal.png'))
|
||||
expected = Image.open(os.path.join(IMAGES_PATH,
|
||||
'line_vertical_w2px_normal.png'))
|
||||
expected.load()
|
||||
img, draw = self.create_base_image_draw((20, 20))
|
||||
draw.line((5, 5, 5, 14), BLACK, 2)
|
||||
self.assert_image_equal(img, expected, 'line straigth vertical normal 2px wide failed')
|
||||
expected = Image.open(os.path.join(IMAGES_PATH, 'line_vertical_w2px_inverted.png'))
|
||||
self.assert_image_equal(
|
||||
img, expected, 'line straigth vertical normal 2px wide failed')
|
||||
expected = Image.open(os.path.join(IMAGES_PATH,
|
||||
'line_vertical_w2px_inverted.png'))
|
||||
expected.load()
|
||||
img, draw = self.create_base_image_draw((20, 20))
|
||||
draw.line((5, 14, 5, 5), BLACK, 2)
|
||||
self.assert_image_equal(img, expected, 'line straigth vertical inverted 2px wide failed')
|
||||
expected = Image.open(os.path.join(IMAGES_PATH, 'line_vertical_w3px.png'))
|
||||
self.assert_image_equal(
|
||||
img, expected, 'line straigth vertical inverted 2px wide failed')
|
||||
expected = Image.open(os.path.join(IMAGES_PATH,
|
||||
'line_vertical_w3px.png'))
|
||||
expected.load()
|
||||
img, draw = self.create_base_image_draw((20, 20))
|
||||
draw.line((5, 5, 5, 14), BLACK, 3)
|
||||
self.assert_image_equal(img, expected, 'line straigth vertical normal 3px wide failed')
|
||||
self.assert_image_equal(
|
||||
img, expected, 'line straigth vertical normal 3px wide failed')
|
||||
img, draw = self.create_base_image_draw((20, 20))
|
||||
draw.line((5, 14, 5, 5), BLACK, 3)
|
||||
self.assert_image_equal(img, expected, 'line straigth vertical inverted 3px wide failed')
|
||||
expected = Image.open(os.path.join(IMAGES_PATH, 'line_vertical_w101px.png'))
|
||||
self.assert_image_equal(
|
||||
img, expected, 'line straigth vertical inverted 3px wide failed')
|
||||
expected = Image.open(os.path.join(IMAGES_PATH,
|
||||
'line_vertical_w101px.png'))
|
||||
expected.load()
|
||||
img, draw = self.create_base_image_draw((110, 200))
|
||||
draw.line((55, 5, 55, 195), BLACK, 101)
|
||||
|
@ -360,14 +378,14 @@ class TestImageDraw(PillowTestCase):
|
|||
self.assert_image_equal(img, expected,
|
||||
'line vertical 1px slope 2px wide failed')
|
||||
|
||||
|
||||
def test_line_oblique_45(self):
|
||||
expected = Image.open(os.path.join(IMAGES_PATH, 'line_oblique_45_w3px_a.png'))
|
||||
expected = Image.open(os.path.join(IMAGES_PATH,
|
||||
'line_oblique_45_w3px_a.png'))
|
||||
expected.load()
|
||||
img, draw = self.create_base_image_draw((20, 20))
|
||||
draw.line((5, 5, 14, 14), BLACK, 3)
|
||||
self.assert_image_equal(img, expected,
|
||||
'line oblique 45 normal 3px wide A failed')
|
||||
'line oblique 45 normal 3px wide A failed')
|
||||
img, draw = self.create_base_image_draw((20, 20))
|
||||
draw.line((14, 14, 5, 5), BLACK, 3)
|
||||
self.assert_image_equal(img, expected,
|
||||
|
|
Loading…
Reference in New Issue
Block a user