|
| 1 | +from tifffile import imread |
| 2 | +from pathlib import Path |
| 3 | +import warnings |
| 4 | + |
| 5 | +from qtpy.QtWidgets import QTextEdit |
| 6 | + |
| 7 | +from napari_cellseg3d.code_plugins.plugin_model_inference import Inferer |
| 8 | + |
| 9 | + |
| 10 | +class LogFixture(QTextEdit): |
| 11 | + def __init__(self): |
| 12 | + super(LogFixture, self).__init__() |
| 13 | + |
| 14 | + def print_and_log(self, text, printing=None): |
| 15 | + print(text) |
| 16 | + |
| 17 | + def warn(self, warning): |
| 18 | + warnings.warn(warning) |
| 19 | + |
| 20 | + |
| 21 | +def test_inference(make_napari_viewer, qtbot): |
| 22 | + |
| 23 | + im_path = str(Path(__file__).resolve().parent / "res/test.tif") |
| 24 | + image = imread(im_path) |
| 25 | + |
| 26 | + assert image.shape == (6, 6, 6) |
| 27 | + |
| 28 | + viewer = make_napari_viewer() |
| 29 | + widget = Inferer(viewer) |
| 30 | + widget.log = LogFixture() |
| 31 | + viewer.window.add_dock_widget(widget) |
| 32 | + viewer.add_image(image) |
| 33 | + |
| 34 | + assert len(viewer.layers) == 1 |
| 35 | + |
| 36 | + widget.window_infer_box.setChecked(True) |
| 37 | + widget.window_overlap_slider.setValue(0.0) |
| 38 | + widget.keep_data_on_cpu_box.setChecked(True) |
| 39 | + |
| 40 | + assert widget.check_ready() |
| 41 | + |
| 42 | + widget.start() |
| 43 | + assert widget.worker is not None |
| 44 | + |
| 45 | + with qtbot.waitSignal(signal=widget.worker.finished) as blocker: |
| 46 | + blocker.connect(widget.worker.errored) |
| 47 | + |
| 48 | + assert len(viewer.layers) == 2 |
0 commit comments