Skip to content

Commit

Permalink
Moved constants out of test_big_stitcher_bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorTatarnikov committed Jul 30, 2024
1 parent ca780b0 commit c59034f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 45 deletions.
12 changes: 9 additions & 3 deletions tests/test_unit/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import platform
import shutil
from pathlib import Path
from platform import system

import pooch
import pytest
Expand Down Expand Up @@ -96,9 +96,9 @@ def bdv_directory_function_level():

@pytest.fixture(scope="module")
def imagej_path():
if platform.system() == "Windows":
if system() == "Windows":
return Path.home() / "Fiji.app/ImageJ-win64.exe"
elif platform.system() == "Darwin":
elif system() == "Darwin":
return Path.home() / "Fiji.app"
else:
return Path.home() / "Fiji.app/ImageJ-linux64"
Expand Down Expand Up @@ -151,6 +151,12 @@ def test_constants(imagej_path):
"PIXEL_SIZE_XY": 4.08,
"PIXEL_SIZE_Z": 5.0,
"MOCK_IMAGEJ_PATH": imagej_path,
# The file dialogue on macOS has a different behaviour
# The selected file path is to the "Fiji.app" directory
# The ImageJ executable is in "Fiji.app/Contents/MacOS/ImageJ-macosx"
"MOCK_IMAGEJ_EXEC_PATH": imagej_path / "Contents/MacOS/ImageJ-macosx"
if system() == "Darwin"
else imagej_path,
"MOCK_XML_PATH": Path.home() / "stitching/Brain2/bdv.xml",
"MOCK_TILE_CONFIG_PATH": Path.home()
/ "stitching/Brain2/bdv_tile_config.txt",
Expand Down
55 changes: 13 additions & 42 deletions tests/test_unit/test_big_stitcher_bridge.py
Original file line number Diff line number Diff line change
@@ -1,56 +1,29 @@
from importlib.resources import files
from pathlib import Path

import pytest

from brainglobe_stitch.big_stitcher_bridge import run_big_stitcher

IMAGEJ_PATH_WINDOWS = Path("C:/Fiji.app/ImageJ-win64.exe")
XML_PATH_WINDOWS = Path("C:/stitching/Brain2/bdv.xml")
TILE_CONFIG_PATH_WINDOWS = Path("C:/stitching/Brain2/bdv_tile_config.txt")

IMAGEJ_PATH_MAC = Path("/Users/user/Fiji.app")
IMAGEJ_PATH_MAC_CHECK = Path(
"/Users/user/Fiji.app/Contents/MacOS/ImageJ-macosx"
)
XML_PATH_MAC = Path("/Users/user/stitching/Brain2/bdv.xml")
TILE_CONFIG_PATH_MAC = Path("/Users/user/stitching/Brain2/bdv_tile_config.txt")


@pytest.mark.parametrize(
"test_platform, imagej_path, xml_path, tile_config_path",
[
(
"Windows",
IMAGEJ_PATH_WINDOWS,
XML_PATH_WINDOWS,
TILE_CONFIG_PATH_WINDOWS,
),
("Darwin", IMAGEJ_PATH_MAC, XML_PATH_MAC, TILE_CONFIG_PATH_MAC),
],
)
def test_run_big_stitcher_defaults(
mocker, test_platform, imagej_path, xml_path, tile_config_path
):
def test_run_big_stitcher_defaults(mocker, test_constants):
mock_subprocess_run = mocker.patch(
"brainglobe_stitch.big_stitcher_bridge.subprocess.run"
)
mocker.patch(
"brainglobe_stitch.big_stitcher_bridge.system",
return_value=test_platform,
)

imagej_path = test_constants["MOCK_IMAGEJ_PATH"]
xml_path = test_constants["MOCK_XML_PATH"]
tile_config_path = test_constants["MOCK_TILE_CONFIG_PATH"]

run_big_stitcher(imagej_path, xml_path, tile_config_path)

# Expected path to the ImageJ macro
# Should be in the root of the package
macro_path = files("brainglobe_stitch") / "bigstitcher_macro.ijm"

if test_platform == "Darwin":
imagej_path = IMAGEJ_PATH_MAC_CHECK
expected_imagej_path = test_constants["MOCK_IMAGEJ_EXEC_PATH"]

command = (
f"{imagej_path} --ij2"
f"{expected_imagej_path} --ij2"
f" --headless -macro {macro_path} "
f'"{xml_path} {tile_config_path} 0 488 4 4 1"'
)
Expand All @@ -76,18 +49,15 @@ def test_run_big_stitcher(
downsample_x,
downsample_y,
downsample_z,
test_constants,
):
mock_subprocess_run = mocker.patch(
"brainglobe_stitch.big_stitcher_bridge.subprocess.run"
)
mocker.patch(
"brainglobe_stitch.big_stitcher_bridge.system",
return_value="Windows",
)

imagej_path = IMAGEJ_PATH_WINDOWS
xml_path = XML_PATH_WINDOWS
tile_config_path = TILE_CONFIG_PATH_WINDOWS
imagej_path = test_constants["MOCK_IMAGEJ_PATH"]
xml_path = test_constants["MOCK_XML_PATH"]
tile_config_path = test_constants["MOCK_TILE_CONFIG_PATH"]

run_big_stitcher(
imagej_path,
Expand All @@ -101,9 +71,10 @@ def test_run_big_stitcher(
)

macro_path = files("brainglobe_stitch").joinpath("bigstitcher_macro.ijm")
expected_imagej_path = test_constants["MOCK_IMAGEJ_EXEC_PATH"]

command = (
f"{imagej_path} --ij2"
f"{expected_imagej_path} --ij2"
f" --headless -macro {macro_path} "
f'"{xml_path} {tile_config_path} {int(all_channels)} '
f"{selected_channel} "
Expand Down

0 comments on commit c59034f

Please sign in to comment.