From 4ea0ff711810aa55c778841c9a9a73909090b3ee Mon Sep 17 00:00:00 2001 From: Roman Inflianskas Date: Sun, 14 Sep 2014 14:41:42 +0400 Subject: [PATCH] refactoring: extract common from lena and hopper --- Tests/helper.py | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/Tests/helper.py b/Tests/helper.py index 637e77f9c..1fc7fd0fe 100644 --- a/Tests/helper.py +++ b/Tests/helper.py @@ -180,8 +180,9 @@ def tostring(im, format, **options): return out.getvalue() -def hopper(mode="RGB", cache={}): +def test_image(filename, mode="RGB", cache={}): from PIL import Image + from os import path im = None # FIXME: Implement caching to reduce reading from disk but so an original # copy is returned each time and the cached image isn't modified by tests @@ -189,35 +190,23 @@ def hopper(mode="RGB", cache={}): # im = cache.get(mode) if im is None: if mode == "RGB": - im = Image.open("Tests/images/hopper.ppm") + im = Image.open(path.join("Tests/images", filename)) elif mode == "F": - im = lena("L").convert(mode) + im = test_image(filename, "L").convert(mode) elif mode[:4] == "I;16": - im = lena("I").convert(mode) + im = test_image(filename, "I").convert(mode) else: - im = lena("RGB").convert(mode) + im = test_image(filename, "RGB").convert(mode) # cache[mode] = im return im +def hopper(mode="RGB", cache={}): + return test_image("hopper.ppm", mode, cache) + + def lena(mode="RGB", cache={}): - from PIL import Image - im = None - # FIXME: Implement 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/lena.ppm") - elif mode == "F": - im = lena("L").convert(mode) - elif mode[:4] == "I;16": - im = lena("I").convert(mode) - else: - im = lena("RGB").convert(mode) - # cache[mode] = im - return im + return test_image("lena.ppm", mode, cache) def command_succeeds(cmd):