Ensure PIL tests run with PIL.

This commit is contained in:
Stefan van der Walt
2013-06-29 11:01:18 -05:00
parent 6cef8727a0
commit f429b5abad
2 changed files with 20 additions and 17 deletions
+1 -17
View File
@@ -1,8 +1,7 @@
import os
from numpy.testing import *
from numpy.testing import assert_array_equal, raises, run_module_suite
import numpy as np
from StringIO import StringIO
import skimage.io as io
from skimage import data_dir
@@ -29,20 +28,5 @@ def test_imread_url():
assert image.shape == (512, 512)
def test_imsave_filelike():
shape = (2, 2)
image = np.zeros(shape)
s = StringIO()
# save to file-like object
io.imsave(s, image)
# read from file-like object
s.seek(0)
out = io.imread(s)
assert out.shape == shape
np.testing.assert_allclose(out, image)
if __name__ == "__main__":
run_module_suite()
+19
View File
@@ -7,6 +7,8 @@ from tempfile import NamedTemporaryFile
from skimage import data_dir
from skimage.io import imread, imsave, use_plugin, reset_plugins
from skimage._shared.six.moves import StringIO
try:
from PIL import Image
@@ -124,5 +126,22 @@ class TestSave:
x = (x * 255).astype(dtype)
yield self.roundtrip, dtype, x
@skipif(not PIL_available)
def test_imsave_filelike():
shape = (2, 2)
image = np.zeros(shape)
s = StringIO()
# save to file-like object
imsave(s, image)
# read from file-like object
s.seek(0)
out = imread(s)
assert out.shape == shape
assert_allclose(out, image)
if __name__ == "__main__":
run_module_suite()