Skip to content

Commit

Permalink
Merge pull request #3392 from hugovk/update-tests
Browse files Browse the repository at this point in the history
Update tests
  • Loading branch information
hugovk committed Nov 11, 2018
2 parents f542697 + 5df41b4 commit 302f862
Show file tree
Hide file tree
Showing 24 changed files with 60 additions and 67 deletions.
2 changes: 1 addition & 1 deletion Tests/check_large_memory.py
Expand Up @@ -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):
Expand Down
9 changes: 4 additions & 5 deletions Tests/helper.py
Expand Up @@ -110,7 +110,7 @@ def assert_image_equal(self, a, b, msg=None):
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")
Expand Down Expand Up @@ -163,7 +163,6 @@ def assert_image_similar_tofile(self, a, filename, epsilon, msg=None,
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")
Expand All @@ -175,7 +174,7 @@ def assert_warning(self, warn_class, func, *args, **kwargs):
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
Expand All @@ -187,10 +186,10 @@ def assert_warning(self, warn_class, func, *args, **kwargs):
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"""
Expand Down
12 changes: 6 additions & 6 deletions Tests/test_000_sanity.py
Expand Up @@ -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')

Expand All @@ -19,11 +19,11 @@ def test_sanity(self):
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__':
Expand Down
2 changes: 2 additions & 0 deletions Tests/test_color_lut.py
Expand Up @@ -294,6 +294,8 @@ def test_convert_table(self):

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):
Expand Down
2 changes: 1 addition & 1 deletion Tests/test_features.py
Expand Up @@ -5,7 +5,7 @@
try:
from PIL import _webp
HAVE_WEBP = True
except:
except ImportError:
HAVE_WEBP = False


Expand Down
6 changes: 2 additions & 4 deletions Tests/test_file_eps.py
Expand Up @@ -228,12 +228,10 @@ def test_open_eps(self):
"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")
self.assertEqual(img.mode, "RGB")

def test_emptyline(self):
# Test file includes an empty line in the header data
Expand Down
4 changes: 2 additions & 2 deletions Tests/test_file_ico.py
Expand Up @@ -28,7 +28,7 @@ def test_save_to_bytes(self):
# 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)
Expand Down Expand Up @@ -81,7 +81,7 @@ def test_only_save_relevant_sizes(self):
# 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__':
Expand Down
6 changes: 3 additions & 3 deletions Tests/test_file_libtiff.py
Expand Up @@ -415,7 +415,7 @@ def test_multipage_nframes(self):
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()
Expand Down Expand Up @@ -545,11 +545,11 @@ def test_fd_duplication(self):
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)

Expand Down
10 changes: 5 additions & 5 deletions Tests/test_file_png.py
Expand Up @@ -82,19 +82,19 @@ def test_sanity(self):
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"
Expand Down
10 changes: 5 additions & 5 deletions Tests/test_file_tiff.py
Expand Up @@ -26,19 +26,19 @@ def test_sanity(self):
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]
Expand Down
4 changes: 2 additions & 2 deletions Tests/test_file_tiff_metadata.py
Expand Up @@ -136,8 +136,8 @@ def test_write_metadata(self):
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']
Expand Down
9 changes: 2 additions & 7 deletions Tests/test_file_webp_alpha.py
Expand Up @@ -5,18 +5,13 @@
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")
Expand Down
2 changes: 1 addition & 1 deletion Tests/test_file_webp_lossless.py
Expand Up @@ -16,7 +16,7 @@ def setUp(self):
self.skipTest('WebP support not installed')
return

if (_webp.WebPDecoderVersion() < 0x0200):
if _webp.WebPDecoderVersion() < 0x0200:
self.skipTest('lossless not included')

self.rgb_mode = "RGB"
Expand Down
8 changes: 4 additions & 4 deletions Tests/test_image.py
Expand Up @@ -56,7 +56,7 @@ def test_width_height(self):
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):
Expand Down Expand Up @@ -286,9 +286,9 @@ def test_alpha_inplace(self):
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,
Expand Down Expand Up @@ -516,7 +516,7 @@ def _make_new(base_image, im, palette_result=None):
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)
Expand Down
2 changes: 1 addition & 1 deletion Tests/test_image_convert.py
Expand Up @@ -88,7 +88,7 @@ def test_trns_p_rgba(self):
# 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')
Expand Down
2 changes: 1 addition & 1 deletion Tests/test_image_getdata.py
Expand Up @@ -23,7 +23,7 @@ def getdata(mode):
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))
Expand Down
2 changes: 1 addition & 1 deletion Tests/test_image_getextrema.py
Expand Up @@ -19,7 +19,7 @@ def extrema(mode):
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):
Expand Down
6 changes: 3 additions & 3 deletions Tests/test_image_resample.py
Expand Up @@ -196,7 +196,7 @@ def test_enlarge_lanczos(self):
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
Expand Down Expand Up @@ -453,7 +453,7 @@ def test_subsample(self):

# 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):
Expand Down Expand Up @@ -496,7 +496,7 @@ def test_no_passthrough(self):
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:
Expand Down
4 changes: 2 additions & 2 deletions Tests/test_imagedraw.py
Expand Up @@ -46,7 +46,7 @@ def test_valueerror(self):
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()
Expand Down Expand Up @@ -543,7 +543,7 @@ def create_base_image_draw(self, size,
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'))
Expand Down
6 changes: 3 additions & 3 deletions Tests/test_imagefile.py
Expand Up @@ -144,7 +144,7 @@ def test_broken_datastream_without_errors(self):
class MockPyDecoder(ImageFile.PyDecoder):
def decode(self, buffer):
# eof
return (-1, 0)
return -1, 0


xoff, yoff, xsize, ysize = 10, 20, 100, 100
Expand Down Expand Up @@ -204,7 +204,7 @@ def test_negsize(self):

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)

Expand All @@ -218,7 +218,7 @@ def test_oversize(self):
im.tile = [
("MOCK", (xoff, yoff, xoff+xsize + 100, yoff+ysize), 32, None)
]
d = self.get_decoder()
self.get_decoder()

self.assertRaises(ValueError, im.load)

Expand Down
7 changes: 3 additions & 4 deletions Tests/test_imagetk.py
Expand Up @@ -11,23 +11,22 @@
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):
Expand Down

0 comments on commit 302f862

Please sign in to comment.