Skip to content

Commit

Permalink
runner util
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Schorb committed Mar 14, 2024
1 parent e58b37f commit a1133c5
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 12 deletions.
45 changes: 45 additions & 0 deletions src/debug_runner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# launch_napari.py
from napari import Viewer, run
import sys
import os
import yaml

module0 = "mobie-napari-bridge"

module = module0.replace("-", "_")

def get_widgetname():
widget_name = None
if len(sys.argv) > 1:
if sys.argv[1] != "":
selection = sys.argv[1]
with open(os.path.join(os.getcwd(), "src", module, "napari.yaml")) as f:
mod_settings = yaml.safe_load(f)

for cmd in mod_settings['contributions']['commands']:
if selection not in cmd['python_name']:
continue
else:
w_id = cmd['id']
for widget in mod_settings['contributions']['widgets']:
if w_id not in widget['command']:
continue
else:
widget_name = widget['display_name']

return widget_name




if __name__ == "__main__":

viewer = Viewer()
widget_name = get_widgetname()
dock_widget, plugin_widget = viewer.window.add_plugin_dock_widget(
module0, widget_name=widget_name
)
# Optional steps to setup your plugin to a state of failure
# E.g. plugin_widget.parameter_name.value = "some value"
# E.g. plugin_widget.button.click()
run()
16 changes: 16 additions & 0 deletions src/mobie_napari_bridge/_tests/test_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,19 @@ def test_example_q_widget(make_napari_viewer, capsys):
# read captured output and check that it's as we expected
captured = capsys.readouterr()
assert captured.out == "napari has 1 layers\n"


def test_browse_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 = TestBrowse(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"
12 changes: 0 additions & 12 deletions src/mobie_napari_bridge/debug_runner.py

This file was deleted.

0 comments on commit a1133c5

Please sign in to comment.