Skip to content

Commit

Permalink
Testing: Add tests for external plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
ccordoba12 committed Aug 7, 2021
1 parent a11766a commit 87ec476
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
44 changes: 43 additions & 1 deletion spyder/app/tests/test_find_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@
Tests for finding plugins.
"""

import pytest

from spyder.api.plugins import Plugins
from spyder.api.utils import get_class_values
from spyder.app.find_plugins import find_internal_plugins
from spyder.app.find_plugins import (
find_internal_plugins, find_external_plugins)
from spyder.config.base import running_in_ci


def test_find_internal_plugins():
Expand All @@ -30,3 +34,41 @@ def test_find_internal_plugins():

# Names must be the same
assert sorted(expected_names) == sorted(list(internal_plugins.keys()))


@pytest.mark.skipif(not running_in_ci(), reason="Only works in CIs")
def test_find_external_plugins():
"""Test that we return the external plugins installed when testing."""
internal_names = get_class_values(Plugins)
expected_names = ['spyder_boilerplate']
expected_special_attrs = {
'spyder_boilerplate': [
'spyder_boilerplate.spyder.plugin',
'spyder-boilerplate',
'0.0.1'
]
}

# Dictionary of external plugins
external_plugins = find_external_plugins()

# External plugins must be the ones installed while testing
assert len(external_plugins.keys()) == len(expected_names)

# Names must not be among internal plugins
for name in external_plugins.keys():
assert name not in internal_names

# Names must be the expected ones.
assert sorted(expected_names) == sorted(list(external_plugins.keys()))

# Assert special attributes are present
for name in external_plugins.keys():
plugin_class = external_plugins[name]
special_attrs = [
plugin_class._spyder_module_name,
plugin_class._spyder_package_name,
plugin_class._spyder_version
]

assert expected_special_attrs[name] == special_attrs
14 changes: 14 additions & 0 deletions spyder/app/tests/test_mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
from spyder.config.base import (
get_home_dir, get_conf_path, get_module_path, running_in_ci)
from spyder.config.manager import CONF
from spyder.dependencies import DEPENDENCIES
from spyder.plugins.base import PluginWindow
from spyder.plugins.help.widgets import ObjectComboBox
from spyder.plugins.help.tests.test_plugin import check_text
Expand Down Expand Up @@ -4161,5 +4162,18 @@ def test_copy_paste(main_window, qtbot, tmpdir):
assert expected in code_editor.toPlainText()


@pytest.mark.slow
@pytest.mark.skipif(not running_in_ci(), reason="Only works in CIs")
def test_add_external_plugins_to_dependencies(main_window):
"""Test that we register external plugins in the main window."""
external_names = []
for dep in DEPENDENCIES:
name = getattr(dep, 'package_name', None)
if name:
external_names.append(name)

assert 'spyder-boilerplate' in external_names


if __name__ == "__main__":
pytest.main()

0 comments on commit 87ec476

Please sign in to comment.