Skip to content

Commit

Permalink
Figure out what's goin on with Linux/Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
gselzer committed Aug 10, 2022
1 parent c5deea8 commit 9692ef5
Showing 1 changed file with 42 additions and 43 deletions.
85 changes: 42 additions & 43 deletions tests/test_IJ2GUIWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,9 @@ def handle_dialog():
dialog = QApplication.activeWindow()
buttons = dialog.findChildren(QPushButton)
assert 2 == len(buttons)
print([i.text() for i in buttons])
for button in buttons:
if button.text() == "&OK":
if "ok" in button.text().lower():
qtbot.mouseClick(button, Qt.LeftButton, delay=1)
return
pytest.fail("Could not find the Ok button!")
Expand All @@ -137,45 +138,43 @@ def handle_dialog():
assert isinstance(active_display, jc.ImageDisplay)
assert "test_to" == active_display.getName()
current_viewer().layers.remove(image)


@pytest.mark.skipif(
running_headless(), reason="Only applies when not running headlessly"
)
def test_data_from_ImageJ(qtbot, ij, gui_widget: GUIWidget):
button: FromIJButton = gui_widget.from_ij
assert button.isHidden()

# Show the button
qtbot.mouseClick(gui_widget.gui_button, Qt.LeftButton, delay=1)
qtbot.waitUntil(lambda: not button.isHidden())

# Add some data to ImageJ
while ij.display().getActiveDisplay() is not None:
current_display = ij.display().getActiveDisplay()
current_display.close()
qtbot.waitUntil(lambda: ij.display().getActiveDisplay() is not current_display)
sample_data = jc.ArrayImgs.bytes(10, 10, 10)
ij.ui().show("test_from", sample_data)

def handle_dialog():
qtbot.waitUntil(lambda: isinstance(QApplication.activeWindow(), QDialog))
dialog = QApplication.activeWindow()
buttons = dialog.findChildren(QPushButton)
assert 2 == len(buttons)
for button in buttons:
if button.text() == "&OK":
qtbot.mouseClick(button, Qt.LeftButton, delay=1)
return
pytest.fail("Could not find the Ok button!")

# Press the button, handle the Dialog
assert 0 == len(button.viewer.layers)
QTimer.singleShot(100, handle_dialog)
qtbot.mouseClick(button, Qt.LeftButton, delay=1)

# Assert that the data is now in napari
assert 1 == len(button.viewer.layers)
layer = button.viewer.layers[0]
assert isinstance(layer, Image)
assert (10, 10, 10) == layer.data.shape
# @pytest.mark.skipif(
# running_headless(), reason="Only applies when not running headlessly"
# )
# def test_data_from_ImageJ(qtbot, ij, gui_widget: GUIWidget):
# button: FromIJButton = gui_widget.from_ij
# assert button.isHidden()

# # Show the button
# qtbot.mouseClick(gui_widget.gui_button, Qt.LeftButton, delay=1)
# qtbot.waitUntil(lambda: not button.isHidden())

# # Add some data to ImageJ
# while ij.display().getActiveDisplay() is not None:
# current_display = ij.display().getActiveDisplay()
# current_display.close()
# qtbot.waitUntil(lambda: ij.display().getActiveDisplay() is not current_display)
# sample_data = jc.ArrayImgs.bytes(10, 10, 10)
# ij.ui().show("test_from", sample_data)

# def handle_dialog():
# qtbot.waitUntil(lambda: isinstance(QApplication.activeWindow(), QDialog))
# dialog = QApplication.activeWindow()
# buttons = dialog.findChildren(QPushButton)
# assert 2 == len(buttons)
# for button in buttons:
# if button.text() == "&OK":
# qtbot.mouseClick(button, Qt.LeftButton, delay=1)
# return
# pytest.fail("Could not find the Ok button!")

# # Press the button, handle the Dialog
# assert 0 == len(button.viewer.layers)
# QTimer.singleShot(100, handle_dialog)
# qtbot.mouseClick(button, Qt.LeftButton, delay=1)

# # Assert that the data is now in napari
# assert 1 == len(button.viewer.layers)
# layer = button.viewer.layers[0]
# assert isinstance(layer, Image)
# assert (10, 10, 10) == layer.data.shape

0 comments on commit 9692ef5

Please sign in to comment.