diff --git a/tests/conftest.py b/tests/conftest.py index 7af199e..4a2cf3f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -6,6 +6,7 @@ """ import argparse +import subprocess from datetime import datetime from pathlib import Path @@ -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.""" @@ -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): """ diff --git a/tests/test_integration/test_whole_workflow.py b/tests/test_integration/test_whole_workflow.py index 38f0869..c45c618 100644 --- a/tests/test_integration/test_whole_workflow.py +++ b/tests/test_integration/test_whole_workflow.py @@ -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, ( @@ -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, ( diff --git a/tests/test_unit/test_metadata.py b/tests/test_unit/test_metadata.py index 2f922b5..adda669 100644 --- a/tests/test_unit/test_metadata.py +++ b/tests/test_unit/test_metadata.py @@ -7,7 +7,6 @@ import re import shutil -import subprocess from pathlib import Path import yaml @@ -15,27 +14,6 @@ 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.""" @@ -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( @@ -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 @@ -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 @@ -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.