Skip to content

Test xarray naming post conversion and enable GUI tests #327

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -45,9 +45,10 @@ jobs:
python -m pip install -e '.[dev]'

- name: Test PyImageJ
shell: bash
run: |
bin/test.sh
uses: GabrielBB/xvfb-action@v1
with:
run:
bash bin/test.sh

ensure-clean-code:
runs-on: ubuntu-latest
8 changes: 6 additions & 2 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import argparse

import sys
import pytest

import imagej
@@ -21,7 +21,7 @@ def pytest_addoption(parser):
"--headless",
type=str2bool,
action="store",
default=True,
default=False,
help="Start in headless mode",
)
parser.addoption(
@@ -46,6 +46,10 @@ def ij(request):
imagej.when_imagej_starts(lambda ij: setattr(ij, "_testing", True))

mode = "headless" if headless else "interactive"
# set headless mode for macOS only
macos = sys.platform == "darwin"
if macos:
mode = "headless"
ij = imagej.init(ij_dir, mode=mode, add_legacy=legacy)

yield ij
8 changes: 8 additions & 0 deletions tests/test_fiji.py
Original file line number Diff line number Diff line change
@@ -5,22 +5,30 @@


def test_plugins_load_using_pairwise_stitching(ij):
# get pariwise stiching Fiji plugin, if available
try:
sj.jimport("plugin.Stitching_Pairwise")
except TypeError:
pytest.skip("No Pairwise Stitching plugin available. Skipping test.")

# skip if missing legacy or in headless mode
if not ij.legacy:
pytest.skip("No original ImageJ. Skipping test.")
if ij.ui().isHeadless():
pytest.skip("No GUI. Skipping test.")

# create random image tiles
tile1 = ij.IJ.createImage("Tile1", "8-bit random", 512, 512, 1)
tile2 = ij.IJ.createImage("Tile2", "8-bit random", 512, 512, 1)
tile1.show()
tile2.show()

# stich image tiles
args = {"first_image": tile1.getTitle(), "second_image": tile2.getTitle()}
ij.py.run_plugin("Pairwise stitching", args)
result_name = ij.WindowManager.getCurrentImage().getTitle()

# clean up the windows
ij.IJ.run("Close All", "")

assert result_name == "Tile1<->Tile2"
21 changes: 21 additions & 0 deletions tests/test_legacy.py
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
import numpy as np
import pytest
import scyjava as sj
import xarray

# -- Fixtures --

@@ -13,6 +14,11 @@ def arr():
return empty_array


@pytest.fixture(scope="module")
def xarr(arr):
return xarray.DataArray(arr, name="test_xarray")


@pytest.fixture(scope="module")
def results_table(ij):
if ij.legacy and ij.legacy.isActive():
@@ -113,6 +119,8 @@ def test_get_imageplus_synchronizes_from_imagej_to_imagej2(ij, arr):
ij.ui().show(ds)
macro = """run("Add...", "value=5");"""
ij.py.run_macro(macro)
imp = ij.WindowManager.getCurrentImage()
ij.py.sync_image(imp)

assert arr[0, 0] == original + 5

@@ -141,6 +149,19 @@ def test_window_to_numpy_converts_active_image_to_xarray(ij, arr):
assert (arr == new_arr.values).all


def test_linked_dataset_conversion_to_xarray(ij, xarr):
ensure_legacy_enabled(ij)
ensure_gui_available(ij)

# get a dataset, linked to an ImagePlus
dataset = ij.py.to_dataset(xarr)
ij.ui().show(dataset)

# convert the image data to xarray
xarr_out = ij.py.to_xarray(dataset)
assert xarr_out.name == "test_xarray"


def test_functions_throw_warning_if_legacy_not_enabled(ij):
ensure_legacy_disabled(ij)