mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-05 01:08:41 +08:00
Merge pull request #1214 from blink1073/remove-null-plugin
Remove null_plugin in Favor of the pil_plugin
This commit is contained in:
@@ -1,3 +0,0 @@
|
||||
[null]
|
||||
description = Default plugin that does nothing
|
||||
provides = imshow, imread, imsave, _app_show
|
||||
@@ -1,25 +0,0 @@
|
||||
__all__ = ['imshow', 'imread', 'imsave', '_app_show']
|
||||
|
||||
import warnings
|
||||
|
||||
message = '''\
|
||||
No plugin has been loaded. Please refer to the docstring for ``skimage.io``
|
||||
for a list of available plugins. You may specify a plugin explicitly as
|
||||
an argument to ``imread``, e.g. ``imread("image.jpg", plugin='pil')``.
|
||||
|
||||
'''
|
||||
|
||||
|
||||
def imshow(*args, **kwargs):
|
||||
warnings.warn(RuntimeWarning(message))
|
||||
|
||||
|
||||
def imread(*args, **kwargs):
|
||||
warnings.warn(RuntimeWarning(message))
|
||||
|
||||
|
||||
def imsave(*args, **kwargs):
|
||||
warnings.warn(RuntimeWarning(message))
|
||||
|
||||
|
||||
_app_show = imshow
|
||||
@@ -1,20 +1,12 @@
|
||||
__all__ = ['imread', 'imsave']
|
||||
|
||||
import numpy as np
|
||||
|
||||
try:
|
||||
from PIL import Image
|
||||
except ImportError:
|
||||
raise ImportError("The Python Image Library could not be found. "
|
||||
"Please refer to "
|
||||
"https://pypi.python.org/pypi/Pillow/ (or "
|
||||
"http://pypi.python.org/pypi/PIL/) "
|
||||
"for further instructions.")
|
||||
from six import string_types
|
||||
from PIL import Image
|
||||
|
||||
from skimage.util import img_as_ubyte, img_as_uint
|
||||
|
||||
from six import string_types
|
||||
from skimage.external.tifffile import imread as tif_imread, imsave as tif_imsave
|
||||
from skimage.external.tifffile import (
|
||||
imread as tif_imread, imsave as tif_imsave)
|
||||
|
||||
|
||||
def imread(fname, dtype=None):
|
||||
|
||||
@@ -44,7 +44,8 @@ plugin_meta_data = {}
|
||||
# the following preferences.
|
||||
preferred_plugins = {
|
||||
# Default plugins for all types (overridden by specific types below).
|
||||
'all': ['pil', 'matplotlib', 'qt', 'freeimage', 'null']
|
||||
'all': ['pil', 'matplotlib', 'qt', 'freeimage'],
|
||||
'imshow': ['matplotlib']
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
import os
|
||||
import warnings
|
||||
from contextlib import contextmanager
|
||||
|
||||
import numpy as np
|
||||
from numpy.testing import raises
|
||||
|
||||
from skimage import io
|
||||
from skimage import data_dir
|
||||
|
||||
|
||||
@contextmanager
|
||||
def warnings_as_errors():
|
||||
# Temporarily set warnings as errors so we can test the warning is raised.
|
||||
with warnings.catch_warnings():
|
||||
warnings.filterwarnings('error')
|
||||
yield
|
||||
|
||||
@raises(Warning)
|
||||
def test_null_imread():
|
||||
path = os.path.join(data_dir, 'color.png')
|
||||
with warnings_as_errors():
|
||||
io.imread(path, plugin='null')
|
||||
|
||||
|
||||
@raises(Warning)
|
||||
def test_null_imsave():
|
||||
with warnings_as_errors():
|
||||
io.imsave('dummy.png', np.zeros((3, 3)), plugin='null')
|
||||
|
||||
|
||||
@raises(Warning)
|
||||
def test_null_imshow():
|
||||
with warnings_as_errors():
|
||||
io.imshow(np.zeros((3, 3)), plugin='null')
|
||||
|
||||
|
||||
@raises(Warning)
|
||||
def test_null_imread_collection():
|
||||
# Note that the null plugin doesn't define an `imread_collection` plugin
|
||||
# but this function is dynamically added by the plugin manager.
|
||||
path = os.path.join(data_dir, '*.png')
|
||||
with warnings_as_errors():
|
||||
collection = io.imread_collection(path, plugin='null')
|
||||
collection[0]
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from numpy.testing import run_module_suite
|
||||
run_module_suite()
|
||||
@@ -4,21 +4,10 @@ from numpy.testing import assert_equal, raises
|
||||
|
||||
from skimage import io
|
||||
from skimage.io import manage_plugins
|
||||
from numpy.testing.decorators import skipif
|
||||
|
||||
try:
|
||||
io.use_plugin('pil')
|
||||
PIL_available = True
|
||||
priority_plugin = 'pil'
|
||||
except ImportError:
|
||||
PIL_available = False
|
||||
|
||||
try:
|
||||
io.use_plugin('freeimage')
|
||||
FI_available = True
|
||||
priority_plugin = 'freeimage'
|
||||
except RuntimeError:
|
||||
FI_available = False
|
||||
io.use_plugin('pil')
|
||||
priority_plugin = 'pil'
|
||||
|
||||
|
||||
def setup_module():
|
||||
@@ -65,7 +54,6 @@ def test_failed_use():
|
||||
manage_plugins.use_plugin('asd')
|
||||
|
||||
|
||||
@skipif(not PIL_available and not FI_available)
|
||||
def test_use_priority():
|
||||
manage_plugins.use_plugin(priority_plugin)
|
||||
plug, func = manage_plugins.plugin_store['imread'][0]
|
||||
@@ -76,7 +64,6 @@ def test_use_priority():
|
||||
assert_equal(plug, 'test')
|
||||
|
||||
|
||||
@skipif(not PIL_available)
|
||||
def test_use_priority_with_func():
|
||||
manage_plugins.use_plugin('pil')
|
||||
plug, func = manage_plugins.plugin_store['imread'][0]
|
||||
@@ -106,28 +93,28 @@ def test_available():
|
||||
|
||||
|
||||
def test_load_preferred_plugins_all():
|
||||
from skimage.io._plugins import null_plugin
|
||||
from skimage.io._plugins import pil_plugin
|
||||
|
||||
with protect_preferred_plugins():
|
||||
manage_plugins.preferred_plugins = {'all': ['null']}
|
||||
manage_plugins.preferred_plugins = {'all': ['pil']}
|
||||
manage_plugins.reset_plugins()
|
||||
|
||||
for plugin_type in ('imread', 'imsave', 'imshow'):
|
||||
plug, func = manage_plugins.plugin_store[plugin_type][0]
|
||||
assert func == getattr(null_plugin, plugin_type)
|
||||
assert func == getattr(pil_plugin, plugin_type)
|
||||
|
||||
|
||||
def test_load_preferred_plugins_imread():
|
||||
from skimage.io._plugins import null_plugin
|
||||
from skimage.io._plugins import pil_plugin, matplotlib_plugin
|
||||
|
||||
with protect_preferred_plugins():
|
||||
manage_plugins.preferred_plugins['imread'] = ['null']
|
||||
manage_plugins.preferred_plugins['imread'] = ['pil']
|
||||
manage_plugins.reset_plugins()
|
||||
|
||||
plug, func = manage_plugins.plugin_store['imread'][0]
|
||||
assert func == null_plugin.imread
|
||||
assert func == pil_plugin.imread
|
||||
plug, func = manage_plugins.plugin_store['imshow'][0]
|
||||
assert func != null_plugin.imshow
|
||||
assert func == matplotlib_plugin.imshow, func.__module__
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user