From cf6c4be9166ca5c11a25a42fc016b2b4a6b92d09 Mon Sep 17 00:00:00 2001 From: CyclingNinja Date: Thu, 23 May 2024 13:49:03 +0100 Subject: [PATCH 1/6] Add list plugins method and tests --- glue/main.py | 9 +++++++-- glue/tests/test_main.py | 25 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/glue/main.py b/glue/main.py index 0637c6d5e..0b228b1ce 100644 --- a/glue/main.py +++ b/glue/main.py @@ -59,8 +59,7 @@ 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 in plugins_to_require: if item.module not in _installed_plugins: _installed_plugins.add(item.name) @@ -115,3 +114,9 @@ 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_plugins(): + """ + Function to list all plugins that are currently loaded + """ + return sorted(_loaded_plugins) \ No newline at end of file diff --git a/glue/tests/test_main.py b/glue/tests/test_main.py index 10b35bd86..961416a8d 100644 --- a/glue/tests/test_main.py +++ b/glue/tests/test_main.py @@ -1,6 +1,21 @@ from unittest.mock import patch from glue.main import load_plugins +from glue.main import list_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() + + plugin = [call[0][0] for call in info.call_args_list] + assert False + def test_no_duplicate_loading(capsys): @@ -18,3 +33,13 @@ def test_no_duplicate_loading(capsys): for acall in info.call_args_list: if 'Loading plugin' in acall[0][0]: assert 'failed' in acall[0][0] + + +def test_list_plugins(): + """ + Regression test for retrieving the list of currently loaded plugins + """ + load_plugins(require_qt_plugins=False) + plugins = list_plugins() + assert isinstance(plugins, list) + assert len(plugins) == 14 From a9beefbeaa1fd8a0145bbd9362611aaa884c91fa Mon Sep 17 00:00:00 2001 From: CyclingNinja Date: Fri, 24 May 2024 15:11:47 +0100 Subject: [PATCH 2/6] Codestyle modifications --- glue/main.py | 3 ++- glue/tests/test_main.py | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/glue/main.py b/glue/main.py index 0b228b1ce..63fa2b279 100644 --- a/glue/main.py +++ b/glue/main.py @@ -115,8 +115,9 @@ def load_plugins(splash=None, require_qt_plugins=False, plugins_to_load=None): from glue._settings_helpers import load_settings load_settings() + def list_plugins(): """ Function to list all plugins that are currently loaded """ - return sorted(_loaded_plugins) \ No newline at end of file + return sorted(_loaded_plugins) diff --git a/glue/tests/test_main.py b/glue/tests/test_main.py index 961416a8d..4744005e4 100644 --- a/glue/tests/test_main.py +++ b/glue/tests/test_main.py @@ -17,7 +17,6 @@ def test_load_plugins(capsys): assert False - def test_no_duplicate_loading(capsys): """ Regression test for duplicated loading of plugins From 8589681ac620de1def593ac0cc5d050bde666e6f Mon Sep 17 00:00:00 2001 From: CyclingNinja Date: Thu, 30 May 2024 10:01:50 +0100 Subject: [PATCH 3/6] Test adjustments --- glue/main.py | 2 +- glue/tests/test_main.py | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/glue/main.py b/glue/main.py index 63fa2b279..d32aca234 100644 --- a/glue/main.py +++ b/glue/main.py @@ -59,7 +59,7 @@ 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_require: + if item.module in plugins_to_load: if item.module not in _installed_plugins: _installed_plugins.add(item.name) diff --git a/glue/tests/test_main.py b/glue/tests/test_main.py index 4744005e4..7d4c83744 100644 --- a/glue/tests/test_main.py +++ b/glue/tests/test_main.py @@ -13,8 +13,13 @@ def test_load_plugins(capsys): with patch.object(logger, 'info') as info: load_plugins() - plugin = [call[0][0] for call in info.call_args_list] - assert False + # 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]) + + assert len(plugins) == 5 def test_no_duplicate_loading(capsys): @@ -41,4 +46,4 @@ def test_list_plugins(): load_plugins(require_qt_plugins=False) plugins = list_plugins() assert isinstance(plugins, list) - assert len(plugins) == 14 + assert len(plugins) == 5 From fcc2f54fefe1e60363dd813da53c6b3f5d39a70c Mon Sep 17 00:00:00 2001 From: CyclingNinja Date: Mon, 3 Jun 2024 15:56:46 +0100 Subject: [PATCH 4/6] adding available plugins function and test --- glue/main.py | 18 ++++++++++++++---- glue/tests/test_main.py | 21 ++++++++++++++++----- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/glue/main.py b/glue/main.py index d32aca234..353cd7342 100644 --- a/glue/main.py +++ b/glue/main.py @@ -3,7 +3,7 @@ from importlib import import_module from glue.logger import logger -from glue._plugin_helpers import REQUIRED_PLUGINS, REQUIRED_PLUGINS_QT +from glue._plugin_helpers import REQUIRED_PLUGINS _loaded_plugins = set() @@ -50,8 +50,8 @@ def load_plugins(splash=None, require_qt_plugins=False, plugins_to_load=None): if plugins_to_load is None: plugins_to_load = [i.module for i in list(iter_plugin_entry_points())] - if require_qt_plugins: - plugins_to_require = [*REQUIRED_PLUGINS, *REQUIRED_PLUGINS_QT] + if plugins_to_load: + plugins_to_require = [*REQUIRED_PLUGINS] else: plugins_to_require = REQUIRED_PLUGINS else: @@ -116,8 +116,18 @@ def load_plugins(splash=None, require_qt_plugins=False, plugins_to_load=None): load_settings() -def list_plugins(): +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 7d4c83744..da995d8af 100644 --- a/glue/tests/test_main.py +++ b/glue/tests/test_main.py @@ -1,7 +1,6 @@ from unittest.mock import patch -from glue.main import load_plugins -from glue.main import list_plugins +from glue.main import load_plugins, list_loaded_plugins, list_available_plugins def test_load_plugins(capsys): @@ -17,9 +16,10 @@ def test_load_plugins(capsys): plugins = [] for acall in info.call_args_list: if ('loaded' or 'succeeded') in acall[0][0]: - plugins.append(acall[0][0]) + plugins.append(acall[0][0].split(' ')[1]) assert len(plugins) == 5 + assert 'coordinate_helpers' in plugins def test_no_duplicate_loading(capsys): @@ -39,11 +39,22 @@ def test_no_duplicate_loading(capsys): assert 'failed' in acall[0][0] -def test_list_plugins(): +def test_list_loaded_plugins(): """ Regression test for retrieving the list of currently loaded plugins """ load_plugins(require_qt_plugins=False) - plugins = list_plugins() + plugins = list_loaded_plugins() assert isinstance(plugins, list) assert len(plugins) == 5 + + +def test_list_available_plugins(): + """ + Regression test for retrieving the list of currently available plugins + """ + available_plugins = list_available_plugins() + assert isinstance(available_plugins, list) + assert len(available_plugins) == 7 + assert 'casa_formats_io.glue_factory' in available_plugins + assert 'glue.plugins.wcs_autolinking' in available_plugins From 6169782722a0e0b7393ffb4b2a54be7eeaa81102 Mon Sep 17 00:00:00 2001 From: CyclingNinja Date: Tue, 4 Jun 2024 15:38:51 +0100 Subject: [PATCH 5/6] Complete tests and revert qt_refactor --- glue/main.py | 6 +++--- glue/tests/test_main.py | 18 +++++++++++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/glue/main.py b/glue/main.py index 353cd7342..a428be40c 100644 --- a/glue/main.py +++ b/glue/main.py @@ -3,7 +3,7 @@ from importlib import import_module from glue.logger import logger -from glue._plugin_helpers import REQUIRED_PLUGINS +from glue._plugin_helpers import REQUIRED_PLUGINS, REQUIRED_PLUGINS_QT _loaded_plugins = set() @@ -50,8 +50,8 @@ def load_plugins(splash=None, require_qt_plugins=False, plugins_to_load=None): if plugins_to_load is None: plugins_to_load = [i.module for i in list(iter_plugin_entry_points())] - if plugins_to_load: - plugins_to_require = [*REQUIRED_PLUGINS] + if require_qt_plugins: + plugins_to_require = [*REQUIRED_PLUGINS, *REQUIRED_PLUGINS_QT] else: plugins_to_require = REQUIRED_PLUGINS else: diff --git a/glue/tests/test_main.py b/glue/tests/test_main.py index da995d8af..dd1a0013d 100644 --- a/glue/tests/test_main.py +++ b/glue/tests/test_main.py @@ -1,6 +1,7 @@ from unittest.mock import patch from glue.main import load_plugins, list_loaded_plugins, list_available_plugins +from glue._plugin_helpers import REQUIRED_PLUGINS def test_load_plugins(capsys): @@ -34,27 +35,38 @@ 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 + assert len(loaded_plugins) == 5 + def test_list_loaded_plugins(): """ - Regression test for retrieving the list of currently 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) assert len(plugins) == 5 + for test_plugin in REQUIRED_PLUGINS: + assert test_plugin in plugins def test_list_available_plugins(): """ - Regression test for retrieving the list of currently available plugins + Unit test for retrieving the list of currently available plugins """ available_plugins = list_available_plugins() assert isinstance(available_plugins, list) assert len(available_plugins) == 7 - assert 'casa_formats_io.glue_factory' in available_plugins assert 'glue.plugins.wcs_autolinking' in available_plugins + assert 'glue.core.data_exporters' in available_plugins + assert 'glue.plugins.coordinate_helpers' in available_plugins From 20787f25371d01f81ac733d46b0541ad79cf3fc7 Mon Sep 17 00:00:00 2001 From: CyclingNinja Date: Mon, 16 Sep 2024 16:14:35 +0200 Subject: [PATCH 6/6] Correct tests to plugin count --- glue/tests/test_main.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/glue/tests/test_main.py b/glue/tests/test_main.py index dd1a0013d..6c961d28d 100644 --- a/glue/tests/test_main.py +++ b/glue/tests/test_main.py @@ -19,7 +19,6 @@ def test_load_plugins(capsys): if ('loaded' or 'succeeded') in acall[0][0]: plugins.append(acall[0][0].split(' ')[1]) - assert len(plugins) == 5 assert 'coordinate_helpers' in plugins @@ -45,7 +44,6 @@ def test_no_duplicate_loading(capsys): assert 'glue.plugins.wcs_autolinking' in loaded_plugins assert 'glue.core.data_exporters' in loaded_plugins assert 'glue.plugins.coordinate_helpers' in loaded_plugins - assert len(loaded_plugins) == 5 def test_list_loaded_plugins(): @@ -55,7 +53,6 @@ def test_list_loaded_plugins(): load_plugins(require_qt_plugins=False) plugins = list_loaded_plugins() assert isinstance(plugins, list) - assert len(plugins) == 5 for test_plugin in REQUIRED_PLUGINS: assert test_plugin in plugins @@ -66,7 +63,6 @@ def test_list_available_plugins(): """ available_plugins = list_available_plugins() assert isinstance(available_plugins, list) - assert len(available_plugins) == 7 assert 'glue.plugins.wcs_autolinking' in available_plugins assert 'glue.core.data_exporters' in available_plugins assert 'glue.plugins.coordinate_helpers' in available_plugins