Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CI, tox config and other test adjustments #3

Merged
merged 26 commits into from
May 4, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 16 additions & 56 deletions napari_plugin_manager/_tests/test_qt_plugin_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ def close(self):
self._is_visible = False


@pytest.fixture
def plugin_dialog(qtbot, monkeypatch, mock_pm, plugins, old_plugins): # noqa
@pytest.fixture(params=[True, False], ids=["constructor", "no-constructor"])
def plugin_dialog(request, qtbot, monkeypatch, mock_pm, plugins, old_plugins): # noqa
"""Fixture that provides a plugin dialog for a normal napari install."""

class PluginManagerMock:
Expand Down Expand Up @@ -160,16 +160,11 @@ def set_blocked(self, plugin, blocked):
"iter_napari_plugin_info",
_iter_napari_pypi_plugin_info,
)

monkeypatch.setattr(qt_plugin_dialog, 'WarnPopup', WarnPopupMock)

# This is patching `napari.utils.misc.running_as_constructor_app` function
# to mock a normal napari install.
monkeypatch.setattr(
qt_plugin_dialog,
"running_as_constructor_app",
lambda: False,
)
monkeypatch.setattr(qt_plugin_dialog, "running_as_constructor_app", lambda: request.param)

monkeypatch.setattr(
napari.plugins, 'plugin_manager', OldPluginManagerMock()
Expand All @@ -181,44 +176,16 @@ def set_blocked(self, plugin, blocked):

widget = qt_plugin_dialog.QtPluginDialog()
widget.show()
qtbot.wait(300)
qtbot.waitUntil(widget.isVisible, timeout=300)
qtbot.add_widget(widget)
qtbot.waitUntil(lambda: widget.available_list.count() >= 2, timeout=300)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we know how many entries we expect here? If the test ends before the thread yelding new plugin entries it may end with a crash whole test setup. We should wait until this thread ends working.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also lambdas are sometimes funky in these tests, so using a separate function might be slightly better

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done :)

yield widget
widget.hide()
widget._add_items_timer.stop()
assert not widget._add_items_timer.isActive()


@pytest.fixture
def plugin_dialog_constructor(qtbot, monkeypatch):
"""
Fixture that provides a plugin dialog for a constructor based install.
"""
monkeypatch.setattr(
qt_plugin_dialog,
"iter_napari_plugin_info",
_iter_napari_pypi_plugin_info,
)

# This is patching `napari.utils.misc.running_as_constructor_app` function
# to mock a constructor based install.
monkeypatch.setattr(
qt_plugin_dialog,
"running_as_constructor_app",
lambda: True,
)
monkeypatch.setattr(qt_plugin_dialog, 'WarnPopup', WarnPopupMock)

widget = qt_plugin_dialog.QtPluginDialog()
widget.show()
qtbot.wait(300)
qtbot.add_widget(widget)
yield widget
widget.hide()
widget._add_items_timer.stop()


def test_filter_not_available_plugins(qtbot, plugin_dialog_constructor):
def test_filter_not_available_plugins(qtbot, plugin_dialog):
jaimergp marked this conversation as resolved.
Show resolved Hide resolved
"""
Check that the plugins listed under available plugins are
enabled and disabled accordingly.
Expand All @@ -229,14 +196,14 @@ def test_filter_not_available_plugins(qtbot, plugin_dialog_constructor):
The second plugin ("test-name-1") is available on conda-forge and
should be enabled without the tooltip warning.
"""
item = plugin_dialog_constructor.available_list.item(0)
widget = plugin_dialog_constructor.available_list.itemWidget(item)
item = plugin_dialog.available_list.item(0)
widget = plugin_dialog.available_list.itemWidget(item)
if widget:
assert not widget.action_button.isEnabled()
assert widget.warning_tooltip.isVisible()

item = plugin_dialog_constructor.available_list.item(1)
widget = plugin_dialog_constructor.available_list.itemWidget(item)
item = plugin_dialog.available_list.item(1)
widget = plugin_dialog.available_list.itemWidget(item)
assert widget.action_button.isEnabled()
assert not widget.warning_tooltip.isVisible()

Expand Down Expand Up @@ -270,25 +237,18 @@ def test_filter_installed_plugins(plugin_dialog):
assert plugin_dialog.installed_list._count_visible() == 0


def test_visible_widgets(plugin_dialog):
def test_visible_widgets(request, plugin_dialog):
"""
Test that the direct entry button and textbox are visible for
normal napari installs.
Test that the direct entry button and textbox are visible
"""

if "no-constructor" not in request.node.name:
# the plugin_dialog fixture has this id
# skip for 'constructor' variant
pytest.skip()
assert plugin_dialog.direct_entry_edit.isVisible()
assert plugin_dialog.direct_entry_btn.isVisible()


def test_constructor_visible_widgets(plugin_dialog_constructor):
"""
Test that the direct entry button and textbox are hidden for
constructor based napari installs.
"""
assert not plugin_dialog_constructor.direct_entry_edit.isVisible()
assert not plugin_dialog_constructor.direct_entry_btn.isVisible()


def test_version_dropdown(qtbot, plugin_dialog):
"""
Test that when the source drop down is changed, it displays the other versions properly.
Expand Down