Skip to content
Snippets Groups Projects
Commit 82c3a682 authored by Andrey Aristov's avatar Andrey Aristov
Browse files

fix test

parent 500360ba
No related branches found
No related tags found
No related merge requests found
from napari_segment import ExampleQWidget, example_magic_widget
import numpy as np
# make_napari_viewer is a pytest fixture that returns a napari viewer object
# capsys is a pytest fixture that captures stdout and stderr output streams
def test_example_q_widget(make_napari_viewer, capsys):
# make viewer and add an image layer using our fixture
viewer = make_napari_viewer()
viewer.add_image(np.random.random((100, 100)))
# create our widget, passing in the viewer
my_widget = ExampleQWidget(viewer)
# call our widget method
my_widget._on_click()
# read captured output and check that it's as we expected
captured = capsys.readouterr()
assert captured.out == "napari has 1 layers\n"
def test_example_magic_widget(make_napari_viewer, capsys):
viewer = make_napari_viewer()
layer = viewer.add_image(np.random.random((100, 100)))
# this time, our widget will be a MagicFactory or FunctionGui instance
my_widget = example_magic_widget()
# if we "call" this object, it'll execute our function
my_widget(viewer.layers[0])
# read captured output and check that it's as we expected
captured = capsys.readouterr()
assert captured.out == f"you have selected {layer}\n"
from napari_segment import ExampleQWidget, example_magic_widget from napari_segment import SegmentStack
import numpy as np import numpy as np
import dask.array as da
# make_napari_viewer is a pytest fixture that returns a napari viewer object # make_napari_viewer is a pytest fixture that returns a napari viewer object
# capsys is a pytest fixture that captures stdout and stderr output streams # capsys is a pytest fixture that captures stdout and stderr output streams
def test_example_q_widget(make_napari_viewer, capsys): def test_segment_stack(make_napari_viewer, capsys):
# make viewer and add an image layer using our fixture # make viewer and add an image layer using our fixture
viewer = make_napari_viewer() viewer = make_napari_viewer()
viewer.add_image(np.random.random((100, 100))) viewer.add_image(np.random.random((5, 100, 100)), name="test_data", metadata={"path": "fakepath.nd2"})
# create our widget, passing in the viewer # create our widget, passing in the viewer
my_widget = ExampleQWidget(viewer) widget = SegmentStack(viewer)
assert widget.input.current_choice == "test_data"
assert widget.path == "fakepath.nd2"
assert isinstance(widget.ddata, da.Array)
assert widget.ddata.chunks == ((1, 1, 1, 1, 1), (100/widget.binning,), (100/widget.binning,))
# call our widget method
my_widget._on_click()
# read captured output and check that it's as we expected # read captured output and check that it's as we expected
captured = capsys.readouterr() # captured = capsys.readouterr()
assert captured.out == "napari has 1 layers\n" # assert captured.out == "napari has 1 layers\n"
def test_example_magic_widget(make_napari_viewer, capsys):
viewer = make_napari_viewer()
layer = viewer.add_image(np.random.random((100, 100)))
# this time, our widget will be a MagicFactory or FunctionGui instance
my_widget = example_magic_widget()
# if we "call" this object, it'll execute our function
my_widget(viewer.layers[0])
# read captured output and check that it's as we expected
captured = capsys.readouterr()
assert captured.out == f"you have selected {layer}\n"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment