forked from napari/napari
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* main: (26 commits) Fix some typing in napari.components (napari#6203) Use class name for object that does not have qt name (napari#6222) test: [Automatic] Constraints upgrades: `hypothesis`, `magicgui`, `psygnal`, `tensorstore`, `tifffile`, `tqdm`, `virtualenv` (napari#6143) Replace more np.all( ... = ...) with np.array_equal (napari#6213) remove np.all(... == ...) in test_surface.py (napari#6218) Ensure pandas Series is initialized with a list as data (napari#6226) Stop using temporary directory for store array for paint test (napari#6191) Bugfix: ensure thumbnail represents canvas when multiscale (napari#6200) cleanup np.all(... == ...) from test_points.py (napari#6217) [pre-commit.ci] pre-commit autoupdate (napari#6221) use app-model for file menu (napari#4865) Add tests to cover slicing behavior when changing layers and data (napari#4819) [pre-commit.ci] pre-commit autoupdate (napari#6128) Add test coverage for async slicing of labels (napari#5325) Add collision check when set colors for labels layer (napari#6193) Update "toggle ndview" text (napari#6192) Prevent layer controls buttons changing layout while taking screenshots with flash effect on (napari#6194) Fix typing in napari.utils.perf (napari#6132) Add GUI test coverage for changes to Labels.show_selected_label (napari#5372) Fix types in 'napari.utils.colormaps.categorical_colormap' (napari#6154) ...
- Loading branch information
Showing
81 changed files
with
2,111 additions
and
1,372 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
repos: | ||
- repo: https://github.com/psf/black-pre-commit-mirror | ||
rev: 23.7.0 | ||
rev: 23.9.1 | ||
hooks: | ||
- id: black | ||
pass_filenames: true | ||
exclude: _vendor|vendored|examples | ||
- repo: https://github.com/astral-sh/ruff-pre-commit | ||
rev: v0.0.281 | ||
rev: v0.0.288 | ||
hooks: | ||
- id: ruff | ||
exclude: _vendor|vendored | ||
- repo: https://github.com/seddonym/import-linter | ||
rev: v1.10.0 | ||
rev: v1.11.1 | ||
hooks: | ||
- id: import-linter | ||
stages: [manual] | ||
- repo: https://github.com/python-jsonschema/check-jsonschema | ||
rev: 0.23.3 | ||
rev: 0.26.3 | ||
hooks: | ||
- id: check-github-workflows |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,65 @@ | ||
from unittest.mock import MagicMock | ||
|
||
import numpy as np | ||
import pytest | ||
from app_model.types import Action | ||
|
||
from napari import viewer | ||
from napari._app_model import constants, get_app | ||
from napari._app_model import get_app | ||
from napari._app_model.constants import MenuId | ||
from napari._app_model.context import LayerListContextKeys as LLCK | ||
from napari._qt._qapp_model import build_qmodel_menu | ||
from napari._qt._qapp_model.qactions import init_qactions | ||
from napari._qt.qt_main_window import Window | ||
from napari.layers import Image | ||
|
||
|
||
@pytest.mark.parametrize('menu_id', list(constants.MenuId)) | ||
def test_build_qmodel_menu(qtbot, menu_id): | ||
"""Test that we can build qmenus for all registered menu IDs""" | ||
# `builtins` required so there are samples registered, so samples menu exists | ||
@pytest.mark.parametrize('menu_id', list(MenuId)) | ||
def test_build_qmodel_menu(builtins, make_napari_viewer, qtbot, menu_id): | ||
"""Test that we can build qmenus for all registered menu IDs.""" | ||
app = get_app() | ||
|
||
mock = MagicMock() | ||
with app.injection_store.register( | ||
providers={viewer.Viewer: lambda: mock, Window: lambda: mock} | ||
): | ||
init_qactions.cache_clear() | ||
init_qactions() | ||
# Configures `app`, registers actions and initializes plugins | ||
make_napari_viewer() | ||
|
||
menu = build_qmodel_menu(menu_id) | ||
qtbot.addWidget(menu) | ||
|
||
# `>=` because separator bars count as actions | ||
assert len(menu.actions()) >= len(app.menus.get_menu(menu_id)) | ||
|
||
|
||
def test_update_menu_state_context(make_napari_viewer): | ||
"""Test `_update_menu_state` correctly updates enabled/visible state.""" | ||
app = get_app() | ||
viewer = make_napari_viewer() | ||
|
||
action = Action( | ||
id='dummy_id', | ||
title='dummy title', | ||
callback=lambda: None, | ||
menus=[{'id': MenuId.MENUBAR_FILE, 'when': (LLCK.num_layers > 0)}], | ||
enablement=(LLCK.num_layers == 2), | ||
) | ||
app.register_action(action) | ||
|
||
dummy_action = viewer.window.file_menu.findAction('dummy_id') | ||
|
||
assert 'dummy_id' in app.commands | ||
assert len(viewer.layers) == 0 | ||
# `dummy_action` should be disabled & not visible as num layers == 0 | ||
viewer.window._update_menu_state('file_menu') | ||
assert not dummy_action.isVisible() | ||
assert not dummy_action.isEnabled() | ||
|
||
menu = build_qmodel_menu(menu_id) | ||
qtbot.addWidget(menu) | ||
layer_a = Image(np.random.random((10, 10))) | ||
viewer.layers.append(layer_a) | ||
assert len(viewer.layers) == 1 | ||
viewer.window._update_menu_state('file_menu') | ||
# `dummy_action` should be visible but not enabled after adding layer | ||
assert dummy_action.isVisible() | ||
assert not dummy_action.isEnabled() | ||
|
||
# `>=` because separator bars count as actions | ||
assert len(menu.actions()) >= len(app.menus.get_menu(menu_id)) | ||
layer_b = Image(np.random.random((10, 10))) | ||
viewer.layers.append(layer_b) | ||
assert len(viewer.layers) == 2 | ||
# `dummy_action` should be enabled and visible after adding second layer | ||
viewer.window._update_menu_state('file_menu') | ||
assert dummy_action.isVisible() | ||
assert dummy_action.isEnabled() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.