def test_initialise(): with tempdir.tempdir(changeto=False) as td1, \ tempdir.tempdir(changeto=False) as td2: with open(op.join(td1, 'plugin1.py'), 'wt') as f: f.write(code.format(prefix='Plugin1')) with open(op.join(td2, 'plugin2.py'), 'wt') as f: f.write(code.format(prefix='Plugin2')) with mock.patch.dict( 'os.environ', {'FSLEYES_PLUGIN_PATH' : op.pathsep.join((td1, td2))}): plugins.initialise() assert 'fsleyes-plugin-plugin1' in plugins.listPlugins() assert 'fsleyes-plugin-plugin2' in plugins.listPlugins() p1 = sys.modules['fsleyes_plugin_plugin1'] p2 = sys.modules['fsleyes_plugin_plugin2'] views = plugins.listViews() ctrls = plugins.listControls() tools = plugins.listTools() assert views['Plugin1View'] is p1.Plugin1View assert views['Plugin2View'] is p2.Plugin2View assert ctrls['Plugin1Control'] is p1.Plugin1Control assert ctrls['Plugin2Control'] is p2.Plugin2Control assert tools['Plugin1Tool'] is p1.Plugin1Tool assert tools['Plugin2Tool'] is p2.Plugin2Tool
def test_loadPlugin(): with tempdir.tempdir(changeto=False) as td: with open(op.join(td, 'test_loadplugin.py'), 'wt') as f: f.write(code.format(prefix='Load')) plugins.loadPlugin(op.join(td, 'test_loadplugin.py')) mod = sys.modules['fsleyes_plugin_test_loadplugin'] assert 'fsleyes-plugin-test-loadplugin' in plugins.listPlugins() assert plugins.listTools()[ 'LoadTool'] is mod.LoadTool assert plugins.listControls()['LoadControl'] is mod.LoadControl assert plugins.listViews()[ 'LoadView'] is mod.LoadView
def test_installPlugin(): with tempdir.tempdir() as td: with open('test_installplugin.py', 'wt') as f: f.write(code.format(prefix='Install')) s = fslsettings.Settings('test_plugins', cfgdir=td, writeOnExit=False) with fslsettings.use(s): plugins.installPlugin('test_installplugin.py') mod = sys.modules['fsleyes_plugin_test_installplugin'] assert 'fsleyes-plugin-test-installplugin' in plugins.listPlugins() assert plugins.listTools()[ 'InstallTool'] is mod.InstallTool assert plugins.listControls()['InstallControl'] is mod.InstallControl assert plugins.listViews()[ 'InstallView'] is mod.InstallView assert op.exists(op.join(td, 'plugins', 'test_installplugin.py'))
def _test_LoadPluginAction(frame, overlayList, displayCtx): act = loadplugin.LoadPluginAction(overlayList, displayCtx, frame) class FileDialog(object): ShowModal_return = wx.ID_OK GetPath_return = '' def __init__(self, *args, **kwargs): pass def ShowModal(self): return FileDialog.ShowModal_return def GetPath(self): return FileDialog.GetPath_return class MessageDialog(object): ShowModal_return = wx.ID_OK def __init__(self, *args, **kwargs): pass def ShowModal(self): return MessageDialog.ShowModal_return @contextlib.contextmanager def reportIfError(*a, **kwa): try: yield except Exception: pass with mock.patch('wx.FileDialog', FileDialog), \ mock.patch('wx.MessageDialog', MessageDialog), \ mock.patch('fsleyes_widgets.utils.status.reportIfError', reportIfError): FileDialog.ShowModal_return = wx.ID_CANCEL act() FileDialog.ShowModal_return = wx.ID_OK FileDialog.GetPath_return = 'bad path' MessageDialog.ShowModal_return = wx.ID_CANCEL act() FileDialog.ShowModal_return = wx.ID_OK FileDialog.GetPath_return = 'bad path' MessageDialog.ShowModal_return = wx.ID_NO act() FileDialog.ShowModal_return = wx.ID_OK FileDialog.GetPath_return = 'bad path' MessageDialog.ShowModal_return = wx.ID_YES act() FileDialog.ShowModal_return = wx.ID_OK FileDialog.GetPath_return = 'bad path' MessageDialog.ShowModal_return = wx.ID_YES act() with tempdir.tempdir(changeto=False) as td, \ fslsettings.use(fslsettings.Settings(cfgdir=td)): with open(op.join(td, 'test_loadpluginaction.py'), 'wt') as f: f.write(code) FileDialog.GetPath_return = op.join(td, 'test_loadpluginaction.py') act() assert 'fsleyes-plugin-test-loadpluginaction' in plugins.listPlugins( )
def test_listPlugins(): for plugin in ['fsleyes-plugin-bad-example', 'fsleyes-plugin-example']: assert plugin in plugins.listPlugins()