From a86e032a1844c96c38d6c906d2726cef09373687 Mon Sep 17 00:00:00 2001 From: homm Date: Wed, 19 Nov 2014 03:41:44 +0300 Subject: [PATCH] return fresh image is no mode specified and cached version otherwise --- Tests/helper.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/Tests/helper.py b/Tests/helper.py index c7d947414..c33660fe6 100644 --- a/Tests/helper.py +++ b/Tests/helper.py @@ -182,23 +182,25 @@ def tostring(im, format, **options): return out.getvalue() -def hopper(mode="RGB", cache={}): +def hopper(mode=None, cache={}): from PIL import Image - im = None - # Use caching to reduce reading from disk but so an original copy is + if mode is None: + # Always return fresh not-yet-loaded version of image. + # Operations on not-yet-loaded images is separate class of errors + # what we should catch. + return Image.open("Tests/images/hopper.ppm") + # Use caching to reduce reading from disk but so an original copy is # returned each time and the cached image isn't modified by tests # (for fast, isolated, repeatable tests). im = cache.get(mode) if im is None: - if mode == "RGB": - im = Image.open("Tests/images/hopper.ppm") - elif mode == "F": + if mode == "F": im = hopper("L").convert(mode) elif mode[:4] == "I;16": im = hopper("I").convert(mode) else: - im = hopper("RGB").convert(mode) - cache[mode] = im + im = hopper().convert(mode) + cache[mode] = im return im.copy()