Describe plugins using .ini files, so that we don't need to import them to know their capabilities.

This commit is contained in:
Stefan van der Walt
2009-11-03 00:09:31 +02:00
parent 0f2474a9b9
commit 447397dfa3
13 changed files with 176 additions and 165 deletions
+22 -32
View File
@@ -5,55 +5,45 @@ from scikits.image.io._plugins import plugin
from copy import deepcopy
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)
def show_other(arr):
return "other"
def setup_module(self):
self.backup_plugin_store = deepcopy(plugin.plugin_store)
plugin.register('testcase', read=read, save=save, show=show)
plugin.register('other', show=show_other)
plugin.load('test')
def teardown_module(self):
plugin.plugin_store = self.backup_plugin_store
class TestPlugin:
def test_read(self):
io.imread('test.png', as_grey=True, dtype='i4', plugin='testcase')
io.imread('test.png', as_grey=True, dtype='i4', plugin='test')
def test_save(self):
io.imsave('test.png', [1, 2, 3], plugin='testcase')
io.imsave('test.png', [1, 2, 3], plugin='test')
def test_show(self):
io.imshow([1, 2, 3], plugin_arg=(1, 2), plugin='testcase')
io.imshow([1, 2, 3], plugin_arg=(1, 2), plugin='test')
def test_use(self):
plugin.use('other', 'show')
assert io.imshow(None) == 'other'
plugin.use('test')
@raises(RuntimeError)
def test_failed_use(self):
plugin.use('asd')
def test_use_priority(self):
plugin.use('pil')
plug, func = plugin.plugin_store['imread'][0]
print plugin.plugin_store
assert_equal(plug, 'pil')
plugin.use('test')
plug, func = plugin.plugin_store['imread'][0]
print plugin.plugin_store
assert_equal(plug, 'test')
def test_available(self):
plugin.use('other', 'show')
d = plugin.available('show')
assert d['show'][0] == 'other'
def test_load(self):
plugin.load('test')
fname, arr = io.imsave('outfile', [1, 2, 3])
assert_equal(fname, 'outfile')
assert_equal(arr, [1, 2, 3])
assert_equal(plugin.available('save')['save'][0], 'test')
assert 'qt' in io.plugins()
assert 'test' in io.plugins(loaded=True)
if __name__ == "__main__":
run_module_suite()