Add hopper() to eventually replace lena()

This commit is contained in:
Hugo 2014-09-04 08:03:55 +03:00
parent c3d3789da7
commit 5dd4d6d941
2 changed files with 26 additions and 6 deletions

View File

@ -180,6 +180,26 @@ def tostring(im, format, **options):
return out.getvalue() return out.getvalue()
def hopper(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/hopper.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
def lena(mode="RGB", cache={}): def lena(mode="RGB", cache={}):
from PIL import Image from PIL import Image
im = None im = None

View File

@ -1,4 +1,4 @@
from helper import unittest, PillowTestCase, lena from helper import unittest, PillowTestCase, hopper
from PIL import Image from PIL import Image
import sys import sys
@ -58,7 +58,7 @@ class TestImage(PillowTestCase):
def test_expand_x(self): def test_expand_x(self):
# Arrange # Arrange
im = lena() im = hopper()
orig_size = im.size orig_size = im.size
xmargin = 5 xmargin = 5
@ -71,7 +71,7 @@ class TestImage(PillowTestCase):
def test_expand_xy(self): def test_expand_xy(self):
# Arrange # Arrange
im = lena() im = hopper()
orig_size = im.size orig_size = im.size
xmargin = 5 xmargin = 5
ymargin = 3 ymargin = 3
@ -85,7 +85,7 @@ class TestImage(PillowTestCase):
def test_getbands(self): def test_getbands(self):
# Arrange # Arrange
im = lena() im = hopper()
# Act # Act
bands = im.getbands() bands = im.getbands()
@ -95,7 +95,7 @@ class TestImage(PillowTestCase):
def test_getbbox(self): def test_getbbox(self):
# Arrange # Arrange
im = lena() im = hopper()
# Act # Act
bbox = im.getbbox() bbox = im.getbbox()
@ -185,7 +185,7 @@ class TestImage(PillowTestCase):
def test_effect_spread(self): def test_effect_spread(self):
# Arrange # Arrange
im = lena() im = hopper()
distance = 10 distance = 10
# Act # Act