Skip to content

Commit

Permalink
test: fix tests, stop using make_napari_viewer fixture (#338)
Browse files Browse the repository at this point in the history
* test: enable_console

* remove marks

* stop using make_napari_viewer

* fix pyqt6

---------

Co-authored-by: Talley Lambert <[email protected]>
  • Loading branch information
fdrgsp and tlambert03 authored Jul 17, 2024
1 parent 1cc323f commit 6c895f3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
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 @@ def _clear(self) -> None:
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()

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

0 comments on commit 6c895f3

Please sign in to comment.