Skip to content

Commit

Permalink
Add list plugins method and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
CyclingNinja committed May 24, 2024
1 parent 5e92185 commit 18adb50
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
9 changes: 7 additions & 2 deletions glue/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
25 changes: 25 additions & 0 deletions glue/tests/test_main.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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

0 comments on commit 18adb50

Please sign in to comment.