mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-12 02:06:18 +03:00
Changed format of lambda calls
This commit is contained in:
parent
371933a597
commit
9e843a2d9b
|
@ -36,7 +36,7 @@ class TestDecompressionBomb(PillowTestCase):
|
|||
|
||||
# Act / Assert
|
||||
self.assert_warning(Image.DecompressionBombWarning,
|
||||
lambda: Image.open(TEST_FILE))
|
||||
Image.open, TEST_FILE)
|
||||
|
||||
class TestDecompressionCrop(PillowTestCase):
|
||||
|
||||
|
@ -52,7 +52,7 @@ class TestDecompressionCrop(PillowTestCase):
|
|||
# same decompression bomb warnings on them.
|
||||
box = (0, 0, self.src.width * 2, self.src.height * 2)
|
||||
self.assert_warning(Image.DecompressionBombWarning,
|
||||
lambda: self.src.crop(box))
|
||||
self.src.crop, box)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -7,7 +7,7 @@ try:
|
|||
HAVE_WEBP = True
|
||||
except:
|
||||
HAVE_WEBP = False
|
||||
|
||||
|
||||
|
||||
class TestFeatures(PillowTestCase):
|
||||
|
||||
|
@ -34,7 +34,7 @@ class TestFeatures(PillowTestCase):
|
|||
def check_webp_mux(self):
|
||||
self.assertEqual(features.check('webp_mux'),
|
||||
_webp.HAVE_WEBPMUX)
|
||||
|
||||
|
||||
def test_check_modules(self):
|
||||
for feature in features.modules:
|
||||
self.assertIn(features.check_module(feature), [True, False])
|
||||
|
@ -51,13 +51,13 @@ class TestFeatures(PillowTestCase):
|
|||
# Arrange
|
||||
codec = "unsupported_codec"
|
||||
# Act / Assert
|
||||
self.assertRaises(ValueError, lambda: features.check_codec(codec))
|
||||
self.assertRaises(ValueError, features.check_codec, codec)
|
||||
|
||||
def test_unsupported_module(self):
|
||||
# Arrange
|
||||
module = "unsupported_module"
|
||||
# Act / Assert
|
||||
self.assertRaises(ValueError, lambda: features.check_module(module))
|
||||
self.assertRaises(ValueError, features.check_module, module)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -28,7 +28,7 @@ class TestFileBmp(PillowTestCase):
|
|||
def test_invalid_file(self):
|
||||
with open("Tests/images/flower.jpg", "rb") as fp:
|
||||
self.assertRaises(SyntaxError,
|
||||
lambda: BmpImagePlugin.BmpImageFile(fp))
|
||||
BmpImagePlugin.BmpImageFile, fp)
|
||||
|
||||
def test_save_to_bytes(self):
|
||||
output = io.BytesIO()
|
||||
|
|
|
@ -24,8 +24,7 @@ class TestFileBufrStub(PillowTestCase):
|
|||
|
||||
# Act / Assert
|
||||
self.assertRaises(SyntaxError,
|
||||
lambda:
|
||||
BufrStubImagePlugin.BufrStubImageFile(invalid_file))
|
||||
BufrStubImagePlugin.BufrStubImageFile, invalid_file)
|
||||
|
||||
def test_load(self):
|
||||
# Arrange
|
||||
|
@ -40,7 +39,7 @@ class TestFileBufrStub(PillowTestCase):
|
|||
tmpfile = self.tempfile("temp.bufr")
|
||||
|
||||
# Act / Assert: stub cannot save without an implemented handler
|
||||
self.assertRaises(IOError, lambda: im.save(tmpfile))
|
||||
self.assertRaises(IOError, im.save, tmpfile)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -21,7 +21,7 @@ class TestFileCur(PillowTestCase):
|
|||
invalid_file = "Tests/images/flower.jpg"
|
||||
|
||||
self.assertRaises(SyntaxError,
|
||||
lambda: CurImagePlugin.CurImageFile(invalid_file))
|
||||
CurImagePlugin.CurImageFile, invalid_file)
|
||||
|
||||
no_cursors_file = "Tests/images/no_cursors.cur"
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ class TestFileDcx(PillowTestCase):
|
|||
def test_invalid_file(self):
|
||||
with open("Tests/images/flower.jpg", "rb") as fp:
|
||||
self.assertRaises(SyntaxError,
|
||||
lambda: DcxImagePlugin.DcxImageFile(fp))
|
||||
DcxImagePlugin.DcxImageFile, fp)
|
||||
|
||||
def test_tell(self):
|
||||
# Arrange
|
||||
|
@ -58,7 +58,7 @@ class TestFileDcx(PillowTestCase):
|
|||
frame = 999 # too big on purpose
|
||||
|
||||
# Act / Assert
|
||||
self.assertRaises(EOFError, lambda: im.seek(frame))
|
||||
self.assertRaises(EOFError, im.seek, frame)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -55,7 +55,7 @@ class TestFileEps(PillowTestCase):
|
|||
invalid_file = "Tests/images/flower.jpg"
|
||||
|
||||
self.assertRaises(SyntaxError,
|
||||
lambda: EpsImagePlugin.EpsImageFile(invalid_file))
|
||||
EpsImagePlugin.EpsImageFile, invalid_file)
|
||||
|
||||
def test_cmyk(self):
|
||||
cmyk_image = Image.open("Tests/images/pil_sample_cmyk.eps")
|
||||
|
@ -97,7 +97,7 @@ class TestFileEps(PillowTestCase):
|
|||
def test_image_mode_not_supported(self):
|
||||
im = hopper("RGBA")
|
||||
tmpfile = self.tempfile('temp.eps')
|
||||
self.assertRaises(ValueError, lambda: im.save(tmpfile))
|
||||
self.assertRaises(ValueError, im.save, tmpfile)
|
||||
|
||||
def test_render_scale1(self):
|
||||
# We need png support for these render test
|
||||
|
|
|
@ -24,8 +24,7 @@ class TestFileFitsStub(PillowTestCase):
|
|||
|
||||
# Act / Assert
|
||||
self.assertRaises(SyntaxError,
|
||||
lambda:
|
||||
FitsStubImagePlugin.FITSStubImageFile(invalid_file))
|
||||
FitsStubImagePlugin.FITSStubImageFile, invalid_file)
|
||||
|
||||
def test_load(self):
|
||||
# Arrange
|
||||
|
@ -41,10 +40,10 @@ class TestFileFitsStub(PillowTestCase):
|
|||
dummy_filename = "dummy.filename"
|
||||
|
||||
# Act / Assert: stub cannot save without an implemented handler
|
||||
self.assertRaises(IOError, lambda: im.save(dummy_filename))
|
||||
self.assertRaises(IOError, im.save, dummy_filename)
|
||||
self.assertRaises(
|
||||
IOError,
|
||||
lambda: FitsStubImagePlugin._save(im, dummy_fp, dummy_filename))
|
||||
FitsStubImagePlugin._save, im, dummy_fp, dummy_filename)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -41,7 +41,7 @@ class TestFileFli(PillowTestCase):
|
|||
invalid_file = "Tests/images/flower.jpg"
|
||||
|
||||
self.assertRaises(SyntaxError,
|
||||
lambda: FliImagePlugin.FliImageFile(invalid_file))
|
||||
FliImagePlugin.FliImageFile, invalid_file)
|
||||
|
||||
def test_n_frames(self):
|
||||
im = Image.open(static_test_file)
|
||||
|
@ -71,7 +71,7 @@ class TestFileFli(PillowTestCase):
|
|||
self.assertEqual(im.tell(), 0)
|
||||
|
||||
# Test seek past end of file
|
||||
self.assertRaises(EOFError, lambda: im.seek(2))
|
||||
self.assertRaises(EOFError, im.seek, 2)
|
||||
|
||||
def test_seek_tell(self):
|
||||
im = Image.open(animated_test_file)
|
||||
|
|
|
@ -9,12 +9,12 @@ class TestFileFpx(PillowTestCase):
|
|||
# Test an invalid OLE file
|
||||
invalid_file = "Tests/images/flower.jpg"
|
||||
self.assertRaises(SyntaxError,
|
||||
lambda: FpxImagePlugin.FpxImageFile(invalid_file))
|
||||
FpxImagePlugin.FpxImageFile, invalid_file)
|
||||
|
||||
# Test a valid OLE file, but not an FPX file
|
||||
ole_file = "Tests/images/test-ole-file.doc"
|
||||
self.assertRaises(SyntaxError,
|
||||
lambda: FpxImagePlugin.FpxImageFile(ole_file))
|
||||
FpxImagePlugin.FpxImageFile, ole_file)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -9,7 +9,7 @@ class TestFileGbr(PillowTestCase):
|
|||
invalid_file = "Tests/images/flower.jpg"
|
||||
|
||||
self.assertRaises(SyntaxError,
|
||||
lambda: GbrImagePlugin.GbrImageFile(invalid_file))
|
||||
GbrImagePlugin.GbrImageFile, invalid_file)
|
||||
|
||||
def test_gbr_file(self):
|
||||
im = Image.open('Tests/images/gbr.gbr')
|
||||
|
|
|
@ -31,7 +31,7 @@ class TestFileGif(PillowTestCase):
|
|||
invalid_file = "Tests/images/flower.jpg"
|
||||
|
||||
self.assertRaises(SyntaxError,
|
||||
lambda: GifImagePlugin.GifImageFile(invalid_file))
|
||||
GifImagePlugin.GifImageFile, invalid_file)
|
||||
|
||||
def test_optimize(self):
|
||||
def test_grayscale(optimize):
|
||||
|
|
|
@ -10,13 +10,13 @@ class TestImage(PillowTestCase):
|
|||
GimpPaletteFile(fp)
|
||||
|
||||
with open('Tests/images/hopper.jpg', 'rb') as fp:
|
||||
self.assertRaises(SyntaxError, lambda: GimpPaletteFile(fp))
|
||||
self.assertRaises(SyntaxError, GimpPaletteFile, fp)
|
||||
|
||||
with open('Tests/images/bad_palette_file.gpl', 'rb') as fp:
|
||||
self.assertRaises(SyntaxError, lambda: GimpPaletteFile(fp))
|
||||
self.assertRaises(SyntaxError, GimpPaletteFile, fp)
|
||||
|
||||
with open('Tests/images/bad_palette_entry.gpl', 'rb') as fp:
|
||||
self.assertRaises(ValueError, lambda: GimpPaletteFile(fp))
|
||||
self.assertRaises(ValueError, GimpPaletteFile, fp)
|
||||
|
||||
def test_get_palette(self):
|
||||
# Arrange
|
||||
|
|
|
@ -24,8 +24,7 @@ class TestFileGribStub(PillowTestCase):
|
|||
|
||||
# Act / Assert
|
||||
self.assertRaises(SyntaxError,
|
||||
lambda:
|
||||
GribStubImagePlugin.GribStubImageFile(invalid_file))
|
||||
GribStubImagePlugin.GribStubImageFile, invalid_file)
|
||||
|
||||
def test_load(self):
|
||||
# Arrange
|
||||
|
@ -40,7 +39,7 @@ class TestFileGribStub(PillowTestCase):
|
|||
tmpfile = self.tempfile("temp.grib")
|
||||
|
||||
# Act / Assert: stub cannot save without an implemented handler
|
||||
self.assertRaises(IOError, lambda: im.save(tmpfile))
|
||||
self.assertRaises(IOError, im.save, tmpfile)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -24,8 +24,7 @@ class TestFileHdf5Stub(PillowTestCase):
|
|||
|
||||
# Act / Assert
|
||||
self.assertRaises(SyntaxError,
|
||||
lambda:
|
||||
Hdf5StubImagePlugin.HDF5StubImageFile(invalid_file))
|
||||
Hdf5StubImagePlugin.HDF5StubImageFile, invalid_file)
|
||||
|
||||
def test_load(self):
|
||||
# Arrange
|
||||
|
@ -41,10 +40,10 @@ class TestFileHdf5Stub(PillowTestCase):
|
|||
dummy_filename = "dummy.filename"
|
||||
|
||||
# Act / Assert: stub cannot save without an implemented handler
|
||||
self.assertRaises(IOError, lambda: im.save(dummy_filename))
|
||||
self.assertRaises(IOError, im.save, dummy_filename)
|
||||
self.assertRaises(
|
||||
IOError,
|
||||
lambda: Hdf5StubImagePlugin._save(im, dummy_fp, dummy_filename))
|
||||
Hdf5StubImagePlugin._save, im, dummy_fp, dummy_filename)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -98,7 +98,7 @@ class TestFileIcns(PillowTestCase):
|
|||
def test_not_an_icns_file(self):
|
||||
with io.BytesIO(b'invalid\n') as fp:
|
||||
self.assertRaises(SyntaxError,
|
||||
lambda: IcnsImagePlugin.IcnsFile(fp))
|
||||
IcnsImagePlugin.IcnsFile, fp)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -18,7 +18,7 @@ class TestFileIco(PillowTestCase):
|
|||
def test_invalid_file(self):
|
||||
with open("Tests/images/flower.jpg", "rb") as fp:
|
||||
self.assertRaises(SyntaxError,
|
||||
lambda: IcoImagePlugin.IcoImageFile(fp))
|
||||
IcoImagePlugin.IcoImageFile, fp)
|
||||
|
||||
def test_save_to_bytes(self):
|
||||
output = io.BytesIO()
|
||||
|
|
|
@ -54,13 +54,13 @@ class TestFileIm(PillowTestCase):
|
|||
def test_save_unsupported_mode(self):
|
||||
out = self.tempfile('temp.im')
|
||||
im = hopper("HSV")
|
||||
self.assertRaises(ValueError, lambda: im.save(out))
|
||||
self.assertRaises(ValueError, im.save, out)
|
||||
|
||||
def test_invalid_file(self):
|
||||
invalid_file = "Tests/images/flower.jpg"
|
||||
|
||||
self.assertRaises(SyntaxError,
|
||||
lambda: ImImagePlugin.ImImageFile(invalid_file))
|
||||
ImImagePlugin.ImImageFile, invalid_file)
|
||||
|
||||
def test_number(self):
|
||||
self.assertEqual(1.2, ImImagePlugin.number("1.2"))
|
||||
|
|
|
@ -312,7 +312,7 @@ class TestFileJpeg(PillowTestCase):
|
|||
self.assertEqual(getsampling(im), (2, 2, 1, 1, 1, 1))
|
||||
|
||||
self.assertRaises(
|
||||
TypeError, lambda: self.roundtrip(hopper(), subsampling="1:1:1"))
|
||||
TypeError, self.roundtrip, hopper(), subsampling="1:1:1")
|
||||
|
||||
def test_exif(self):
|
||||
im = Image.open("Tests/images/pil_sample_rgb.jpg")
|
||||
|
@ -421,18 +421,18 @@ class TestFileJpeg(PillowTestCase):
|
|||
self._n_qtables_helper(4, "Tests/images/pil_sample_cmyk.jpg")
|
||||
|
||||
# not a sequence
|
||||
self.assertRaises(Exception, lambda: self.roundtrip(im, qtables='a'))
|
||||
self.assertRaises(Exception, self.roundtrip, im, qtables='a')
|
||||
# sequence wrong length
|
||||
self.assertRaises(Exception, lambda: self.roundtrip(im, qtables=[]))
|
||||
self.assertRaises(Exception, self.roundtrip, im, qtables=[])
|
||||
# sequence wrong length
|
||||
self.assertRaises(Exception,
|
||||
lambda: self.roundtrip(im, qtables=[1, 2, 3, 4, 5]))
|
||||
self.roundtrip, im, qtables=[1, 2, 3, 4, 5])
|
||||
|
||||
# qtable entry not a sequence
|
||||
self.assertRaises(Exception, lambda: self.roundtrip(im, qtables=[1]))
|
||||
self.assertRaises(Exception, self.roundtrip, im, qtables=[1])
|
||||
# qtable entry has wrong number of items
|
||||
self.assertRaises(Exception,
|
||||
lambda: self.roundtrip(im, qtables=[[1, 2, 3, 4]]))
|
||||
self.roundtrip, im, qtables=[[1, 2, 3, 4]])
|
||||
|
||||
@unittest.skipUnless(djpeg_available(), "djpeg not available")
|
||||
def test_load_djpeg(self):
|
||||
|
@ -477,7 +477,7 @@ class TestFileJpeg(PillowTestCase):
|
|||
# Act
|
||||
# Shouldn't raise error
|
||||
fn = "Tests/images/sugarshack_bad_mpo_header.jpg"
|
||||
im = self.assert_warning(UserWarning, lambda: Image.open(fn))
|
||||
im = self.assert_warning(UserWarning, Image.open, fn)
|
||||
|
||||
# Assert
|
||||
self.assertEqual(im.format, "JPEG")
|
||||
|
@ -582,7 +582,7 @@ class TestFileCloseW32(PillowTestCase):
|
|||
im = Image.open(tmpfile)
|
||||
fp = im.fp
|
||||
self.assertFalse(fp.closed)
|
||||
self.assertRaises(Exception, lambda: os.remove(tmpfile))
|
||||
self.assertRaises(Exception, os.remove, tmpfile)
|
||||
im.load()
|
||||
self.assertTrue(fp.closed)
|
||||
# this should not fail, as load should have closed the file.
|
||||
|
|
|
@ -44,8 +44,7 @@ class TestFileJpeg2k(PillowTestCase):
|
|||
invalid_file = "Tests/images/flower.jpg"
|
||||
|
||||
self.assertRaises(SyntaxError,
|
||||
lambda:
|
||||
Jpeg2KImagePlugin.Jpeg2KImageFile(invalid_file))
|
||||
Jpeg2KImagePlugin.Jpeg2KImageFile, invalid_file)
|
||||
|
||||
def test_bytesio(self):
|
||||
with open('Tests/images/test-card-lossless.jp2', 'rb') as f:
|
||||
|
|
|
@ -362,10 +362,9 @@ class TestFileLibTiff(LibTiffTestCase):
|
|||
im = hopper('RGB')
|
||||
out = self.tempfile('temp.tif')
|
||||
|
||||
self.assertRaises(
|
||||
IOError, lambda: im.save(out, compression='tiff_ccitt'))
|
||||
self.assertRaises(IOError, lambda: im.save(out, compression='group3'))
|
||||
self.assertRaises(IOError, lambda: im.save(out, compression='group4'))
|
||||
self.assertRaises(IOError, im.save, out, compression='tiff_ccitt')
|
||||
self.assertRaises(IOError, im.save, out, compression='group3')
|
||||
self.assertRaises(IOError, im.save, out, compression='group4')
|
||||
|
||||
def test_fp_leak(self):
|
||||
im = Image.open("Tests/images/hopper_g4_500.tif")
|
||||
|
@ -373,10 +372,10 @@ class TestFileLibTiff(LibTiffTestCase):
|
|||
|
||||
os.fstat(fn)
|
||||
im.load() # this should close it.
|
||||
self.assertRaises(OSError, lambda: os.fstat(fn))
|
||||
self.assertRaises(OSError, os.fstat, fn)
|
||||
im = None # this should force even more closed.
|
||||
self.assertRaises(OSError, lambda: os.fstat(fn))
|
||||
self.assertRaises(OSError, lambda: os.close(fn))
|
||||
self.assertRaises(OSError, os.fstat, fn)
|
||||
self.assertRaises(OSError, os.close, fn)
|
||||
|
||||
def test_multipage(self):
|
||||
# issue #862
|
||||
|
|
|
@ -9,8 +9,7 @@ class TestFileMcIdas(PillowTestCase):
|
|||
invalid_file = "Tests/images/flower.jpg"
|
||||
|
||||
self.assertRaises(SyntaxError,
|
||||
lambda:
|
||||
McIdasImagePlugin.McIdasImageFile(invalid_file))
|
||||
McIdasImagePlugin.McIdasImageFile, invalid_file)
|
||||
|
||||
def test_valid_file(self):
|
||||
# Arrange
|
||||
|
|
|
@ -42,19 +42,19 @@ class TestFileMic(PillowTestCase):
|
|||
im.seek(0)
|
||||
self.assertEqual(im.tell(), 0)
|
||||
|
||||
self.assertRaises(EOFError, lambda: im.seek(99))
|
||||
self.assertRaises(EOFError, im.seek, 99)
|
||||
self.assertEqual(im.tell(), 0)
|
||||
|
||||
def test_invalid_file(self):
|
||||
# Test an invalid OLE file
|
||||
invalid_file = "Tests/images/flower.jpg"
|
||||
self.assertRaises(SyntaxError,
|
||||
lambda: MicImagePlugin.MicImageFile(invalid_file))
|
||||
MicImagePlugin.MicImageFile, invalid_file)
|
||||
|
||||
# Test a valid OLE file, but not a MIC file
|
||||
ole_file = "Tests/images/test-ole-file.doc"
|
||||
self.assertRaises(SyntaxError,
|
||||
lambda: MicImagePlugin.MicImageFile(ole_file))
|
||||
MicImagePlugin.MicImageFile, ole_file)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -26,7 +26,7 @@ class TestFileMsp(PillowTestCase):
|
|||
invalid_file = "Tests/images/flower.jpg"
|
||||
|
||||
self.assertRaises(SyntaxError,
|
||||
lambda: MspImagePlugin.MspImageFile(invalid_file))
|
||||
MspImagePlugin.MspImageFile, invalid_file)
|
||||
|
||||
def test_bad_checksum(self):
|
||||
# Arrange
|
||||
|
@ -35,7 +35,7 @@ class TestFileMsp(PillowTestCase):
|
|||
|
||||
# Act / Assert
|
||||
self.assertRaises(SyntaxError,
|
||||
lambda: MspImagePlugin.MspImageFile(bad_checksum))
|
||||
MspImagePlugin.MspImageFile, bad_checksum)
|
||||
|
||||
def test_open_windows_v1(self):
|
||||
# Arrange
|
||||
|
@ -77,7 +77,7 @@ class TestFileMsp(PillowTestCase):
|
|||
filename = self.tempfile("temp.msp")
|
||||
|
||||
# Act/Assert
|
||||
self.assertRaises(IOError, lambda: im.save(filename))
|
||||
self.assertRaises(IOError, im.save, filename)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -51,7 +51,7 @@ class TestFilePalm(PillowTestCase):
|
|||
mode = "RGB"
|
||||
|
||||
# Act / Assert
|
||||
self.assertRaises(IOError, lambda: self.helper_save_as_palm(mode))
|
||||
self.assertRaises(IOError, self.helper_save_as_palm, mode)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -21,13 +21,14 @@ class TestFilePcx(PillowTestCase):
|
|||
|
||||
# Test an unsupported mode
|
||||
f = self.tempfile("temp.pcx")
|
||||
self.assertRaises(ValueError, lambda: hopper("RGBA").save(f))
|
||||
im = hopper("RGBA")
|
||||
self.assertRaises(ValueError, im.save, f)
|
||||
|
||||
def test_invalid_file(self):
|
||||
invalid_file = "Tests/images/flower.jpg"
|
||||
|
||||
self.assertRaises(SyntaxError,
|
||||
lambda: PcxImagePlugin.PcxImageFile(invalid_file))
|
||||
PcxImagePlugin.PcxImageFile, invalid_file)
|
||||
|
||||
def test_odd(self):
|
||||
# see issue #523, odd sized images should have a stride that's even.
|
||||
|
|
|
@ -59,7 +59,7 @@ class TestFilePdf(PillowTestCase):
|
|||
im = hopper("LA")
|
||||
outfile = self.tempfile("temp_LA.pdf")
|
||||
|
||||
self.assertRaises(ValueError, lambda: im.save(outfile))
|
||||
self.assertRaises(ValueError, im.save, outfile)
|
||||
|
||||
def test_save_all(self):
|
||||
# Single frame image
|
||||
|
|
|
@ -22,7 +22,7 @@ class TestFilePixar(PillowTestCase):
|
|||
|
||||
self.assertRaises(
|
||||
SyntaxError,
|
||||
lambda: PixarImagePlugin.PixarImageFile(invalid_file))
|
||||
PixarImagePlugin.PixarImageFile, invalid_file)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -87,14 +87,14 @@ class TestFilePng(PillowTestCase):
|
|||
invalid_file = "Tests/images/flower.jpg"
|
||||
|
||||
self.assertRaises(SyntaxError,
|
||||
lambda: PngImagePlugin.PngImageFile(invalid_file))
|
||||
PngImagePlugin.PngImageFile, invalid_file)
|
||||
|
||||
def test_broken(self):
|
||||
# Check reading of totally broken files. In this case, the test
|
||||
# file was checked into Subversion as a text file.
|
||||
|
||||
test_file = "Tests/images/broken.png"
|
||||
self.assertRaises(IOError, lambda: Image.open(test_file))
|
||||
self.assertRaises(IOError, Image.open, test_file)
|
||||
|
||||
def test_bad_text(self):
|
||||
# Make sure PIL can read malformed tEXt chunks (@PIL152)
|
||||
|
@ -424,7 +424,7 @@ class TestFilePng(PillowTestCase):
|
|||
data = b'\x89' + fd.read()
|
||||
|
||||
pngfile = BytesIO(data)
|
||||
self.assertRaises(IOError, lambda: Image.open(pngfile))
|
||||
self.assertRaises(IOError, Image.open, pngfile)
|
||||
|
||||
def test_trns_rgb(self):
|
||||
# Check writing and reading of tRNS chunks for RGB images.
|
||||
|
|
|
@ -39,7 +39,7 @@ class TestFilePpm(PillowTestCase):
|
|||
with open(path, 'w') as f:
|
||||
f.write('P6')
|
||||
|
||||
self.assertRaises(ValueError, lambda: Image.open(path))
|
||||
self.assertRaises(ValueError, Image.open, path)
|
||||
|
||||
def test_neg_ppm(self):
|
||||
# Storage.c accepted negative values for xsize, ysize. the
|
||||
|
|
|
@ -21,7 +21,7 @@ class TestImagePsd(PillowTestCase):
|
|||
invalid_file = "Tests/images/flower.jpg"
|
||||
|
||||
self.assertRaises(SyntaxError,
|
||||
lambda: PsdImagePlugin.PsdImageFile(invalid_file))
|
||||
PsdImagePlugin.PsdImageFile, invalid_file)
|
||||
|
||||
def test_n_frames(self):
|
||||
im = Image.open("Tests/images/hopper_merged.psd")
|
||||
|
@ -66,7 +66,7 @@ class TestImagePsd(PillowTestCase):
|
|||
def test_seek_eoferror(self):
|
||||
im = Image.open(test_file)
|
||||
|
||||
self.assertRaises(EOFError, lambda: im.seek(-1))
|
||||
self.assertRaises(EOFError, im.seek, -1)
|
||||
|
||||
def test_icc_profile(self):
|
||||
im = Image.open(test_file)
|
||||
|
|
|
@ -42,8 +42,7 @@ class TestFileSgi(PillowTestCase):
|
|||
invalid_file = "Tests/images/flower.jpg"
|
||||
|
||||
self.assertRaises(ValueError,
|
||||
lambda:
|
||||
SgiImagePlugin.SgiImageFile(invalid_file))
|
||||
SgiImagePlugin.SgiImageFile, invalid_file)
|
||||
|
||||
def test_write(self):
|
||||
def roundtrip(img):
|
||||
|
@ -62,14 +61,14 @@ class TestFileSgi(PillowTestCase):
|
|||
im = hopper('LA')
|
||||
out = self.tempfile('temp.sgi')
|
||||
|
||||
self.assertRaises(ValueError, lambda: im.save(out, format='sgi'))
|
||||
self.assertRaises(ValueError, im.save, out, format='sgi')
|
||||
|
||||
def test_incorrect_number_of_bands(self):
|
||||
im = hopper('YCbCr')
|
||||
im.mode = 'RGB'
|
||||
out = self.tempfile('temp.sgi')
|
||||
|
||||
self.assertRaises(ValueError, lambda: im.save(out, format='sgi'))
|
||||
self.assertRaises(ValueError, im.save, out, format='sgi')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -84,12 +84,12 @@ class TestImageSpider(PillowTestCase):
|
|||
def test_invalid_file(self):
|
||||
invalid_file = "Tests/images/invalid.spider"
|
||||
|
||||
self.assertRaises(IOError, lambda: Image.open(invalid_file))
|
||||
self.assertRaises(IOError, Image.open, invalid_file)
|
||||
|
||||
def test_nonstack_file(self):
|
||||
im = Image.open(TEST_FILE)
|
||||
|
||||
self.assertRaises(EOFError, lambda: im.seek(0))
|
||||
self.assertRaises(EOFError, im.seek, 0)
|
||||
|
||||
def test_nonstack_dos(self):
|
||||
im = Image.open(TEST_FILE)
|
||||
|
|
|
@ -24,7 +24,7 @@ class TestFileSun(PillowTestCase):
|
|||
|
||||
invalid_file = "Tests/images/flower.jpg"
|
||||
self.assertRaises(SyntaxError,
|
||||
lambda: SunImagePlugin.SunImageFile(invalid_file))
|
||||
SunImagePlugin.SunImageFile, invalid_file)
|
||||
|
||||
def test_im1(self):
|
||||
im = Image.open('Tests/images/sunraster.im1')
|
||||
|
|
|
@ -144,11 +144,11 @@ class TestFileTiff(PillowTestCase):
|
|||
invalid_file = "Tests/images/flower.jpg"
|
||||
|
||||
self.assertRaises(SyntaxError,
|
||||
lambda: TiffImagePlugin.TiffImageFile(invalid_file))
|
||||
TiffImagePlugin.TiffImageFile, invalid_file)
|
||||
|
||||
TiffImagePlugin.PREFIXES.append(b"\xff\xd8\xff\xe0")
|
||||
self.assertRaises(SyntaxError,
|
||||
lambda: TiffImagePlugin.TiffImageFile(invalid_file))
|
||||
TiffImagePlugin.TiffImageFile, invalid_file)
|
||||
TiffImagePlugin.PREFIXES.pop()
|
||||
|
||||
def test_bad_exif(self):
|
||||
|
@ -167,7 +167,7 @@ class TestFileTiff(PillowTestCase):
|
|||
def test_save_unsupported_mode(self):
|
||||
im = hopper("HSV")
|
||||
outfile = self.tempfile("temp.tif")
|
||||
self.assertRaises(IOError, lambda: im.save(outfile))
|
||||
self.assertRaises(IOError, im.save, outfile)
|
||||
|
||||
def test_little_endian(self):
|
||||
im = Image.open('Tests/images/16bit.cropped.tif')
|
||||
|
@ -344,7 +344,7 @@ class TestFileTiff(PillowTestCase):
|
|||
filename = "Tests/images/pil136.tiff"
|
||||
im = Image.open(filename)
|
||||
self.assertEqual(im.tell(), 0)
|
||||
self.assertRaises(EOFError, lambda: im.seek(1))
|
||||
self.assertRaises(EOFError, im.seek, 1)
|
||||
|
||||
def test__limit_rational_int(self):
|
||||
from PIL.TiffImagePlugin import _limit_rational
|
||||
|
@ -519,7 +519,7 @@ class TestFileTiffW32(PillowTestCase):
|
|||
im = Image.open(tmpfile)
|
||||
fp = im.fp
|
||||
self.assertFalse(fp.closed)
|
||||
self.assertRaises(Exception, lambda: os.remove(tmpfile))
|
||||
self.assertRaises(Exception, os.remove, tmpfile)
|
||||
im.load()
|
||||
self.assertTrue(fp.closed)
|
||||
|
||||
|
|
|
@ -161,7 +161,7 @@ class TestFileTiffMetadata(PillowTestCase):
|
|||
head = f.read(8)
|
||||
info = TiffImagePlugin.ImageFileDirectory(head)
|
||||
try:
|
||||
self.assert_warning(UserWarning, lambda: info.load(f))
|
||||
self.assert_warning(UserWarning, info.load, f)
|
||||
except struct.error:
|
||||
self.fail("Should not be struct errors there.")
|
||||
|
||||
|
|
|
@ -75,7 +75,8 @@ class TestFileWebp(PillowTestCase):
|
|||
def test_write_unsupported_mode(self):
|
||||
temp_file = self.tempfile("temp.webp")
|
||||
|
||||
self.assertRaises(IOError, lambda: hopper("L").save(temp_file))
|
||||
im = hopper("L")
|
||||
self.assertRaises(IOError, im.save, temp_file)
|
||||
|
||||
def test_WebPEncode_with_invalid_args(self):
|
||||
self.assertRaises(TypeError, _webp.WebPEncode)
|
||||
|
|
|
@ -50,7 +50,7 @@ class TestFileWmf(PillowTestCase):
|
|||
|
||||
for ext in [".wmf", ".emf"]:
|
||||
tmpfile = self.tempfile("temp"+ext)
|
||||
self.assertRaises(IOError, lambda: im.save(tmpfile))
|
||||
self.assertRaises(IOError, im.save, tmpfile)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -21,7 +21,7 @@ class TestFileXpm(PillowTestCase):
|
|||
invalid_file = "Tests/images/flower.jpg"
|
||||
|
||||
self.assertRaises(SyntaxError,
|
||||
lambda: XpmImagePlugin.XpmImageFile(invalid_file))
|
||||
XpmImagePlugin.XpmImageFile, invalid_file)
|
||||
|
||||
def test_load_read(self):
|
||||
# Arrange
|
||||
|
|
|
@ -25,8 +25,7 @@ class TestFileXVThumb(PillowTestCase):
|
|||
|
||||
# Act / Assert
|
||||
self.assertRaises(SyntaxError,
|
||||
lambda:
|
||||
XVThumbImagePlugin.XVThumbImageFile(bad_file))
|
||||
XVThumbImagePlugin.XVThumbImageFile, bad_file)
|
||||
|
||||
def test_invalid_file(self):
|
||||
# Arrange
|
||||
|
@ -34,8 +33,7 @@ class TestFileXVThumb(PillowTestCase):
|
|||
|
||||
# Act / Assert
|
||||
self.assertRaises(SyntaxError,
|
||||
lambda:
|
||||
XVThumbImagePlugin.XVThumbImageFile(invalid_file))
|
||||
XVThumbImagePlugin.XVThumbImageFile, invalid_file)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -17,7 +17,7 @@ class TestFontBdf(PillowTestCase):
|
|||
|
||||
def test_invalid_file(self):
|
||||
with open("Tests/images/flower.jpg", "rb") as fp:
|
||||
self.assertRaises(SyntaxError, lambda: BdfFontFile.BdfFontFile(fp))
|
||||
self.assertRaises(SyntaxError, BdfFontFile.BdfFontFile, fp)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -32,7 +32,7 @@ class TestFontPcf(PillowTestCase):
|
|||
|
||||
def test_invalid_file(self):
|
||||
with open("Tests/images/flower.jpg", "rb") as fp:
|
||||
self.assertRaises(SyntaxError, lambda: PcfFontFile.PcfFontFile(fp))
|
||||
self.assertRaises(SyntaxError, PcfFontFile.PcfFontFile, fp)
|
||||
|
||||
def xtest_draw(self):
|
||||
|
||||
|
|
|
@ -47,10 +47,9 @@ class TestImage(PillowTestCase):
|
|||
self.assertEqual(im2.getcolors(), [(10000, 0)])
|
||||
self.assertEqual(im3.getcolors(), [(10000, 0)])
|
||||
|
||||
self.assertRaises(ValueError, lambda: Image.new("X", (100, 100)))
|
||||
self.assertRaises(ValueError, lambda: Image.new("", (100, 100)))
|
||||
# self.assertRaises(
|
||||
# MemoryError, lambda: Image.new("L", (1000000, 1000000)))
|
||||
self.assertRaises(ValueError, Image.new, "X", (100, 100))
|
||||
self.assertRaises(ValueError, Image.new, "", (100, 100))
|
||||
# self.assertRaises(MemoryError, Image.new, "L", (1000000, 1000000))
|
||||
|
||||
def test_width_height(self):
|
||||
im = Image.new("RGB", (1, 2))
|
||||
|
@ -68,10 +67,10 @@ class TestImage(PillowTestCase):
|
|||
else:
|
||||
import io
|
||||
im = io.BytesIO(b'')
|
||||
self.assertRaises(IOError, lambda: Image.open(im))
|
||||
self.assertRaises(IOError, Image.open, im)
|
||||
|
||||
def test_bad_mode(self):
|
||||
self.assertRaises(ValueError, lambda: Image.open("filename", "bad mode"))
|
||||
self.assertRaises(ValueError, Image.open, "filename", "bad mode")
|
||||
|
||||
@unittest.skipIf(sys.version_info < (3, 4),
|
||||
"pathlib only available in Python 3.4 or later")
|
||||
|
@ -112,7 +111,7 @@ class TestImage(PillowTestCase):
|
|||
def test_unknown_extension(self):
|
||||
im = hopper()
|
||||
temp_file = self.tempfile("temp.unknown")
|
||||
self.assertRaises(ValueError, lambda: im.save(temp_file))
|
||||
self.assertRaises(ValueError, im.save, temp_file)
|
||||
|
||||
def test_internals(self):
|
||||
|
||||
|
@ -278,17 +277,17 @@ class TestImage(PillowTestCase):
|
|||
|
||||
# errors
|
||||
self.assertRaises(ValueError,
|
||||
lambda: source.alpha_composite(over, "invalid source"))
|
||||
source.alpha_composite, over, "invalid source")
|
||||
self.assertRaises(ValueError,
|
||||
lambda: source.alpha_composite(over, (0, 0), "invalid destination"))
|
||||
source.alpha_composite, over, (0, 0), "invalid destination")
|
||||
self.assertRaises(ValueError,
|
||||
lambda: source.alpha_composite(over, (0)))
|
||||
source.alpha_composite, over, (0))
|
||||
self.assertRaises(ValueError,
|
||||
lambda: source.alpha_composite(over, (0, 0), (0)))
|
||||
source.alpha_composite, over, (0, 0), (0))
|
||||
self.assertRaises(ValueError,
|
||||
lambda: source.alpha_composite(over, (0, -1)))
|
||||
source.alpha_composite, over, (0, -1))
|
||||
self.assertRaises(ValueError,
|
||||
lambda: source.alpha_composite(over, (0, 0), (0, -1)))
|
||||
source.alpha_composite, over, (0, 0), (0, -1))
|
||||
|
||||
def test_registered_extensions_uninitialized(self):
|
||||
# Arrange
|
||||
|
@ -344,7 +343,7 @@ class TestImage(PillowTestCase):
|
|||
# Act/Assert
|
||||
self.assertRaises(
|
||||
ValueError,
|
||||
lambda: Image.effect_mandelbrot(size, extent, quality))
|
||||
Image.effect_mandelbrot, size, extent, quality)
|
||||
|
||||
def test_effect_noise(self):
|
||||
# Arrange
|
||||
|
@ -405,7 +404,7 @@ class TestImage(PillowTestCase):
|
|||
im = hopper()
|
||||
|
||||
# Act / Assert
|
||||
self.assertRaises(NotImplementedError, lambda: im.offset(None))
|
||||
self.assertRaises(NotImplementedError, im.offset, None)
|
||||
|
||||
def test_fromstring(self):
|
||||
self.assertRaises(NotImplementedError, Image.fromstring)
|
||||
|
@ -416,7 +415,7 @@ class TestImage(PillowTestCase):
|
|||
|
||||
# Act / Assert
|
||||
self.assertRaises(ValueError,
|
||||
lambda: Image.linear_gradient(wrong_mode))
|
||||
Image.linear_gradient, wrong_mode)
|
||||
return
|
||||
|
||||
def test_linear_gradient(self):
|
||||
|
@ -442,7 +441,7 @@ class TestImage(PillowTestCase):
|
|||
|
||||
# Act / Assert
|
||||
self.assertRaises(ValueError,
|
||||
lambda: Image.radial_gradient(wrong_mode))
|
||||
Image.radial_gradient, wrong_mode)
|
||||
return
|
||||
|
||||
def test_radial_gradient(self):
|
||||
|
@ -465,7 +464,7 @@ class TestImage(PillowTestCase):
|
|||
def test_remap_palette(self):
|
||||
# Test illegal image mode
|
||||
im = hopper()
|
||||
self.assertRaises(ValueError, lambda: im.remap_palette(None))
|
||||
self.assertRaises(ValueError, im.remap_palette, None)
|
||||
|
||||
|
||||
class MockEncoder(object):
|
||||
|
@ -491,10 +490,10 @@ class TestRegistry(PillowTestCase):
|
|||
self.assertEqual(enc.args, ('RGB', 'args', 'extra'))
|
||||
|
||||
def test_encode_registry_fail(self):
|
||||
self.assertRaises(IOError, lambda: Image._getencoder('RGB',
|
||||
'DoesNotExist',
|
||||
('args',),
|
||||
extra=('extra',)))
|
||||
self.assertRaises(IOError, Image._getencoder, 'RGB',
|
||||
'DoesNotExist',
|
||||
('args',),
|
||||
extra=('extra',))
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -104,7 +104,7 @@ class TestImageConvert(PillowTestCase):
|
|||
|
||||
p = self.assert_warning(
|
||||
UserWarning,
|
||||
lambda: im.convert('P', palette=Image.ADAPTIVE))
|
||||
im.convert, 'P', palette=Image.ADAPTIVE)
|
||||
self.assertNotIn('transparency', p.info)
|
||||
p.save(f)
|
||||
|
||||
|
@ -124,7 +124,7 @@ class TestImageConvert(PillowTestCase):
|
|||
|
||||
p = self.assert_warning(
|
||||
UserWarning,
|
||||
lambda: im.convert('P', palette=Image.ADAPTIVE))
|
||||
im.convert, 'P', palette=Image.ADAPTIVE)
|
||||
self.assertNotIn('transparency', p.info)
|
||||
p.save(f)
|
||||
|
||||
|
@ -148,7 +148,7 @@ class TestImageConvert(PillowTestCase):
|
|||
|
||||
# Act / Assert
|
||||
self.assertRaises(ValueError,
|
||||
lambda: im.convert(mode='CMYK', matrix=matrix))
|
||||
im.convert, mode='CMYK', matrix=matrix)
|
||||
|
||||
def test_matrix_wrong_mode(self):
|
||||
# Arrange
|
||||
|
@ -161,7 +161,7 @@ class TestImageConvert(PillowTestCase):
|
|||
|
||||
# Act / Assert
|
||||
self.assertRaises(ValueError,
|
||||
lambda: im.convert(mode='L', matrix=matrix))
|
||||
im.convert, mode='L', matrix=matrix)
|
||||
|
||||
def test_matrix_xyz(self):
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ class TestImageFilter(PillowTestCase):
|
|||
filter(ImageFilter.UnsharpMask)
|
||||
filter(ImageFilter.UnsharpMask(10))
|
||||
|
||||
self.assertRaises(TypeError, lambda: filter("hello"))
|
||||
self.assertRaises(TypeError, filter, "hello")
|
||||
|
||||
def test_crash(self):
|
||||
|
||||
|
@ -83,7 +83,7 @@ class TestImageFilter(PillowTestCase):
|
|||
|
||||
self.assertEqual(rankfilter("1"), (0, 4, 8))
|
||||
self.assertEqual(rankfilter("L"), (0, 4, 8))
|
||||
self.assertRaises(ValueError, lambda: rankfilter("P"))
|
||||
self.assertRaises(ValueError, rankfilter, "P")
|
||||
self.assertEqual(rankfilter("RGB"), ((0, 0, 0), (4, 0, 0), (8, 0, 0)))
|
||||
self.assertEqual(rankfilter("I"), (0, 4, 8))
|
||||
self.assertEqual(rankfilter("F"), (0.0, 4.0, 8.0))
|
||||
|
|
|
@ -19,7 +19,7 @@ class TestImageLoad(PillowTestCase):
|
|||
im = Image.open("Tests/images/hopper.gif")
|
||||
im.close()
|
||||
self.assertRaises(ValueError, im.load)
|
||||
self.assertRaises(ValueError, lambda: im.getpixel((0, 0)))
|
||||
self.assertRaises(ValueError, im.getpixel, (0, 0))
|
||||
|
||||
def test_contextmanager(self):
|
||||
fn = None
|
||||
|
@ -27,7 +27,7 @@ class TestImageLoad(PillowTestCase):
|
|||
fn = im.fp.fileno()
|
||||
os.fstat(fn)
|
||||
|
||||
self.assertRaises(OSError, lambda: os.fstat(fn))
|
||||
self.assertRaises(OSError, os.fstat, fn)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -6,17 +6,17 @@ class TestImagePoint(PillowTestCase):
|
|||
def test_sanity(self):
|
||||
im = hopper()
|
||||
|
||||
self.assertRaises(ValueError, lambda: im.point(list(range(256))))
|
||||
self.assertRaises(ValueError, im.point, list(range(256)))
|
||||
im.point(list(range(256))*3)
|
||||
im.point(lambda x: x)
|
||||
|
||||
im = im.convert("I")
|
||||
self.assertRaises(ValueError, lambda: im.point(list(range(256))))
|
||||
self.assertRaises(ValueError, im.point, list(range(256)))
|
||||
im.point(lambda x: x*1)
|
||||
im.point(lambda x: x+1)
|
||||
im.point(lambda x: x*1+1)
|
||||
self.assertRaises(TypeError, lambda: im.point(lambda x: x-1))
|
||||
self.assertRaises(TypeError, lambda: im.point(lambda x: x/1))
|
||||
self.assertRaises(TypeError, im.point, lambda x: x-1)
|
||||
self.assertRaises(TypeError, im.point, lambda x: x/1)
|
||||
|
||||
def test_16bit_lut(self):
|
||||
""" Tests for 16 bit -> 8 bit lut for converting I->L images
|
||||
|
@ -36,7 +36,8 @@ class TestImagePoint(PillowTestCase):
|
|||
self.assert_image_equal(out.convert('L'), im.point(int_lut, 'L'))
|
||||
|
||||
def test_f_mode(self):
|
||||
self.assertRaises(ValueError, lambda: hopper('F').point(None))
|
||||
im = hopper('F')
|
||||
self.assertRaises(ValueError, im.point, None)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -13,14 +13,14 @@ class TestImagePutPalette(PillowTestCase):
|
|||
if p:
|
||||
return im.mode, p[:10]
|
||||
return im.mode
|
||||
self.assertRaises(ValueError, lambda: palette("1"))
|
||||
self.assertRaises(ValueError, palette, "1")
|
||||
self.assertEqual(palette("L"), ("P", [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]))
|
||||
self.assertEqual(palette("P"), ("P", [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]))
|
||||
self.assertRaises(ValueError, lambda: palette("I"))
|
||||
self.assertRaises(ValueError, lambda: palette("F"))
|
||||
self.assertRaises(ValueError, lambda: palette("RGB"))
|
||||
self.assertRaises(ValueError, lambda: palette("RGBA"))
|
||||
self.assertRaises(ValueError, lambda: palette("YCbCr"))
|
||||
self.assertRaises(ValueError, palette, "I")
|
||||
self.assertRaises(ValueError, palette, "F")
|
||||
self.assertRaises(ValueError, palette, "RGB")
|
||||
self.assertRaises(ValueError, palette, "RGBA")
|
||||
self.assertRaises(ValueError, palette, "YCbCr")
|
||||
|
||||
def test_imagepalette(self):
|
||||
im = hopper("P")
|
||||
|
|
|
@ -39,7 +39,7 @@ class TestImageQuantize(PillowTestCase):
|
|||
def test_rgba_quantize(self):
|
||||
image = hopper('RGBA')
|
||||
image.quantize()
|
||||
self.assertRaises(Exception, lambda: image.quantize(method=0))
|
||||
self.assertRaises(Exception, image.quantize, method=0)
|
||||
|
||||
def test_quantize(self):
|
||||
image = Image.open('Tests/images/caption_6_33_22.png').convert('RGB')
|
||||
|
|
|
@ -114,7 +114,7 @@ class TestImageResize(PillowTestCase):
|
|||
|
||||
# Test unknown resampling filter
|
||||
im = hopper()
|
||||
self.assertRaises(ValueError, lambda: im.resize((10, 10), "unknown"))
|
||||
self.assertRaises(ValueError, im.resize, (10, 10), "unknown")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -141,8 +141,8 @@ class TestImageTransform(PillowTestCase):
|
|||
self.test_mesh()
|
||||
|
||||
def test_missing_method_data(self):
|
||||
self.assertRaises(ValueError, lambda:
|
||||
hopper().transform((100, 100), None))
|
||||
im = hopper()
|
||||
self.assertRaises(ValueError, im.transform, (100, 100), None)
|
||||
|
||||
|
||||
class TestImageTransformAffine(PillowTestCase):
|
||||
|
|
|
@ -148,22 +148,22 @@ class TestImageCms(PillowTestCase):
|
|||
psRGB = ImageCms.createProfile("sRGB")
|
||||
pLab = ImageCms.createProfile("LAB")
|
||||
t = ImageCms.buildTransform(pLab, psRGB, "LAB", "RGB")
|
||||
self.assertRaises(ValueError, lambda: t.apply_in_place(hopper("RGBA")))
|
||||
self.assertRaises(ValueError, t.apply_in_place, hopper("RGBA"))
|
||||
|
||||
# the procedural pyCMS API uses PyCMSError for all sorts of errors
|
||||
self.assertRaises(
|
||||
ImageCms.PyCMSError,
|
||||
lambda: ImageCms.profileToProfile(hopper(), "foo", "bar"))
|
||||
ImageCms.profileToProfile, hopper(), "foo", "bar")
|
||||
self.assertRaises(
|
||||
ImageCms.PyCMSError,
|
||||
lambda: ImageCms.buildTransform("foo", "bar", "RGB", "RGB"))
|
||||
ImageCms.buildTransform, "foo", "bar", "RGB", "RGB")
|
||||
self.assertRaises(
|
||||
ImageCms.PyCMSError,
|
||||
lambda: ImageCms.getProfileName(None))
|
||||
ImageCms.getProfileName, None)
|
||||
self.skip_missing()
|
||||
self.assertRaises(
|
||||
ImageCms.PyCMSError,
|
||||
lambda: ImageCms.isIntentSupported(SRGB, None, None))
|
||||
ImageCms.isIntentSupported, SRGB, None, None)
|
||||
|
||||
def test_display_profile(self):
|
||||
# try fetching the profile for the current display device
|
||||
|
@ -175,11 +175,11 @@ class TestImageCms(PillowTestCase):
|
|||
|
||||
def test_unsupported_color_space(self):
|
||||
self.assertRaises(ImageCms.PyCMSError,
|
||||
lambda: ImageCms.createProfile("unsupported"))
|
||||
ImageCms.createProfile, "unsupported")
|
||||
|
||||
def test_invalid_color_temperature(self):
|
||||
self.assertRaises(ImageCms.PyCMSError,
|
||||
lambda: ImageCms.createProfile("LAB", "invalid"))
|
||||
ImageCms.createProfile, "LAB", "invalid")
|
||||
|
||||
def test_simple_lab(self):
|
||||
i = Image.new('RGB', (10, 10), (128, 128, 128))
|
||||
|
|
|
@ -56,8 +56,7 @@ class TestImageDraw(PillowTestCase):
|
|||
def test_mode_mismatch(self):
|
||||
im = hopper("RGB").copy()
|
||||
|
||||
self.assertRaises(ValueError,
|
||||
lambda: ImageDraw.ImageDraw(im, mode="L"))
|
||||
self.assertRaises(ValueError, ImageDraw.ImageDraw, im, mode="L")
|
||||
|
||||
def helper_arc(self, bbox, start, end):
|
||||
# Arrange
|
||||
|
|
|
@ -69,7 +69,7 @@ class TestImageFile(PillowTestCase):
|
|||
im1, im2 = roundtrip("JPEG") # lossy compression
|
||||
self.assert_image(im1, im2.mode, im2.size)
|
||||
|
||||
self.assertRaises(IOError, lambda: roundtrip("PDF"))
|
||||
self.assertRaises(IOError, roundtrip, "PDF")
|
||||
|
||||
def test_ico(self):
|
||||
with open('Tests/images/python.ico', 'rb') as f:
|
||||
|
@ -93,7 +93,7 @@ class TestImageFile(PillowTestCase):
|
|||
self.assert_image_equal(im1, im2)
|
||||
|
||||
def test_raise_ioerror(self):
|
||||
self.assertRaises(IOError, lambda: ImageFile.raise_ioerror(1))
|
||||
self.assertRaises(IOError, ImageFile.raise_ioerror, 1)
|
||||
|
||||
def test_raise_typeerror(self):
|
||||
with self.assertRaises(TypeError):
|
||||
|
@ -182,7 +182,7 @@ class TestPyDecoder(PillowTestCase):
|
|||
self.assertEqual(d.state.xsize, xsize)
|
||||
self.assertEqual(d.state.ysize, ysize)
|
||||
|
||||
self.assertRaises(ValueError, lambda: d.set_as_raw(b'\x00'))
|
||||
self.assertRaises(ValueError, d.set_as_raw, b'\x00')
|
||||
|
||||
def test_extents_none(self):
|
||||
buf = BytesIO(b'\x00'*255)
|
||||
|
|
|
@ -106,7 +106,7 @@ class TestImageFont(PillowTestCase):
|
|||
# Usage note: making two fonts from the same buffer fails.
|
||||
# shared_bytes = self._font_as_bytes()
|
||||
# self._render(shared_bytes)
|
||||
# self.assertRaises(Exception, lambda: _render(shared_bytes))
|
||||
# self.assertRaises(Exception, _render, shared_bytes)
|
||||
|
||||
def test_font_with_open_file(self):
|
||||
with open(FONT_PATH, 'rb') as f:
|
||||
|
@ -211,9 +211,9 @@ class TestImageFont(PillowTestCase):
|
|||
|
||||
# Act/Assert
|
||||
self.assertRaises(AssertionError,
|
||||
lambda: draw.multiline_text((0, 0), TEST_TEXT,
|
||||
font=ttf,
|
||||
align="unknown"))
|
||||
draw.multiline_text, (0, 0), TEST_TEXT,
|
||||
font=ttf,
|
||||
align="unknown")
|
||||
|
||||
def test_draw_align(self):
|
||||
im = Image.new('RGB', (300, 100), 'white')
|
||||
|
@ -384,7 +384,7 @@ class TestImageFont(PillowTestCase):
|
|||
filename = "somefilenamethatdoesntexist.ttf"
|
||||
|
||||
# Act/Assert
|
||||
self.assertRaises(IOError, lambda: ImageFont.load_path(filename))
|
||||
self.assertRaises(IOError, ImageFont.load_path, filename)
|
||||
|
||||
def test_default_font(self):
|
||||
# Arrange
|
||||
|
|
|
@ -81,9 +81,9 @@ class MorphTests(PillowTestCase):
|
|||
|
||||
def test_no_operator_loaded(self):
|
||||
mop = ImageMorph.MorphOp()
|
||||
self.assertRaises(Exception, lambda: mop.apply(None))
|
||||
self.assertRaises(Exception, lambda: mop.match(None))
|
||||
self.assertRaises(Exception, lambda: mop.save_lut(None))
|
||||
self.assertRaises(Exception, mop.apply, None)
|
||||
self.assertRaises(Exception, mop.match, None)
|
||||
self.assertRaises(Exception, mop.save_lut, None)
|
||||
|
||||
# Test the named patterns
|
||||
def test_erosion8(self):
|
||||
|
@ -214,9 +214,9 @@ class MorphTests(PillowTestCase):
|
|||
im = hopper('RGB')
|
||||
mop = ImageMorph.MorphOp(op_name="erosion8")
|
||||
|
||||
self.assertRaises(Exception, lambda: mop.apply(im))
|
||||
self.assertRaises(Exception, lambda: mop.match(im))
|
||||
self.assertRaises(Exception, lambda: mop.get_on_pixels(im))
|
||||
self.assertRaises(Exception, mop.apply, im)
|
||||
self.assertRaises(Exception, mop.match, im)
|
||||
self.assertRaises(Exception, mop.get_on_pixels, im)
|
||||
|
||||
def test_add_patterns(self):
|
||||
# Arrange
|
||||
|
@ -240,7 +240,7 @@ class MorphTests(PillowTestCase):
|
|||
def test_unknown_pattern(self):
|
||||
self.assertRaises(
|
||||
Exception,
|
||||
lambda: ImageMorph.LutBuilder(op_name='unknown'))
|
||||
ImageMorph.LutBuilder, op_name='unknown')
|
||||
|
||||
def test_pattern_syntax_error(self):
|
||||
# Arrange
|
||||
|
@ -249,9 +249,7 @@ class MorphTests(PillowTestCase):
|
|||
lb.add_patterns(new_patterns)
|
||||
|
||||
# Act / Assert
|
||||
self.assertRaises(
|
||||
Exception,
|
||||
lambda: lb.build_lut())
|
||||
self.assertRaises(Exception, lb.build_lut)
|
||||
|
||||
def test_load_invalid_mrl(self):
|
||||
# Arrange
|
||||
|
@ -259,7 +257,7 @@ class MorphTests(PillowTestCase):
|
|||
mop = ImageMorph.MorphOp()
|
||||
|
||||
# Act / Assert
|
||||
self.assertRaises(Exception, lambda: mop.load_lut(invalid_mrl))
|
||||
self.assertRaises(Exception, mop.load_lut, invalid_mrl)
|
||||
|
||||
def test_roundtrip_mrl(self):
|
||||
# Arrange
|
||||
|
|
|
@ -37,26 +37,26 @@ class TestImageOpsUsm(PillowTestCase):
|
|||
def test_usm_formats(self):
|
||||
|
||||
usm = ImageOps.unsharp_mask
|
||||
self.assertRaises(ValueError, lambda: usm(im.convert("1")))
|
||||
self.assertRaises(ValueError, usm, im.convert("1"))
|
||||
usm(im.convert("L"))
|
||||
self.assertRaises(ValueError, lambda: usm(im.convert("I")))
|
||||
self.assertRaises(ValueError, lambda: usm(im.convert("F")))
|
||||
self.assertRaises(ValueError, usm, im.convert("I"))
|
||||
self.assertRaises(ValueError, usm, im.convert("F"))
|
||||
usm(im.convert("RGB"))
|
||||
usm(im.convert("RGBA"))
|
||||
usm(im.convert("CMYK"))
|
||||
self.assertRaises(ValueError, lambda: usm(im.convert("YCbCr")))
|
||||
self.assertRaises(ValueError, usm, im.convert("YCbCr"))
|
||||
|
||||
def test_blur_formats(self):
|
||||
|
||||
blur = ImageOps.gaussian_blur
|
||||
self.assertRaises(ValueError, lambda: blur(im.convert("1")))
|
||||
self.assertRaises(ValueError, blur, im.convert("1"))
|
||||
blur(im.convert("L"))
|
||||
self.assertRaises(ValueError, lambda: blur(im.convert("I")))
|
||||
self.assertRaises(ValueError, lambda: blur(im.convert("F")))
|
||||
self.assertRaises(ValueError, blur, im.convert("I"))
|
||||
self.assertRaises(ValueError, blur, im.convert("F"))
|
||||
blur(im.convert("RGB"))
|
||||
blur(im.convert("RGBA"))
|
||||
blur(im.convert("CMYK"))
|
||||
self.assertRaises(ValueError, lambda: blur(im.convert("YCbCr")))
|
||||
self.assertRaises(ValueError, blur, im.convert("YCbCr"))
|
||||
|
||||
def test_usm_accuracy(self):
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ class TestImagePalette(PillowTestCase):
|
|||
|
||||
ImagePalette.ImagePalette("RGB", list(range(256))*3)
|
||||
self.assertRaises(ValueError,
|
||||
lambda: ImagePalette.ImagePalette("RGB", list(range(256))*2))
|
||||
ImagePalette.ImagePalette, "RGB", list(range(256))*2)
|
||||
|
||||
def test_getcolor(self):
|
||||
|
||||
|
@ -20,10 +20,10 @@ class TestImagePalette(PillowTestCase):
|
|||
test_map[palette.getcolor((i, i, i))] = i
|
||||
|
||||
self.assertEqual(len(test_map), 256)
|
||||
self.assertRaises(ValueError, lambda: palette.getcolor((1, 2, 3)))
|
||||
self.assertRaises(ValueError, palette.getcolor, (1, 2, 3))
|
||||
|
||||
# Test unknown color specifier
|
||||
self.assertRaises(ValueError, lambda: palette.getcolor("unknown"))
|
||||
self.assertRaises(ValueError, palette.getcolor, "unknown")
|
||||
|
||||
def test_file(self):
|
||||
|
||||
|
@ -65,9 +65,8 @@ class TestImagePalette(PillowTestCase):
|
|||
white = 255
|
||||
|
||||
# Act
|
||||
self.assertRaises(
|
||||
NotImplementedError,
|
||||
lambda: ImagePalette.make_linear_lut(black, white))
|
||||
self.assertRaises(NotImplementedError,
|
||||
ImagePalette.make_linear_lut, black, white)
|
||||
|
||||
def test_make_gamma_lut(self):
|
||||
# Arrange
|
||||
|
@ -92,9 +91,9 @@ class TestImagePalette(PillowTestCase):
|
|||
|
||||
# Act / Assert
|
||||
self.assertRaises(ValueError, palette.tobytes)
|
||||
self.assertRaises(ValueError, lambda: palette.getcolor((1, 2, 3)))
|
||||
self.assertRaises(ValueError, palette.getcolor, (1, 2, 3))
|
||||
f = self.tempfile("temp.lut")
|
||||
self.assertRaises(ValueError, lambda: palette.save(f))
|
||||
self.assertRaises(ValueError, palette.save, f)
|
||||
|
||||
def test_getdata(self):
|
||||
# Arrange
|
||||
|
@ -134,7 +133,7 @@ class TestImagePalette(PillowTestCase):
|
|||
|
||||
def test_invalid_palette(self):
|
||||
self.assertRaises(IOError,
|
||||
lambda: ImagePalette.load("Tests/images/hopper.jpg"))
|
||||
ImagePalette.load, "Tests/images/hopper.jpg")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -22,7 +22,7 @@ class TestImageSequence(PillowTestCase):
|
|||
|
||||
self.assertEqual(index, 1)
|
||||
|
||||
self.assertRaises(AttributeError, lambda: ImageSequence.Iterator(0))
|
||||
self.assertRaises(AttributeError, ImageSequence.Iterator, 0)
|
||||
|
||||
def test_iterator(self):
|
||||
im = Image.open('Tests/images/multipage.tiff')
|
||||
|
@ -30,7 +30,7 @@ class TestImageSequence(PillowTestCase):
|
|||
for index in range(0, im.n_frames):
|
||||
self.assertEqual(i[index], next(i))
|
||||
self.assertRaises(IndexError, lambda: i[index+1])
|
||||
self.assertRaises(StopIteration, lambda: next(i))
|
||||
self.assertRaises(StopIteration, next, i)
|
||||
|
||||
def _test_multipage_tiff(self):
|
||||
im = Image.open('Tests/images/multipage.tiff')
|
||||
|
|
|
@ -33,7 +33,7 @@ class TestImageShow(PillowTestCase):
|
|||
|
||||
self.assertIsNone(viewer.get_format(None))
|
||||
|
||||
self.assertRaises(NotImplementedError, lambda: viewer.get_command(None))
|
||||
self.assertRaises(NotImplementedError, viewer.get_command, None)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -26,7 +26,7 @@ class TestImageStat(PillowTestCase):
|
|||
|
||||
self.assertRaises(AttributeError, lambda: st.spam)
|
||||
|
||||
self.assertRaises(TypeError, lambda: ImageStat.Stat(1))
|
||||
self.assertRaises(TypeError, ImageStat.Stat, 1)
|
||||
|
||||
def test_hopper(self):
|
||||
|
||||
|
|
|
@ -29,8 +29,8 @@ class TestLibImage(PillowTestCase):
|
|||
im.im.setmode("RGB")
|
||||
self.assertEqual(im.im.getpixel((0, 0)), (1, 2, 3))
|
||||
|
||||
self.assertRaises(ValueError, lambda: im.im.setmode("L"))
|
||||
self.assertRaises(ValueError, lambda: im.im.setmode("RGBABCDE"))
|
||||
self.assertRaises(ValueError, im.im.setmode, "L")
|
||||
self.assertRaises(ValueError, im.im.setmode, "RGBABCDE")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -60,7 +60,7 @@ class TestNumpy(PillowTestCase):
|
|||
# Check supported 1-bit integer formats
|
||||
self.assert_image(to_image(numpy.bool, 1, 1), '1', TEST_IMAGE_SIZE)
|
||||
self.assert_image(to_image(numpy.bool8, 1, 1), '1', TEST_IMAGE_SIZE)
|
||||
|
||||
|
||||
# Check supported 8-bit integer formats
|
||||
self.assert_image(to_image(numpy.uint8), "L", TEST_IMAGE_SIZE)
|
||||
self.assert_image(to_image(numpy.uint8, 3), "RGB", TEST_IMAGE_SIZE)
|
||||
|
@ -86,12 +86,12 @@ class TestNumpy(PillowTestCase):
|
|||
self.assert_image(to_image(numpy.int32), "I", TEST_IMAGE_SIZE)
|
||||
|
||||
# Check 64-bit integer formats
|
||||
self.assertRaises(TypeError, lambda: to_image(numpy.uint64))
|
||||
self.assertRaises(TypeError, lambda: to_image(numpy.int64))
|
||||
self.assertRaises(TypeError, to_image, numpy.uint64)
|
||||
self.assertRaises(TypeError, to_image, numpy.int64)
|
||||
|
||||
# Check floating-point formats
|
||||
self.assert_image(to_image(numpy.float), "F", TEST_IMAGE_SIZE)
|
||||
self.assertRaises(TypeError, lambda: to_image(numpy.float16))
|
||||
self.assertRaises(TypeError, to_image, numpy.float16)
|
||||
self.assert_image(to_image(numpy.float32), "F", TEST_IMAGE_SIZE)
|
||||
self.assert_image(to_image(numpy.float64), "F", TEST_IMAGE_SIZE)
|
||||
|
||||
|
@ -216,7 +216,7 @@ class TestNumpy(PillowTestCase):
|
|||
def test_bool(self):
|
||||
# https://github.com/python-pillow/Pillow/issues/2044
|
||||
a = numpy.zeros((10,2), dtype=numpy.bool)
|
||||
a[0][0] = True
|
||||
a[0][0] = True
|
||||
|
||||
im2 = Image.fromarray(a)
|
||||
self.assertEqual(im2.getdata()[0], 255)
|
||||
|
|
Loading…
Reference in New Issue
Block a user