diff --git a/glue/main.py b/glue/main.py index 0637c6d5e..a428be40c 100644 --- a/glue/main.py +++ b/glue/main.py @@ -59,7 +59,6 @@ def load_plugins(splash=None, require_qt_plugins=False, plugins_to_load=None): n_plugins = len(plugins_to_require) for i_plugin, item in enumerate(list(iter_plugin_entry_points())): - if item.module in plugins_to_load: if item.module not in _installed_plugins: _installed_plugins.add(item.name) @@ -115,3 +114,20 @@ def load_plugins(splash=None, require_qt_plugins=False, plugins_to_load=None): # that were previously read. from glue._settings_helpers import load_settings load_settings() + + +def list_loaded_plugins(): + """ + Function to list all plugins that are currently loaded + """ + return sorted(_loaded_plugins) + + +def list_available_plugins(): + """ + Function to list all available plugins + """ + from glue._plugin_helpers import iter_plugin_entry_points + + plugins_load_list = [i.module for i in list(iter_plugin_entry_points())] + return plugins_load_list diff --git a/glue/tests/test_main.py b/glue/tests/test_main.py index 10b35bd86..6c961d28d 100644 --- a/glue/tests/test_main.py +++ b/glue/tests/test_main.py @@ -1,6 +1,25 @@ from unittest.mock import patch -from glue.main import load_plugins +from glue.main import load_plugins, list_loaded_plugins, list_available_plugins +from glue._plugin_helpers import REQUIRED_PLUGINS + + +def test_load_plugins(capsys): + """ + Test customisable list of plugins load + """ + from glue.logger import logger + + with patch.object(logger, 'info') as info: + load_plugins() + + # plugins = [call[0][0] for call in info.call_args_list if ('succeeded' or 'loaded') in call[0][0]] + plugins = [] + for acall in info.call_args_list: + if ('loaded' or 'succeeded') in acall[0][0]: + plugins.append(acall[0][0].split(' ')[1]) + + assert 'coordinate_helpers' in plugins def test_no_duplicate_loading(capsys): @@ -15,6 +34,35 @@ def test_no_duplicate_loading(capsys): with patch.object(logger, 'info') as info: load_plugins() + plugins = [] for acall in info.call_args_list: + plugins.append(acall[0][0]) if 'Loading plugin' in acall[0][0]: assert 'failed' in acall[0][0] + + loaded_plugins = list_loaded_plugins() + assert 'glue.plugins.wcs_autolinking' in loaded_plugins + assert 'glue.core.data_exporters' in loaded_plugins + assert 'glue.plugins.coordinate_helpers' in loaded_plugins + + +def test_list_loaded_plugins(): + """ + Unit test for retrieving the list of currently loaded plugins + """ + load_plugins(require_qt_plugins=False) + plugins = list_loaded_plugins() + assert isinstance(plugins, list) + for test_plugin in REQUIRED_PLUGINS: + assert test_plugin in plugins + + +def test_list_available_plugins(): + """ + Unit test for retrieving the list of currently available plugins + """ + available_plugins = list_available_plugins() + assert isinstance(available_plugins, list) + assert 'glue.plugins.wcs_autolinking' in available_plugins + assert 'glue.core.data_exporters' in available_plugins + assert 'glue.plugins.coordinate_helpers' in available_plugins