mirror of
https://github.com/wassname/scikit-image.git
synced 2026-08-11 11:25:30 +08:00
Ensure PIL tests run with PIL.
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user