mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-12 07:29:48 +08:00
Add tests for IO plugins.
This commit is contained in:
@@ -3,7 +3,8 @@
|
||||
import pil_plugin
|
||||
import matplotlib_plugin
|
||||
|
||||
from io import *
|
||||
from plugin import register as register_plugin
|
||||
from sift import *
|
||||
from collection import *
|
||||
|
||||
from io import *
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
__all__ = ['imread', 'imsave', 'imshow']
|
||||
|
||||
from scikits.image.io.plugin import plugin_store
|
||||
|
||||
def _call_plugin(kind, *args, **kwargs):
|
||||
@@ -20,6 +22,7 @@ def _call_plugin(kind, *args, **kwargs):
|
||||
|
||||
return func(*args, **kwargs)
|
||||
|
||||
|
||||
def imread(fname, as_grey=False, dtype=None, plugin=None, flatten=None,
|
||||
**plugin_args):
|
||||
"""Load an image from file.
|
||||
@@ -62,7 +65,8 @@ def imread(fname, as_grey=False, dtype=None, plugin=None, flatten=None,
|
||||
if flatten is not None:
|
||||
as_grey = flatten
|
||||
|
||||
_call_plugin('read', as_grey, dtype, plugin=plugin, **plugin_args)
|
||||
return _call_plugin('read', fname, as_grey=as_grey, dtype=dtype,
|
||||
plugin=plugin, **plugin_args)
|
||||
|
||||
def imsave(fname, arr, plugin=None, **plugin_args):
|
||||
"""Save an image to file.
|
||||
@@ -84,7 +88,7 @@ def imsave(fname, arr, plugin=None, **plugin_args):
|
||||
Passed to the given plugin.
|
||||
|
||||
"""
|
||||
_call_plugin('save', fname, arr, plugin=plugin, **plugin_args)
|
||||
return _call_plugin('save', fname, arr, plugin=plugin, **plugin_args)
|
||||
|
||||
def imshow(arr, plugin=None, **plugin_args):
|
||||
"""Display an image.
|
||||
@@ -104,4 +108,4 @@ def imshow(arr, plugin=None, **plugin_args):
|
||||
Passed to the given plugin.
|
||||
|
||||
"""
|
||||
_call_plugin('show', arr, plugin=None, **plugin_args)
|
||||
return _call_plugin('show', arr, plugin=plugin, **plugin_args)
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
from numpy.testing import *
|
||||
|
||||
from scikits.image import io
|
||||
from scikits.image.io import plugin
|
||||
|
||||
from copy import copy
|
||||
|
||||
def read(fname, as_grey=False, dtype=None):
|
||||
assert fname == 'test.png'
|
||||
assert as_grey == True
|
||||
assert dtype == 'i4'
|
||||
|
||||
def save(fname, arr):
|
||||
assert fname == 'test.png'
|
||||
assert arr == [1, 2, 3]
|
||||
|
||||
def show(arr, plugin_arg=None):
|
||||
assert arr == [1, 2, 3]
|
||||
assert plugin_arg == (1, 2)
|
||||
|
||||
class TestPlugin:
|
||||
def setup(self):
|
||||
self.backup_plugin_store = copy(plugin.plugin_store)
|
||||
plugin.register('test', read=read, save=save, show=show)
|
||||
|
||||
def test_read(self):
|
||||
io.imread('test.png', as_grey=True, dtype='i4', plugin='test')
|
||||
|
||||
def test_save(self):
|
||||
io.imsave('test.png', [1, 2, 3], plugin='test')
|
||||
|
||||
def test_show(self):
|
||||
io.imshow([1, 2, 3], plugin_arg=(1, 2), plugin='test')
|
||||
|
||||
def teardown(self):
|
||||
plugin.plugin_store = self.backup_plugin_store
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run_module_suite()
|
||||
Reference in New Issue
Block a user