Skip to content

Commit

Permalink
Various Flake8 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Jul 3, 2015
1 parent a06b59b commit 309ab1f
Show file tree
Hide file tree
Showing 38 changed files with 144 additions and 53 deletions.
3 changes: 2 additions & 1 deletion Tests/check_imaging_leaks.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ def _test_leak(self, min_iterations, max_iterations, fn, *args, **kwargs):

def test_leak_putdata(self):
im = Image.new('RGB', (25, 25))
self._test_leak(min_iterations, max_iterations, im.putdata, im.getdata())
self._test_leak(min_iterations, max_iterations,
im.putdata, im.getdata())

def test_leak_getlist(self):
im = Image.new('P', (25, 25))
Expand Down
3 changes: 2 additions & 1 deletion Tests/check_png_dos.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ def test_dos_total_memory(self):
total_len = 0
for txt in im2.text.values():
total_len += len(txt)
self.assertLess(total_len, 64*1024*1024, "Total text chunks greater than 64M")
self.assertLess(total_len, 64*1024*1024,
"Total text chunks greater than 64M")

if __name__ == '__main__':
unittest.main()
2 changes: 1 addition & 1 deletion Tests/test_cffi.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def test_get_vs_c(self):
self._test_get_access(hopper('LA'))
self._test_get_access(hopper('1'))
self._test_get_access(hopper('P'))
# self._test_get_access(hopper('PA')) # PA -- how do I make a PA image?
# self._test_get_access(hopper('PA')) # PA -- how do I make a PA image?
self._test_get_access(hopper('F'))

im = Image.new('I;16', (10, 10), 40000)
Expand Down
3 changes: 2 additions & 1 deletion Tests/test_file_bmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def test_sanity(self):

def test_invalid_file(self):
with open("Tests/images/flower.jpg", "rb") as fp:
self.assertRaises(SyntaxError, lambda: BmpImagePlugin.BmpImageFile(fp))
self.assertRaises(SyntaxError,
lambda: BmpImagePlugin.BmpImageFile(fp))

def test_save_to_bytes(self):
output = io.BytesIO()
Expand Down
6 changes: 5 additions & 1 deletion Tests/test_file_bufrstub.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
class TestFileBufrStub(PillowTestCase):

def test_invalid_file(self):
self.assertRaises(SyntaxError, lambda: BufrStubImagePlugin.BufrStubImageFile("Tests/images/flower.jpg"))
invalid_file = "Tests/images/flower.jpg"

self.assertRaises(SyntaxError,
lambda:
BufrStubImagePlugin.BufrStubImageFile(invalid_file))


if __name__ == '__main__':
Expand Down
5 changes: 4 additions & 1 deletion Tests/test_file_cur.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ def test_sanity(self):
self.assertEqual(im.getpixel((16, 16)), (84, 87, 86, 255))

def test_invalid_file(self):
self.assertRaises(SyntaxError, lambda: CurImagePlugin.CurImageFile("Tests/images/flower.jpg"))
invalid_file = "Tests/images/flower.jpg"

self.assertRaises(SyntaxError,
lambda: CurImagePlugin.CurImageFile(invalid_file))


if __name__ == '__main__':
Expand Down
3 changes: 2 additions & 1 deletion Tests/test_file_dcx.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ def test_sanity(self):

def test_invalid_file(self):
with open("Tests/images/flower.jpg", "rb") as fp:
self.assertRaises(SyntaxError, lambda: DcxImagePlugin.DcxImageFile(fp))
self.assertRaises(SyntaxError,
lambda: DcxImagePlugin.DcxImageFile(fp))

def test_tell(self):
# Arrange
Expand Down
9 changes: 7 additions & 2 deletions Tests/test_file_eps.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ def test_sanity(self):
self.assertEqual(image2_scale2.format, "EPS")

def test_invalid_file(self):
self.assertRaises(SyntaxError, lambda: EpsImagePlugin.EpsImageFile("Tests/images/flower.jpg"))
invalid_file = "Tests/images/flower.jpg"

self.assertRaises(SyntaxError,
lambda: EpsImagePlugin.EpsImageFile(invalid_file))

def test_file_object(self):
# issue 479
Expand Down Expand Up @@ -152,7 +155,9 @@ def test_read_binary_preview(self):
Image.open(file3)

def _test_readline(self, t, ending):
ending = "Failure with line ending: %s" % ("".join("%s" % ord(s) for s in ending))
ending = "Failure with line ending: %s" % ("".join(
"%s" % ord(s)
for s in ending))
self.assertEqual(t.readline().strip('\r\n'), 'something', ending)
self.assertEqual(t.readline().strip('\r\n'), 'else', ending)
self.assertEqual(t.readline().strip('\r\n'), 'baz', ending)
Expand Down
6 changes: 5 additions & 1 deletion Tests/test_file_fitsstub.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
class TestFileFitsStub(PillowTestCase):

def test_invalid_file(self):
self.assertRaises(SyntaxError, lambda: FitsStubImagePlugin.FITSStubImageFile("Tests/images/flower.jpg"))
invalid_file = "Tests/images/flower.jpg"

self.assertRaises(SyntaxError,
lambda:
FitsStubImagePlugin.FITSStubImageFile(invalid_file))


if __name__ == '__main__':
Expand Down
5 changes: 4 additions & 1 deletion Tests/test_file_fli.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ def test_sanity(self):
self.assertEqual(im.format, "FLI")

def test_invalid_file(self):
self.assertRaises(SyntaxError, lambda: FliImagePlugin.FliImageFile("Tests/images/flower.jpg"))
invalid_file = "Tests/images/flower.jpg"

self.assertRaises(SyntaxError,
lambda: FliImagePlugin.FliImageFile(invalid_file))

def test_n_frames(self):
im = Image.open(test_file)
Expand Down
5 changes: 4 additions & 1 deletion Tests/test_file_fpx.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
class TestFileFpx(PillowTestCase):

def test_invalid_file(self):
self.assertRaises(SyntaxError, lambda: FpxImagePlugin.FpxImageFile("Tests/images/flower.jpg"))
invalid_file = "Tests/images/flower.jpg"

self.assertRaises(SyntaxError,
lambda: FpxImagePlugin.FpxImageFile(invalid_file))


if __name__ == '__main__':
Expand Down
5 changes: 4 additions & 1 deletion Tests/test_file_gbr.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
class TestFileGbr(PillowTestCase):

def test_invalid_file(self):
self.assertRaises(SyntaxError, lambda: GbrImagePlugin.GbrImageFile("Tests/images/flower.jpg"))
invalid_file = "Tests/images/flower.jpg"

self.assertRaises(SyntaxError,
lambda: GbrImagePlugin.GbrImageFile(invalid_file))


if __name__ == '__main__':
Expand Down
5 changes: 4 additions & 1 deletion Tests/test_file_gif.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ def test_sanity(self):
self.assertEqual(im.format, "GIF")

def test_invalid_file(self):
self.assertRaises(SyntaxError, lambda: GifImagePlugin.GifImageFile("Tests/images/flower.jpg"))
invalid_file = "Tests/images/flower.jpg"

self.assertRaises(SyntaxError,
lambda: GifImagePlugin.GifImageFile(invalid_file))

def test_optimize(self):
from io import BytesIO
Expand Down
6 changes: 5 additions & 1 deletion Tests/test_file_gribstub.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
class TestFileGribStub(PillowTestCase):

def test_invalid_file(self):
self.assertRaises(SyntaxError, lambda: GribStubImagePlugin.GribStubImageFile("Tests/images/flower.jpg"))
invalid_file = "Tests/images/flower.jpg"

self.assertRaises(SyntaxError,
lambda:
GribStubImagePlugin.GribStubImageFile(invalid_file))


if __name__ == '__main__':
Expand Down
6 changes: 5 additions & 1 deletion Tests/test_file_hdf5stub.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
class TestFileHdf5Stub(PillowTestCase):

def test_invalid_file(self):
self.assertRaises(SyntaxError, lambda: Hdf5StubImagePlugin.HDF5StubImageFile("Tests/images/flower.jpg"))
test_file = "Tests/images/flower.jpg"

self.assertRaises(SyntaxError,
lambda:
Hdf5StubImagePlugin.HDF5StubImageFile(test_file))


if __name__ == '__main__':
Expand Down
9 changes: 6 additions & 3 deletions Tests/test_file_ico.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ def test_sanity(self):

def test_invalid_file(self):
with open("Tests/images/flower.jpg", "rb") as fp:
self.assertRaises(SyntaxError, lambda: IcoImagePlugin.IcoImageFile(fp))
self.assertRaises(SyntaxError,
lambda: IcoImagePlugin.IcoImageFile(fp))

def test_save_to_bytes(self):
output = io.BytesIO()
Expand All @@ -34,7 +35,8 @@ def test_save_to_bytes(self):
self.assertEqual(im.mode, reloaded.mode)
self.assertEqual((64, 64), reloaded.size)
self.assertEqual(reloaded.format, "ICO")
self.assert_image_equal(reloaded, hopper().resize((64, 64), Image.LANCZOS))
self.assert_image_equal(reloaded,
hopper().resize((64, 64), Image.LANCZOS))

# the other one
output.seek(0)
Expand All @@ -44,7 +46,8 @@ def test_save_to_bytes(self):
self.assertEqual(im.mode, reloaded.mode)
self.assertEqual((32, 32), reloaded.size)
self.assertEqual(reloaded.format, "ICO")
self.assert_image_equal(reloaded, hopper().resize((32, 32), Image.LANCZOS))
self.assert_image_equal(reloaded,
hopper().resize((32, 32), Image.LANCZOS))


if __name__ == '__main__':
Expand Down
5 changes: 4 additions & 1 deletion Tests/test_file_im.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ def test_roundtrip(self):
self.assert_image_equal(reread, im)

def test_invalid_file(self):
self.assertRaises(SyntaxError, lambda: ImImagePlugin.ImImageFile("Tests/images/flower.jpg"))
invalid_file = "Tests/images/flower.jpg"

self.assertRaises(SyntaxError,
lambda: ImImagePlugin.ImImageFile(invalid_file))


if __name__ == '__main__':
Expand Down
17 changes: 10 additions & 7 deletions Tests/test_file_jpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,22 +291,24 @@ def test_qtables(self):

# dict of qtable lists
self.assert_image_similar(im,
self.roundtrip(im,
qtables={0: standard_l_qtable,
1: standard_chrominance_qtable}),
30)
self.roundtrip(im, qtables={
0: standard_l_qtable,
1: standard_chrominance_qtable
}), 30)

# not a sequence
self.assertRaises(Exception, lambda: self.roundtrip(im, qtables='a'))
# sequence wrong length
self.assertRaises(Exception, lambda: self.roundtrip(im, qtables=[]))
# sequence wrong length
self.assertRaises(Exception, lambda: self.roundtrip(im, qtables=[1, 2, 3, 4, 5]))
self.assertRaises(Exception,
lambda: self.roundtrip(im, qtables=[1, 2, 3, 4, 5]))

# qtable entry not a sequence
self.assertRaises(Exception, lambda: 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.assertRaises(Exception,
lambda: self.roundtrip(im, qtables=[[1, 2, 3, 4]]))

@unittest.skipUnless(djpeg_available(), "djpeg not available")
def test_load_djpeg(self):
Expand Down Expand Up @@ -337,7 +339,8 @@ def gen_random_image(size):
""" Generates a very hard to compress file
:param size: tuple
"""
return Image.frombytes('RGB', size, os.urandom(size[0]*size[1] * 3))
return Image.frombytes('RGB',
size, os.urandom(size[0]*size[1] * 3))

im = gen_random_image((512, 512))
f = self.tempfile("temp.jpeg")
Expand Down
6 changes: 5 additions & 1 deletion Tests/test_file_jpeg2k.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ def test_sanity(self):
self.assertEqual(im.format, 'JPEG2000')

def test_invalid_file(self):
self.assertRaises(SyntaxError, lambda: Jpeg2KImagePlugin.Jpeg2KImageFile("Tests/images/flower.jpg"))
invalid_file = "Tests/images/flower.jpg"

self.assertRaises(SyntaxError,
lambda:
Jpeg2KImagePlugin.Jpeg2KImageFile(invalid_file))

def test_bytesio(self):
with open('Tests/images/test-card-lossless.jp2', 'rb') as f:
Expand Down
6 changes: 5 additions & 1 deletion Tests/test_file_mcidas.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
class TestFileMcIdas(PillowTestCase):

def test_invalid_file(self):
self.assertRaises(SyntaxError, lambda: McIdasImagePlugin.McIdasImageFile("Tests/images/flower.jpg"))
invalid_file = "Tests/images/flower.jpg"

self.assertRaises(SyntaxError,
lambda:
McIdasImagePlugin.McIdasImageFile(invalid_file))


if __name__ == '__main__':
Expand Down
5 changes: 4 additions & 1 deletion Tests/test_file_mic.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
class TestFileMic(PillowTestCase):

def test_invalid_file(self):
self.assertRaises(SyntaxError, lambda: MicImagePlugin.MicImageFile("Tests/images/flower.jpg"))
invalid_file = "Tests/images/flower.jpg"

self.assertRaises(SyntaxError,
lambda: MicImagePlugin.MicImageFile(invalid_file))


if __name__ == '__main__':
Expand Down
5 changes: 4 additions & 1 deletion Tests/test_file_msp.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ def test_sanity(self):
self.assertEqual(im.format, "MSP")

def test_invalid_file(self):
self.assertRaises(SyntaxError, lambda: MspImagePlugin.MspImageFile("Tests/images/flower.jpg"))
invalid_file = "Tests/images/flower.jpg"

self.assertRaises(SyntaxError,
lambda: MspImagePlugin.MspImageFile(invalid_file))

def test_open(self):
# Arrange
Expand Down
5 changes: 4 additions & 1 deletion Tests/test_file_pcx.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ def test_sanity(self):
self._roundtrip(hopper(mode))

def test_invalid_file(self):
self.assertRaises(SyntaxError, lambda: PcxImagePlugin.PcxImageFile("Tests/images/flower.jpg"))
invalid_file = "Tests/images/flower.jpg"

self.assertRaises(SyntaxError,
lambda: PcxImagePlugin.PcxImageFile(invalid_file))

def test_odd(self):
# see issue #523, odd sized images should have a stride that's even.
Expand Down
5 changes: 4 additions & 1 deletion Tests/test_file_png.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ def test_sanity(self):
im = Image.open(test_file)

def test_invalid_file(self):
self.assertRaises(SyntaxError, lambda: PngImagePlugin.PngImageFile("Tests/images/flower.jpg"))
invalid_file = "Tests/images/flower.jpg"

self.assertRaises(SyntaxError,
lambda: PngImagePlugin.PngImageFile(invalid_file))

def test_broken(self):
# Check reading of totally broken files. In this case, the test
Expand Down
5 changes: 4 additions & 1 deletion Tests/test_file_psd.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ def test_sanity(self):
self.assertEqual(im.format, "PSD")

def test_invalid_file(self):
self.assertRaises(SyntaxError, lambda: PsdImagePlugin.PsdImageFile("Tests/images/flower.jpg"))
invalid_file = "Tests/images/flower.jpg"

self.assertRaises(SyntaxError,
lambda: PsdImagePlugin.PsdImageFile(invalid_file))

def test_n_frames(self):
im = Image.open("Tests/images/hopper_merged.psd")
Expand Down
6 changes: 5 additions & 1 deletion Tests/test_file_sgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ def test_rgba(self):
self.assertRaises(ValueError, lambda: Image.open(test_file))

def test_invalid_file(self):
self.assertRaises(ValueError, lambda: SgiImagePlugin.SgiImageFile("Tests/images/flower.jpg"))
invalid_file = "Tests/images/flower.jpg"

self.assertRaises(ValueError,
lambda:
SgiImagePlugin.SgiImageFile(invalid_file))


if __name__ == '__main__':
Expand Down
4 changes: 3 additions & 1 deletion Tests/test_file_sun.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ def test_sanity(self):
# Assert
self.assertEqual(im.size, (128, 128))

self.assertRaises(SyntaxError, lambda: SunImagePlugin.SunImageFile("Tests/images/flower.jpg"))
invalid_file = "Tests/images/flower.jpg"
self.assertRaises(SyntaxError,
lambda: SunImagePlugin.SunImageFile(invalid_file))


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion Tests/test_file_tga.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_save(self):
im.convert("RGBA").save(test_file)
test_im = Image.open(test_file)
self.assertEqual(test_im.size, (100, 100))

# Unsupported mode save
self.assertRaises(IOError, lambda: im.convert("LA").save(test_file))

Expand Down
3 changes: 2 additions & 1 deletion Tests/test_file_tiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ def test_bad_exif(self):
try:
Image.open('Tests/images/hopper_bad_exif.jpg')._getexif()
except struct.error:
self.fail("Bad EXIF data should not pass incorrect values to _binary unpack")
self.fail(
"Bad EXIF data passed incorrect values to _binary unpack")

def test_little_endian(self):
im = Image.open('Tests/images/16bit.cropped.tif')
Expand Down
Loading

0 comments on commit 309ab1f

Please sign in to comment.