Skip to content
50 changes: 32 additions & 18 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"""

import argparse
import subprocess
from datetime import datetime
from pathlib import Path

Expand All @@ -16,6 +17,37 @@
from tests.tree_helpers import tree as tree_lines


@pytest.fixture
def run_photon_mosaic():
def inner_run_photon_mosaic(workdir, configfile, timeout=None):
"""Helper function to run photon-mosaic CLI with dry-run.

timeout: seconds to wait for the subprocess to complete. If None,
wait indefinitely (no timeout).
"""
cmd = [
"photon-mosaic",
"--config",
str(configfile),
"--log-level",
"DEBUG",
]

result = subprocess.run(
cmd,
cwd=workdir,
capture_output=True,
text=True,
timeout=timeout,
encoding="utf-8",
errors="replace",
)

return result

return inner_run_photon_mosaic


@pytest.fixture
def test_data_root():
"""Return the path to test data directory."""
Expand Down Expand Up @@ -62,24 +94,6 @@ def metadata_base_config():
return config


@pytest.fixture
def map_of_tiffs():
"""
Create a map of tiffs in test data using rglob -
for backward compatibility with unit tests that use static data.
For integration tests, use the map_of_tiffs from snake_test_env instead.
"""

photon_mosaic_path = Path(__file__).parent / "data"
map_of_tiffs = {}
for dataset in photon_mosaic_path.glob("*"):
if dataset.is_dir():
# Get just the filenames, not the full paths
tiff_files = [f.name for f in dataset.rglob("*.tif")]
map_of_tiffs[dataset.name] = tiff_files
return map_of_tiffs


@pytest.fixture
def cli_args(snake_test_env):
"""
Expand Down
36 changes: 8 additions & 28 deletions tests/test_integration/test_whole_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,21 +244,11 @@ def test_snakemake_with_contrast(snake_test_env, test_config_with_contrast):
)


def test_photon_mosaic_cli_dry_run(snake_test_env):
def test_photon_mosaic_cli_dry_run(snake_test_env, run_photon_mosaic):
"""Test that photon-mosaic can do a dry run."""
cmd = [
"photon-mosaic",
"--config",
str(snake_test_env["configfile"]),
]

result = subprocess.run(
cmd,
cwd=snake_test_env["workdir"],
capture_output=True,
text=True,
encoding="utf-8",
errors="replace",
result = run_photon_mosaic(
snake_test_env["workdir"],
snake_test_env["configfile"],
)

assert result.returncode == 0, (
Expand All @@ -267,21 +257,11 @@ def test_photon_mosaic_cli_dry_run(snake_test_env):
)


def test_photon_mosaic_cli(snake_test_env):
def test_photon_mosaic_cli(snake_test_env, run_photon_mosaic):
"""Test photon-mosaic pipeline."""
cmd = [
"photon-mosaic",
"--config",
str(snake_test_env["configfile"]),
]

result = subprocess.run(
cmd,
cwd=snake_test_env["workdir"],
capture_output=True,
text=True,
encoding="utf-8",
errors="replace",
result = run_photon_mosaic(
snake_test_env["workdir"],
snake_test_env["configfile"],
)

assert result.returncode == 0, (
Expand Down
32 changes: 6 additions & 26 deletions tests/test_unit/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,13 @@

import re
import shutil
import subprocess
from pathlib import Path

import yaml

from photon_mosaic.dataset_discovery import DatasetDiscoverer


def run_photon_mosaic(workdir, configfile, timeout=None):
"""Helper function to run photon-mosaic CLI with dry-run.

timeout: seconds to wait for the subprocess to complete. If None,
wait indefinitely (no timeout).
"""
cmd = [
"photon-mosaic",
"--config",
str(configfile),
"--log-level",
"DEBUG",
]

result = subprocess.run(
cmd, cwd=workdir, capture_output=True, text=True, timeout=timeout
)

return result


class TestMetadataFunctionality:
"""Test class for metadata extraction functionality."""

Expand Down Expand Up @@ -206,7 +184,9 @@ def test_neuroblueprint_format_validation(self):
name, "sub"
), f"{name} should be invalid"

def test_photon_mosaic_cli_custom_metadata(self, custom_metadata_env):
def test_photon_mosaic_cli_custom_metadata(
self, custom_metadata_env, run_photon_mosaic
):
"""Test photon-mosaic CLI with custom metadata format."""
# Run photon-mosaic with dry-run to test metadata processing
result = run_photon_mosaic(
Expand All @@ -229,7 +209,7 @@ def test_photon_mosaic_cli_custom_metadata(self, custom_metadata_env):
), "Pipeline should complete successfully"

def test_photon_mosaic_cli_neuroblueprint_metadata(
self, neuroblueprint_env
self, neuroblueprint_env, run_photon_mosaic
):
"""Test photon-mosaic CLI with NeuroBlueprint metadata format."""
# Run photon-mosaic with dry-run to test metadata processing
Expand All @@ -253,7 +233,7 @@ def test_photon_mosaic_cli_neuroblueprint_metadata(
), "Pipeline should complete successfully with NeuroBlueprint format"

def test_noncontinuous_ids_preservation(
self, neuroblueprint_noncontinuous_env
self, neuroblueprint_noncontinuous_env, run_photon_mosaic
):
"""Test that non-continuous subject and session IDs are preserved."""
# local variables use module-level imports: re, Path
Expand Down Expand Up @@ -343,7 +323,7 @@ def test_noncontinuous_ids_preservation(
)

def test_alphanumeric_subject_and_session_ids(
self, tmp_path, metadata_base_config
self, tmp_path, metadata_base_config, run_photon_mosaic
):
"""Test that alphanumeric folder names are preserved in transformed
names.
Expand Down
Loading