Exemplo n.º 1
0
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
Exemplo n.º 2
0
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
Exemplo n.º 3
0
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'))
Exemplo n.º 4
0
def test_listTools():
    from fsleyes_plugin_example.plugin import PluginTool

    tools = dict(plugins.listTools())

    assert tools['Plugin tool'] is PluginTool