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
|
"-q", # quiet mode
|
||||||
"-g%dx%d" % size, # set output geometry (pixels)
|
"-g%dx%d" % size, # set output geometry (pixels)
|
||||||
"-r%fx%f" % res, # set input DPI (dots per inch)
|
"-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
|
"-sDEVICE=ppmraw", # ppm driver
|
||||||
"-sOutputFile=%s" % outfile, # output file
|
"-sOutputFile=%s" % outfile, # output file
|
||||||
"-c", "%d %d translate" % (-bbox[0], -bbox[1]),
|
"-c", "%d %d translate" % (-bbox[0], -bbox[1]),
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
import re
|
import re
|
||||||
from PIL._binary import o8
|
from PIL._binary import o8
|
||||||
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# File handler for GIMP's palette format.
|
# File handler for GIMP's palette format.
|
||||||
|
|
||||||
|
@ -56,7 +57,6 @@ class GimpPaletteFile:
|
||||||
|
|
||||||
self.palette = b"".join(self.palette)
|
self.palette = b"".join(self.palette)
|
||||||
|
|
||||||
|
|
||||||
def getpalette(self):
|
def getpalette(self):
|
||||||
|
|
||||||
return self.palette, self.rawmode
|
return self.palette, self.rawmode
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
import sys
|
import sys
|
||||||
sys.path.insert(0, ".")
|
sys.path.insert(0, ".")
|
||||||
|
|
||||||
import glob, os
|
import glob
|
||||||
|
import os
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
for file in glob.glob("PIL/*.py"):
|
for file in glob.glob("PIL/*.py"):
|
||||||
|
|
|
@ -60,7 +60,8 @@ class TestFileJpeg(PillowTestCase):
|
||||||
self.assertGreater(y, 0.8)
|
self.assertGreater(y, 0.8)
|
||||||
self.assertEqual(k, 0.0)
|
self.assertEqual(k, 0.0)
|
||||||
# the opposite corner is black
|
# 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)
|
self.assertGreater(k, 0.9)
|
||||||
# roundtrip, and check again
|
# roundtrip, and check again
|
||||||
im = self.roundtrip(im)
|
im = self.roundtrip(im)
|
||||||
|
@ -69,7 +70,8 @@ class TestFileJpeg(PillowTestCase):
|
||||||
self.assertGreater(m, 0.8)
|
self.assertGreater(m, 0.8)
|
||||||
self.assertGreater(y, 0.8)
|
self.assertGreater(y, 0.8)
|
||||||
self.assertEqual(k, 0.0)
|
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)
|
self.assertGreater(k, 0.9)
|
||||||
|
|
||||||
def test_dpi(self):
|
def test_dpi(self):
|
||||||
|
@ -150,7 +152,8 @@ class TestFileJpeg(PillowTestCase):
|
||||||
if py3:
|
if py3:
|
||||||
a = bytes(random.randint(0, 255) for _ in range(256 * 256 * 3))
|
a = bytes(random.randint(0, 255) for _ in range(256 * 256 * 3))
|
||||||
else:
|
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)
|
im = Image.frombuffer("RGB", (256, 256), a, "raw", "RGB", 0, 1)
|
||||||
# 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)
|
||||||
|
@ -235,8 +238,10 @@ class TestFileJpeg(PillowTestCase):
|
||||||
qtables = im.quantization
|
qtables = im.quantization
|
||||||
reloaded = self.roundtrip(im, qtables=qtables, subsampling=0)
|
reloaded = self.roundtrip(im, qtables=qtables, subsampling=0)
|
||||||
self.assertEqual(im.quantization, reloaded.quantization)
|
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_low'),
|
||||||
self.assert_image_similar(im, self.roundtrip(im, qtables='web_high'), 30)
|
30)
|
||||||
|
self.assert_image_similar(im, self.roundtrip(im, qtables='web_high'),
|
||||||
|
30)
|
||||||
self.assert_image_similar(im, self.roundtrip(im, qtables='keep'), 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.
|
||||||
|
@ -262,22 +267,22 @@ class TestFileJpeg(PillowTestCase):
|
||||||
99 99 99 99 99 99 99 99
|
99 99 99 99 99 99 99 99
|
||||||
""".split(None)]
|
""".split(None)]
|
||||||
# list of qtable lists
|
# list of qtable lists
|
||||||
self.assert_image_similar(im,
|
self.assert_image_similar(
|
||||||
self.roundtrip(im,
|
im, self.roundtrip(
|
||||||
qtables=[standard_l_qtable,
|
im, qtables=[standard_l_qtable, standard_chrominance_qtable]),
|
||||||
standard_chrominance_qtable]),
|
|
||||||
30)
|
30)
|
||||||
|
|
||||||
# tuple of qtable lists
|
# tuple of qtable lists
|
||||||
self.assert_image_similar(im,
|
self.assert_image_similar(
|
||||||
self.roundtrip(im,
|
im, self.roundtrip(
|
||||||
qtables=(standard_l_qtable,
|
im, qtables=(standard_l_qtable, standard_chrominance_qtable)),
|
||||||
standard_chrominance_qtable)),
|
|
||||||
30)
|
30)
|
||||||
|
|
||||||
# dict of qtable lists
|
# dict of qtable lists
|
||||||
self.assert_image_similar(im,
|
self.assert_image_similar(
|
||||||
self.roundtrip(im,
|
im, self.roundtrip(
|
||||||
qtables={0:standard_l_qtable,
|
im, qtables={
|
||||||
1:standard_chrominance_qtable}),
|
0: standard_l_qtable, 1: standard_chrominance_qtable}),
|
||||||
30)
|
30)
|
||||||
|
|
||||||
@unittest.skipUnless(djpeg_available(), "djpeg not available")
|
@unittest.skipUnless(djpeg_available(), "djpeg not available")
|
||||||
|
|
|
@ -255,7 +255,6 @@ class TestImageDraw(PillowTestCase):
|
||||||
self.assert_image_equal(
|
self.assert_image_equal(
|
||||||
im, Image.open("Tests/images/imagedraw_floodfill2.png"))
|
im, Image.open("Tests/images/imagedraw_floodfill2.png"))
|
||||||
|
|
||||||
|
|
||||||
def create_base_image_draw(self, size,
|
def create_base_image_draw(self, size,
|
||||||
mode=DEFAULT_MODE,
|
mode=DEFAULT_MODE,
|
||||||
background1=WHITE,
|
background1=WHITE,
|
||||||
|
@ -267,23 +266,25 @@ class TestImageDraw(PillowTestCase):
|
||||||
img.putpixel((x, y), background2)
|
img.putpixel((x, y), background2)
|
||||||
return (img, ImageDraw.Draw(img))
|
return (img, ImageDraw.Draw(img))
|
||||||
|
|
||||||
|
|
||||||
def test_square(self):
|
def test_square(self):
|
||||||
expected = Image.open(os.path.join(IMAGES_PATH, 'square.png'))
|
expected = Image.open(os.path.join(IMAGES_PATH, 'square.png'))
|
||||||
expected.load()
|
expected.load()
|
||||||
img, draw = self.create_base_image_draw((10, 10))
|
img, draw = self.create_base_image_draw((10, 10))
|
||||||
draw.polygon([(2, 2), (2, 7), (7, 7), (7, 2)], BLACK)
|
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))
|
img, draw = self.create_base_image_draw((10, 10))
|
||||||
draw.polygon([(7, 7), (7, 2), (2, 2), (2, 7)], BLACK)
|
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))
|
img, draw = self.create_base_image_draw((10, 10))
|
||||||
draw.rectangle((2, 2, 7, 7), BLACK)
|
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))
|
img, draw = self.create_base_image_draw((10, 10))
|
||||||
draw.rectangle((7, 7, 2, 2), BLACK)
|
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):
|
def test_triangle_right(self):
|
||||||
expected = Image.open(os.path.join(IMAGES_PATH, 'triangle_right.png'))
|
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)
|
draw.polygon([(3, 5), (17, 5), (10, 12)], BLACK)
|
||||||
self.assert_image_equal(img, expected, 'triangle right failed')
|
self.assert_image_equal(img, expected, 'triangle right failed')
|
||||||
|
|
||||||
|
|
||||||
def test_line_horizontal(self):
|
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()
|
expected.load()
|
||||||
img, draw = self.create_base_image_draw((20, 20))
|
img, draw = self.create_base_image_draw((20, 20))
|
||||||
draw.line((5, 5, 14, 5), BLACK, 2)
|
draw.line((5, 5, 14, 5), BLACK, 2)
|
||||||
self.assert_image_equal(img, expected, 'line straigth horizontal normal 2px wide failed')
|
self.assert_image_equal(
|
||||||
expected = Image.open(os.path.join(IMAGES_PATH, 'line_horizontal_w2px_inverted.png'))
|
img, expected, 'line straigth horizontal normal 2px wide failed')
|
||||||
|
expected = Image.open(os.path.join(IMAGES_PATH,
|
||||||
|
'line_horizontal_w2px_inverted.png'))
|
||||||
expected.load()
|
expected.load()
|
||||||
img, draw = self.create_base_image_draw((20, 20))
|
img, draw = self.create_base_image_draw((20, 20))
|
||||||
draw.line((14, 5, 5, 5), BLACK, 2)
|
draw.line((14, 5, 5, 5), BLACK, 2)
|
||||||
self.assert_image_equal(img, expected, 'line straigth horizontal inverted 2px wide failed')
|
self.assert_image_equal(
|
||||||
expected = Image.open(os.path.join(IMAGES_PATH, 'line_horizontal_w3px.png'))
|
img, expected, 'line straigth horizontal inverted 2px wide failed')
|
||||||
|
expected = Image.open(os.path.join(IMAGES_PATH,
|
||||||
|
'line_horizontal_w3px.png'))
|
||||||
expected.load()
|
expected.load()
|
||||||
img, draw = self.create_base_image_draw((20, 20))
|
img, draw = self.create_base_image_draw((20, 20))
|
||||||
draw.line((5, 5, 14, 5), BLACK, 3)
|
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))
|
img, draw = self.create_base_image_draw((20, 20))
|
||||||
draw.line((14, 5, 5, 5), BLACK, 3)
|
draw.line((14, 5, 5, 5), BLACK, 3)
|
||||||
self.assert_image_equal(img, expected, 'line straigth horizontal inverted 3px wide failed')
|
self.assert_image_equal(
|
||||||
expected = Image.open(os.path.join(IMAGES_PATH, 'line_horizontal_w101px.png'))
|
img, expected, 'line straigth horizontal inverted 3px wide failed')
|
||||||
|
expected = Image.open(os.path.join(IMAGES_PATH,
|
||||||
|
'line_horizontal_w101px.png'))
|
||||||
expected.load()
|
expected.load()
|
||||||
img, draw = self.create_base_image_draw((200, 110))
|
img, draw = self.create_base_image_draw((200, 110))
|
||||||
draw.line((5, 55, 195, 55), BLACK, 101)
|
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):
|
def test_line_h_s1_w2(self):
|
||||||
self.skipTest('failing')
|
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()
|
expected.load()
|
||||||
img, draw = self.create_base_image_draw((20, 20))
|
img, draw = self.create_base_image_draw((20, 20))
|
||||||
draw.line((5, 5, 14, 6), BLACK, 2)
|
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):
|
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()
|
expected.load()
|
||||||
img, draw = self.create_base_image_draw((20, 20))
|
img, draw = self.create_base_image_draw((20, 20))
|
||||||
draw.line((5, 5, 5, 14), BLACK, 2)
|
draw.line((5, 5, 5, 14), BLACK, 2)
|
||||||
self.assert_image_equal(img, expected, 'line straigth vertical normal 2px wide failed')
|
self.assert_image_equal(
|
||||||
expected = Image.open(os.path.join(IMAGES_PATH, 'line_vertical_w2px_inverted.png'))
|
img, expected, 'line straigth vertical normal 2px wide failed')
|
||||||
|
expected = Image.open(os.path.join(IMAGES_PATH,
|
||||||
|
'line_vertical_w2px_inverted.png'))
|
||||||
expected.load()
|
expected.load()
|
||||||
img, draw = self.create_base_image_draw((20, 20))
|
img, draw = self.create_base_image_draw((20, 20))
|
||||||
draw.line((5, 14, 5, 5), BLACK, 2)
|
draw.line((5, 14, 5, 5), BLACK, 2)
|
||||||
self.assert_image_equal(img, expected, 'line straigth vertical inverted 2px wide failed')
|
self.assert_image_equal(
|
||||||
expected = Image.open(os.path.join(IMAGES_PATH, 'line_vertical_w3px.png'))
|
img, expected, 'line straigth vertical inverted 2px wide failed')
|
||||||
|
expected = Image.open(os.path.join(IMAGES_PATH,
|
||||||
|
'line_vertical_w3px.png'))
|
||||||
expected.load()
|
expected.load()
|
||||||
img, draw = self.create_base_image_draw((20, 20))
|
img, draw = self.create_base_image_draw((20, 20))
|
||||||
draw.line((5, 5, 5, 14), BLACK, 3)
|
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))
|
img, draw = self.create_base_image_draw((20, 20))
|
||||||
draw.line((5, 14, 5, 5), BLACK, 3)
|
draw.line((5, 14, 5, 5), BLACK, 3)
|
||||||
self.assert_image_equal(img, expected, 'line straigth vertical inverted 3px wide failed')
|
self.assert_image_equal(
|
||||||
expected = Image.open(os.path.join(IMAGES_PATH, 'line_vertical_w101px.png'))
|
img, expected, 'line straigth vertical inverted 3px wide failed')
|
||||||
|
expected = Image.open(os.path.join(IMAGES_PATH,
|
||||||
|
'line_vertical_w101px.png'))
|
||||||
expected.load()
|
expected.load()
|
||||||
img, draw = self.create_base_image_draw((110, 200))
|
img, draw = self.create_base_image_draw((110, 200))
|
||||||
draw.line((55, 5, 55, 195), BLACK, 101)
|
draw.line((55, 5, 55, 195), BLACK, 101)
|
||||||
|
@ -360,9 +378,9 @@ class TestImageDraw(PillowTestCase):
|
||||||
self.assert_image_equal(img, expected,
|
self.assert_image_equal(img, expected,
|
||||||
'line vertical 1px slope 2px wide failed')
|
'line vertical 1px slope 2px wide failed')
|
||||||
|
|
||||||
|
|
||||||
def test_line_oblique_45(self):
|
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()
|
expected.load()
|
||||||
img, draw = self.create_base_image_draw((20, 20))
|
img, draw = self.create_base_image_draw((20, 20))
|
||||||
draw.line((5, 5, 14, 14), BLACK, 3)
|
draw.line((5, 5, 14, 14), BLACK, 3)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user