Skip to content

Commit

Permalink
adding available plugins function and test
Browse files Browse the repository at this point in the history
  • Loading branch information
CyclingNinja committed Jun 3, 2024
1 parent fe34214 commit ebb1b8c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
18 changes: 14 additions & 4 deletions glue/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
19 changes: 15 additions & 4 deletions glue/tests/test_main.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -20,6 +19,7 @@ def test_load_plugins(capsys):
plugins.append(acall[0][0])

assert len(plugins) == 5
assert 'glue.plugins.tools' in plugins


def test_no_duplicate_loading(capsys):
Expand All @@ -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

0 comments on commit ebb1b8c

Please sign in to comment.