mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-02-03 05:04:24 +03:00
commit
302f86292c
|
@ -21,7 +21,7 @@ class LargeMemoryTest(PillowTestCase):
|
|||
|
||||
def _write_png(self, xdim, ydim):
|
||||
f = self.tempfile('temp.png')
|
||||
im = Image.new('L', (xdim, ydim), (0))
|
||||
im = Image.new('L', (xdim, ydim), 0)
|
||||
im.save(f)
|
||||
|
||||
def test_large(self):
|
||||
|
|
|
@ -110,7 +110,7 @@ class PillowTestCase(unittest.TestCase):
|
|||
try:
|
||||
url = test_image_results.upload(a, b)
|
||||
logger.error("Url for test images: %s" % url)
|
||||
except Exception as msg:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
self.fail(msg or "got different content")
|
||||
|
@ -163,7 +163,6 @@ class PillowTestCase(unittest.TestCase):
|
|||
def assert_warning(self, warn_class, func, *args, **kwargs):
|
||||
import warnings
|
||||
|
||||
result = None
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
# Cause all warnings to always be triggered.
|
||||
warnings.simplefilter("always")
|
||||
|
@ -175,7 +174,7 @@ class PillowTestCase(unittest.TestCase):
|
|||
if warn_class is None:
|
||||
self.assertEqual(len(w), 0,
|
||||
"Expected no warnings, got %s" %
|
||||
list(v.category for v in w))
|
||||
[v.category for v in w])
|
||||
else:
|
||||
self.assertGreaterEqual(len(w), 1)
|
||||
found = False
|
||||
|
@ -187,10 +186,10 @@ class PillowTestCase(unittest.TestCase):
|
|||
return result
|
||||
|
||||
def assert_all_same(self, items, msg=None):
|
||||
self.assertTrue(items.count(items[0]) == len(items), msg)
|
||||
self.assertEqual(items.count(items[0]), len(items), msg)
|
||||
|
||||
def assert_not_all_same(self, items, msg=None):
|
||||
self.assertFalse(items.count(items[0]) == len(items), msg)
|
||||
self.assertNotEqual(items.count(items[0]), len(items), msg)
|
||||
|
||||
def assert_tuple_approx_equal(self, actuals, targets, threshold, msg):
|
||||
"""Tests if actuals has values within threshold from targets"""
|
||||
|
|
|
@ -9,7 +9,7 @@ class TestSanity(PillowTestCase):
|
|||
def test_sanity(self):
|
||||
|
||||
# Make sure we have the binary extension
|
||||
im = PIL.Image.core.new("L", (100, 100))
|
||||
PIL.Image.core.new("L", (100, 100))
|
||||
|
||||
self.assertEqual(PIL.Image.VERSION[:3], '1.1')
|
||||
|
||||
|
@ -19,11 +19,11 @@ class TestSanity(PillowTestCase):
|
|||
self.assertEqual(len(im.tobytes()), 1300)
|
||||
|
||||
# Create images in all remaining major modes.
|
||||
im = PIL.Image.new("L", (100, 100))
|
||||
im = PIL.Image.new("P", (100, 100))
|
||||
im = PIL.Image.new("RGB", (100, 100))
|
||||
im = PIL.Image.new("I", (100, 100))
|
||||
im = PIL.Image.new("F", (100, 100))
|
||||
PIL.Image.new("L", (100, 100))
|
||||
PIL.Image.new("P", (100, 100))
|
||||
PIL.Image.new("RGB", (100, 100))
|
||||
PIL.Image.new("I", (100, 100))
|
||||
PIL.Image.new("F", (100, 100))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -294,6 +294,8 @@ class TestColorLut3DFilter(PillowTestCase):
|
|||
|
||||
lut = ImageFilter.Color3DLUT((2, 2, 2), [(0, 1, 2, 3)] * 8,
|
||||
channels=4)
|
||||
self.assertEqual(tuple(lut.size), (2, 2, 2))
|
||||
self.assertEqual(lut.table, list(range(4)) * 8)
|
||||
|
||||
@unittest.skipIf(numpy is None, "Numpy is not installed")
|
||||
def test_numpy_sources(self):
|
||||
|
|
|
@ -5,7 +5,7 @@ from PIL import features
|
|||
try:
|
||||
from PIL import _webp
|
||||
HAVE_WEBP = True
|
||||
except:
|
||||
except ImportError:
|
||||
HAVE_WEBP = False
|
||||
|
||||
|
||||
|
|
|
@ -228,11 +228,9 @@ class TestFileEps(PillowTestCase):
|
|||
"Tests/images/illuCS6_no_preview.eps",
|
||||
"Tests/images/illuCS6_preview.eps"]
|
||||
|
||||
# Act
|
||||
# Act / Assert
|
||||
for filename in FILES:
|
||||
img = Image.open(filename)
|
||||
|
||||
# Assert
|
||||
self.assertEqual(img.mode, "RGB")
|
||||
|
||||
def test_emptyline(self):
|
||||
|
|
|
@ -28,7 +28,7 @@ class TestFileIco(PillowTestCase):
|
|||
# the default image
|
||||
output.seek(0)
|
||||
reloaded = Image.open(output)
|
||||
self.assertEqual(reloaded.info['sizes'], set([(32, 32), (64, 64)]))
|
||||
self.assertEqual(reloaded.info['sizes'], {(32, 32), (64, 64)})
|
||||
|
||||
self.assertEqual(im.mode, reloaded.mode)
|
||||
self.assertEqual((64, 64), reloaded.size)
|
||||
|
@ -81,7 +81,7 @@ class TestFileIco(PillowTestCase):
|
|||
# Assert
|
||||
self.assertEqual(
|
||||
im_saved.info['sizes'],
|
||||
set([(16, 16), (24, 24), (32, 32), (48, 48)]))
|
||||
{(16, 16), (24, 24), (32, 32), (48, 48)})
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -415,7 +415,7 @@ class TestFileLibTiff(LibTiffTestCase):
|
|||
im = Image.open('Tests/images/multipage.tiff')
|
||||
frames = im.n_frames
|
||||
self.assertEqual(frames, 3)
|
||||
for idx in range(frames):
|
||||
for _ in range(frames):
|
||||
im.seek(0)
|
||||
# Should not raise ValueError: I/O operation on closed file
|
||||
im.load()
|
||||
|
@ -545,11 +545,11 @@ class TestFileLibTiff(LibTiffTestCase):
|
|||
def test_read_icc(self):
|
||||
with Image.open("Tests/images/hopper.iccprofile.tif") as img:
|
||||
icc = img.info.get('icc_profile')
|
||||
self.assertNotEqual(icc, None)
|
||||
self.assertIsNotNone(icc)
|
||||
TiffImagePlugin.READ_LIBTIFF = True
|
||||
with Image.open("Tests/images/hopper.iccprofile.tif") as img:
|
||||
icc_libtiff = img.info.get('icc_profile')
|
||||
self.assertNotEqual(icc_libtiff, None)
|
||||
self.assertIsNotNone(icc_libtiff)
|
||||
TiffImagePlugin.READ_LIBTIFF = False
|
||||
self.assertEqual(icc, icc_libtiff)
|
||||
|
||||
|
|
|
@ -82,19 +82,19 @@ class TestFilePng(PillowTestCase):
|
|||
self.assertEqual(im.format, "PNG")
|
||||
|
||||
hopper("1").save(test_file)
|
||||
im = Image.open(test_file)
|
||||
Image.open(test_file)
|
||||
|
||||
hopper("L").save(test_file)
|
||||
im = Image.open(test_file)
|
||||
Image.open(test_file)
|
||||
|
||||
hopper("P").save(test_file)
|
||||
im = Image.open(test_file)
|
||||
Image.open(test_file)
|
||||
|
||||
hopper("RGB").save(test_file)
|
||||
im = Image.open(test_file)
|
||||
Image.open(test_file)
|
||||
|
||||
hopper("I").save(test_file)
|
||||
im = Image.open(test_file)
|
||||
Image.open(test_file)
|
||||
|
||||
def test_invalid_file(self):
|
||||
invalid_file = "Tests/images/flower.jpg"
|
||||
|
|
|
@ -26,19 +26,19 @@ class TestFileTiff(PillowTestCase):
|
|||
self.assertEqual(im.format, "TIFF")
|
||||
|
||||
hopper("1").save(filename)
|
||||
im = Image.open(filename)
|
||||
Image.open(filename)
|
||||
|
||||
hopper("L").save(filename)
|
||||
im = Image.open(filename)
|
||||
Image.open(filename)
|
||||
|
||||
hopper("P").save(filename)
|
||||
im = Image.open(filename)
|
||||
Image.open(filename)
|
||||
|
||||
hopper("RGB").save(filename)
|
||||
im = Image.open(filename)
|
||||
Image.open(filename)
|
||||
|
||||
hopper("I").save(filename)
|
||||
im = Image.open(filename)
|
||||
Image.open(filename)
|
||||
|
||||
def test_mac_tiff(self):
|
||||
# Read RGBa images from macOS [@PIL136]
|
||||
|
|
|
@ -136,8 +136,8 @@ class TestFileTiffMetadata(PillowTestCase):
|
|||
if isinstance(v, IFDRational):
|
||||
original[k] = IFDRational(*_limit_rational(v, 2**31))
|
||||
if isinstance(v, tuple) and isinstance(v[0], IFDRational):
|
||||
original[k] = tuple([IFDRational(*_limit_rational(elt, 2**31))
|
||||
for elt in v])
|
||||
original[k] = tuple(IFDRational(*_limit_rational(elt, 2**31))
|
||||
for elt in v)
|
||||
|
||||
ignored = ['StripByteCounts', 'RowsPerStrip',
|
||||
'PageNumber', 'StripOffsets']
|
||||
|
|
|
@ -5,18 +5,13 @@ from PIL import Image
|
|||
try:
|
||||
from PIL import _webp
|
||||
except ImportError:
|
||||
pass
|
||||
# Skip in setUp()
|
||||
_webp = None
|
||||
|
||||
|
||||
@unittest.skipIf(_webp is None, "WebP support not installed")
|
||||
class TestFileWebpAlpha(PillowTestCase):
|
||||
|
||||
def setUp(self):
|
||||
try:
|
||||
from PIL import _webp
|
||||
except ImportError:
|
||||
self.skipTest('WebP support not installed')
|
||||
|
||||
if _webp.WebPDecoderBuggyAlpha(self):
|
||||
self.skipTest("Buggy early version of WebP installed, "
|
||||
"not testing transparency")
|
||||
|
|
|
@ -16,7 +16,7 @@ class TestFileWebpLossless(PillowTestCase):
|
|||
self.skipTest('WebP support not installed')
|
||||
return
|
||||
|
||||
if (_webp.WebPDecoderVersion() < 0x0200):
|
||||
if _webp.WebPDecoderVersion() < 0x0200:
|
||||
self.skipTest('lossless not included')
|
||||
|
||||
self.rgb_mode = "RGB"
|
||||
|
|
|
@ -56,7 +56,7 @@ class TestImage(PillowTestCase):
|
|||
self.assertEqual(im.width, 1)
|
||||
self.assertEqual(im.height, 2)
|
||||
|
||||
with self.assertRaises(AttributeError) as e:
|
||||
with self.assertRaises(AttributeError):
|
||||
im.size = (3, 4)
|
||||
|
||||
def test_invalid_image(self):
|
||||
|
@ -286,9 +286,9 @@ class TestImage(PillowTestCase):
|
|||
source.alpha_composite, over, (0, 0),
|
||||
"invalid destination")
|
||||
self.assertRaises(ValueError,
|
||||
source.alpha_composite, over, (0))
|
||||
source.alpha_composite, over, 0)
|
||||
self.assertRaises(ValueError,
|
||||
source.alpha_composite, over, (0, 0), (0))
|
||||
source.alpha_composite, over, (0, 0), 0)
|
||||
self.assertRaises(ValueError,
|
||||
source.alpha_composite, over, (0, -1))
|
||||
self.assertRaises(ValueError,
|
||||
|
@ -516,7 +516,7 @@ class TestImage(PillowTestCase):
|
|||
self.assertEqual(new_im.palette.tobytes(),
|
||||
palette_result.tobytes())
|
||||
else:
|
||||
self.assertEqual(new_im.palette, None)
|
||||
self.assertIsNone(new_im.palette)
|
||||
|
||||
_make_new(im, im_p, im_p.palette)
|
||||
_make_new(im_p, im, None)
|
||||
|
|
|
@ -88,7 +88,7 @@ class TestImageConvert(PillowTestCase):
|
|||
# Assert
|
||||
self.assertNotIn('transparency', im_rgba.info)
|
||||
# https://github.com/python-pillow/Pillow/issues/2702
|
||||
self.assertEqual(im_rgba.palette, None)
|
||||
self.assertIsNone(im_rgba.palette)
|
||||
|
||||
def test_trns_l(self):
|
||||
im = hopper('L')
|
||||
|
|
|
@ -23,7 +23,7 @@ class TestImageGetData(PillowTestCase):
|
|||
self.assertEqual(getdata("L"), (16, 960, 960))
|
||||
self.assertEqual(getdata("I"), (16, 960, 960))
|
||||
self.assertEqual(getdata("F"), (16.0, 960, 960))
|
||||
self.assertEqual(getdata("RGB"), (((11, 13, 52), 960, 960)))
|
||||
self.assertEqual(getdata("RGB"), ((11, 13, 52), 960, 960))
|
||||
self.assertEqual(getdata("RGBA"), ((11, 13, 52, 255), 960, 960))
|
||||
self.assertEqual(getdata("CMYK"), ((244, 242, 203, 0), 960, 960))
|
||||
self.assertEqual(getdata("YCbCr"), ((16, 147, 123), 960, 960))
|
||||
|
|
|
@ -19,7 +19,7 @@ class TestImageGetExtrema(PillowTestCase):
|
|||
self.assertEqual(
|
||||
extrema("RGBA"), ((0, 255), (0, 255), (0, 255), (255, 255)))
|
||||
self.assertEqual(
|
||||
extrema("CMYK"), (((0, 255), (0, 255), (0, 255), (0, 0))))
|
||||
extrema("CMYK"), ((0, 255), (0, 255), (0, 255), (0, 0)))
|
||||
self.assertEqual(extrema("I;16"), (0, 255))
|
||||
|
||||
def test_true_16(self):
|
||||
|
|
|
@ -196,7 +196,7 @@ class TestImagingCoreResampleAccuracy(PillowTestCase):
|
|||
class CoreResampleConsistencyTest(PillowTestCase):
|
||||
def make_case(self, mode, fill):
|
||||
im = Image.new(mode, (512, 9), fill)
|
||||
return (im.resize((9, 512), Image.LANCZOS), im.load()[0, 0])
|
||||
return im.resize((9, 512), Image.LANCZOS), im.load()[0, 0]
|
||||
|
||||
def run_case(self, case):
|
||||
channel, color = case
|
||||
|
@ -453,7 +453,7 @@ class CoreResampleBoxTest(PillowTestCase):
|
|||
|
||||
# error with box should be much smaller than without
|
||||
self.assert_image_similar(reference, with_box, 6)
|
||||
with self.assertRaisesRegex(AssertionError, "difference 29\."):
|
||||
with self.assertRaisesRegex(AssertionError, r"difference 29\."):
|
||||
self.assert_image_similar(reference, without_box, 5)
|
||||
|
||||
def test_formats(self):
|
||||
|
@ -496,7 +496,7 @@ class CoreResampleBoxTest(PillowTestCase):
|
|||
try:
|
||||
res = im.resize(size, Image.LANCZOS, box)
|
||||
self.assertEqual(res.size, size)
|
||||
with self.assertRaisesRegex(AssertionError, "difference \d"):
|
||||
with self.assertRaisesRegex(AssertionError, r"difference \d"):
|
||||
# check that the difference at least that much
|
||||
self.assert_image_similar(res, im.crop(box), 20)
|
||||
except AssertionError:
|
||||
|
|
|
@ -46,7 +46,7 @@ class TestImageDraw(PillowTestCase):
|
|||
im = Image.open("Tests/images/chi.gif")
|
||||
|
||||
draw = ImageDraw.Draw(im)
|
||||
draw.line(((0, 0)), fill=(0, 0, 0))
|
||||
draw.line((0, 0), fill=(0, 0, 0))
|
||||
|
||||
def test_mode_mismatch(self):
|
||||
im = hopper("RGB").copy()
|
||||
|
@ -543,7 +543,7 @@ class TestImageDraw(PillowTestCase):
|
|||
for y in range(0, size[1]):
|
||||
if (x + y) % 2 == 0:
|
||||
img.putpixel((x, y), background2)
|
||||
return (img, ImageDraw.Draw(img))
|
||||
return img, ImageDraw.Draw(img)
|
||||
|
||||
def test_square(self):
|
||||
expected = Image.open(os.path.join(IMAGES_PATH, 'square.png'))
|
||||
|
|
|
@ -144,7 +144,7 @@ class TestImageFile(PillowTestCase):
|
|||
class MockPyDecoder(ImageFile.PyDecoder):
|
||||
def decode(self, buffer):
|
||||
# eof
|
||||
return (-1, 0)
|
||||
return -1, 0
|
||||
|
||||
|
||||
xoff, yoff, xsize, ysize = 10, 20, 100, 100
|
||||
|
@ -204,7 +204,7 @@ class TestPyDecoder(PillowTestCase):
|
|||
|
||||
im = MockImageFile(buf)
|
||||
im.tile = [("MOCK", (xoff, yoff, -10, yoff+ysize), 32, None)]
|
||||
d = self.get_decoder()
|
||||
self.get_decoder()
|
||||
|
||||
self.assertRaises(ValueError, im.load)
|
||||
|
||||
|
@ -218,7 +218,7 @@ class TestPyDecoder(PillowTestCase):
|
|||
im.tile = [
|
||||
("MOCK", (xoff, yoff, xoff+xsize + 100, yoff+ysize), 32, None)
|
||||
]
|
||||
d = self.get_decoder()
|
||||
self.get_decoder()
|
||||
|
||||
self.assertRaises(ValueError, im.load)
|
||||
|
||||
|
|
|
@ -11,23 +11,22 @@ try:
|
|||
import Tkinter as tk
|
||||
dir(ImageTk)
|
||||
HAS_TK = True
|
||||
except (OSError, ImportError) as v:
|
||||
except (OSError, ImportError):
|
||||
# Skipped via setUp()
|
||||
HAS_TK = False
|
||||
|
||||
TK_MODES = ('1', 'L', 'P', 'RGB', 'RGBA')
|
||||
|
||||
|
||||
@unittest.skipIf(not HAS_TK, "Tk not installed")
|
||||
class TestImageTk(PillowTestCase):
|
||||
|
||||
def setUp(self):
|
||||
if not HAS_TK:
|
||||
self.skipTest("Tk not installed")
|
||||
try:
|
||||
# setup tk
|
||||
tk.Frame()
|
||||
# root = tk.Tk()
|
||||
except (tk.TclError) as v:
|
||||
except tk.TclError as v:
|
||||
self.skipTest("TCL Error: %s" % v)
|
||||
|
||||
def test_kw(self):
|
||||
|
|
|
@ -17,7 +17,7 @@ class TestLibPack(PillowTestCase):
|
|||
for x, pixel in enumerate(pixels):
|
||||
im.putpixel((x, 0), pixel)
|
||||
|
||||
if isinstance(data, (int)):
|
||||
if isinstance(data, int):
|
||||
data_len = data * len(pixels)
|
||||
data = bytes(bytearray(range(1, data_len + 1)))
|
||||
|
||||
|
@ -217,7 +217,7 @@ class TestLibUnpack(PillowTestCase):
|
|||
"""
|
||||
data - either raw bytes with data or just number of bytes in rawmode.
|
||||
"""
|
||||
if isinstance(data, (int)):
|
||||
if isinstance(data, int):
|
||||
data_len = data * len(pixels)
|
||||
data = bytes(bytearray(range(1, data_len + 1)))
|
||||
|
||||
|
|
|
@ -8,9 +8,9 @@ except ImportError:
|
|||
pyroma = None
|
||||
|
||||
|
||||
@unittest.skipIf(pyroma is None, "Pyroma is not installed")
|
||||
class TestPyroma(PillowTestCase):
|
||||
|
||||
@unittest.skipUnless(pyroma, "Pyroma is not installed")
|
||||
def test_pyroma(self):
|
||||
# Arrange
|
||||
data = pyroma.projectdata.get_data(".")
|
||||
|
|
|
@ -70,8 +70,8 @@ class TestToQImage(PillowQtTestCase, PillowTestCase):
|
|||
def test_segfault(self):
|
||||
app = QApplication([])
|
||||
ex = Example()
|
||||
assert(app) # Silence warning
|
||||
assert(ex) # Silence warning
|
||||
assert app # Silence warning
|
||||
assert ex # Silence warning
|
||||
|
||||
|
||||
if ImageQt.qt_is_installed:
|
||||
|
@ -86,7 +86,7 @@ if ImageQt.qt_is_installed:
|
|||
|
||||
pixmap1 = QtGui.QPixmap.fromImage(qimage)
|
||||
|
||||
hbox = QHBoxLayout(self)
|
||||
QHBoxLayout(self)
|
||||
|
||||
lbl = QLabel(self)
|
||||
# Segfault in the problem
|
||||
|
|
Loading…
Reference in New Issue
Block a user