BUG: Import PIL.Image correctly. Skip tests if not available.

This commit is contained in:
Stefan van der Walt
2011-04-11 08:53:26 +02:00
parent 924451f48b
commit 8d74f9cc5f
2 changed files with 15 additions and 0 deletions
+3
View File
@@ -40,6 +40,8 @@ class MultiImage(object):
The last accessed frame is cached, all other frames will have to be read
from file.
The current implementation makes use of PIL.
Examples
--------
>>> from scikits.image import data_dir
@@ -92,6 +94,7 @@ class MultiImage(object):
def _getframe(self, framenum):
"""Open the image and extract the frame."""
from PIL import Image
img = Image.open(self.filename)
img.seek(framenum)
return np.asarray(img, dtype=self._dtype)
+12
View File
@@ -3,11 +3,19 @@ import os.path
import numpy as np
from numpy.testing import *
from numpy.testing.decorators import skipif
from scikits.image import data_dir
from scikits.image.io import ImageCollection, MultiImage
try:
from PIL import Image
except ImportError:
PIL_available = False
else:
PIL_available = True
if sys.version_info[0] > 2:
basestring = str
@@ -58,9 +66,11 @@ class TestMultiImage():
# convert im1.tif im2.tif -adjoin multipage.tif
self.img = MultiImage(os.path.join(data_dir, 'multipage.tif'))
@skipif(not PIL_available)
def test_len(self):
assert len(self.img) == 2
@skipif(not PIL_available)
def test_getitem(self):
num = len(self.img)
for i in range(-num, num):
@@ -74,6 +84,7 @@ class TestMultiImage():
assert_raises(IndexError, return_img, num)
assert_raises(IndexError, return_img, -num-1)
@skipif(not PIL_available)
def test_files_property(self):
assert isinstance(self.img.filename, basestring)
@@ -81,6 +92,7 @@ class TestMultiImage():
self.img.filename = f
assert_raises(AttributeError, set_filename, 'newfile')
@skipif(not PIL_available)
def test_conserve_memory_property(self):
assert isinstance(self.img.conserve_memory, bool)