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

test: fix tests, stop using make_napari_viewer fixture #338

Merged
merged 5 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 4 additions & 2 deletions src/napari_micromanager/_gui_objects/_stages_widget.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from contextlib import suppress
from typing import Optional, cast

from pymmcore_plus import CMMCorePlus, DeviceType
Expand Down Expand Up @@ -52,8 +53,9 @@
for i in reversed(range(self.layout().count())):
if item := self.layout().takeAt(i):
if wdg := item.widget():
wdg.setParent(QWidget())
wdg.deleteLater()
with suppress(RuntimeError):
wdg.setParent(QWidget())
wdg.deleteLater()

Check warning on line 58 in src/napari_micromanager/_gui_objects/_stages_widget.py

View check run for this annotation

Codecov / codecov/patch

src/napari_micromanager/_gui_objects/_stages_widget.py#L56-L58

Added lines #L56 - L58 were not covered by tests

def dragEnterEvent(self, event: QDragEnterEvent) -> None:
event.accept()
Expand Down
27 changes: 22 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
from __future__ import annotations

import itertools
from contextlib import suppress
from pathlib import Path
from typing import TYPE_CHECKING, Any

import napari
import pytest
import useq
from napari_micromanager._util import NMM_METADATA_KEY
from napari_micromanager.main_window import MainWindow
from pymmcore_plus import CMMCorePlus

if TYPE_CHECKING:
from collections.abc import Iterator


# to create a new CMMCorePlus() for every test
@pytest.fixture
def core(monkeypatch):
def core(monkeypatch: pytest.MonkeyPatch) -> CMMCorePlus:
new_core = CMMCorePlus()
config_path = str(Path(__file__).parent / "test_config.cfg")
new_core.loadSystemConfiguration(config_path)
Expand All @@ -19,9 +27,16 @@ def core(monkeypatch):


@pytest.fixture
def main_window(core: CMMCorePlus, make_napari_viewer):
viewer = make_napari_viewer()
win = MainWindow(viewer=viewer)
def napari_viewer(qapp: Any) -> Iterator[napari.Viewer]:
viewer = napari.Viewer(show=False)
yield viewer
with suppress(RuntimeError):
viewer.close()


@pytest.fixture
def main_window(core: CMMCorePlus, napari_viewer: napari.Viewer) -> MainWindow:
win = MainWindow(viewer=napari_viewer)
assert core == win._mmc
return win

Expand Down Expand Up @@ -50,7 +65,9 @@ def mda_sequence(request: pytest.FixtureRequest) -> useq.MDASequence:


@pytest.fixture(params=[True, False], ids=["splitC", "no_splitC"])
def mda_sequence_splits(mda_sequence: useq.MDASequence, request) -> useq.MDASequence:
def mda_sequence_splits(
mda_sequence: useq.MDASequence, request: pytest.FixtureRequest
) -> useq.MDASequence:
if request.param:
meta = {"split_channels": True}
mda_sequence.metadata[NMM_METADATA_KEY] = meta
Expand Down
8 changes: 4 additions & 4 deletions tests/test_layer_scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@
from napari_micromanager._mda_handler import _NapariMDAHandler

if TYPE_CHECKING:
import napari
from napari_micromanager.main_window import MainWindow
from pymmcore_plus import CMMCorePlus
from useq import MDASequence


@pytest.mark.parametrize("axis_order", ["tpcz", "tpzc"])
def test_layer_scale(
make_napari_viewer,
napari_viewer: napari.Viewer,
mda_sequence_splits: MDASequence,
axis_order: str,
core: CMMCorePlus,
) -> None:
viewer = make_napari_viewer()
mmc = core
handler = _NapariMDAHandler(mmc, viewer)
handler = _NapariMDAHandler(mmc, napari_viewer)

mmc.setProperty("Objective", "Label", "Nikon 20X Plan Fluor ELWD")

Expand All @@ -30,7 +30,7 @@ def test_layer_scale(
# create zarr layer
handler._on_mda_started(sequence)

layer = viewer.layers[0]
layer = napari_viewer.layers[0]
if sequence.z_plan:
num_z = len(list(sequence.z_plan))
assert layer.scale[layer.data.shape.index(num_z)] == z_step
Expand Down