mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-04 16:31:50 +08:00
BUG: Import PIL.Image correctly. Skip tests if not available.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user