From c525589e75525e775f725619654b152e159b1b5b Mon Sep 17 00:00:00 2001 From: lauraporta <29216006+lauraporta@users.noreply.github.com> Date: Tue, 18 Nov 2025 18:05:37 +0000 Subject: [PATCH 1/8] Use existing function to call photon mosaic --- tests/conftest.py | 22 +++++++++++++ tests/test_integration/test_whole_workflow.py | 33 ++++--------------- tests/test_unit/test_metadata.py | 23 +------------ 3 files changed, 30 insertions(+), 48 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 45cde49..900876a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -5,6 +5,7 @@ tests, following the DRY principle to avoid duplication. """ +import subprocess from datetime import datetime from pathlib import Path @@ -15,6 +16,27 @@ from tests.tree_helpers import tree as tree_lines +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 + + @pytest.fixture def test_data_root(): """Return the path to test data directory.""" diff --git a/tests/test_integration/test_whole_workflow.py b/tests/test_integration/test_whole_workflow.py index 38f0869..75216ef 100644 --- a/tests/test_integration/test_whole_workflow.py +++ b/tests/test_integration/test_whole_workflow.py @@ -8,6 +8,7 @@ from tifffile import imread from photon_mosaic import get_snakefile_path +from tests.conftest import run_photon_mosaic def run_snakemake(workdir, configfile, dry_run=False): @@ -246,19 +247,9 @@ def test_snakemake_with_contrast(snake_test_env, test_config_with_contrast): def test_photon_mosaic_cli_dry_run(snake_test_env): """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, ( @@ -269,19 +260,9 @@ def test_photon_mosaic_cli_dry_run(snake_test_env): def test_photon_mosaic_cli(snake_test_env): """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..74318c4 100644 --- a/tests/test_unit/test_metadata.py +++ b/tests/test_unit/test_metadata.py @@ -7,33 +7,12 @@ 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 +from tests.conftest import run_photon_mosaic class TestMetadataFunctionality: From cec980f7f593d9e9c37471354880ae49f068a1e8 Mon Sep 17 00:00:00 2001 From: lauraporta <29216006+lauraporta@users.noreply.github.com> Date: Tue, 18 Nov 2025 18:14:19 +0000 Subject: [PATCH 2/8] Remove unused fixture --- tests/conftest.py | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 900876a..fcd06d7 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -83,25 +83,7 @@ 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 - - -def create_map_of_tiffs(raw_data_path: Path) -> dict: +def _create_map_of_tiffs(raw_data_path: Path) -> dict: """ Create a map of tiffs for a given raw data directory. @@ -174,7 +156,7 @@ def snake_test_env(tmp_path, base_config, data_factory): print(f"Config file created at: {config_path}") # Generate map of tiffs from the dynamically created data - map_of_tiffs = create_map_of_tiffs(raw_data) + map_of_tiffs = _create_map_of_tiffs(raw_data) print(f"Generated map_of_tiffs: {map_of_tiffs}") print("=== End of test environment setup ===\n") From 90e425bda410b8e8a3a068a60d228cb0490e08e7 Mon Sep 17 00:00:00 2001 From: lauraporta <29216006+lauraporta@users.noreply.github.com> Date: Tue, 18 Nov 2025 18:16:37 +0000 Subject: [PATCH 3/8] Remove underscore --- tests/conftest.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index fcd06d7..ed53f66 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -83,7 +83,7 @@ def metadata_base_config(): return config -def _create_map_of_tiffs(raw_data_path: Path) -> dict: +def create_map_of_tiffs(raw_data_path: Path) -> dict: """ Create a map of tiffs for a given raw data directory. @@ -156,7 +156,7 @@ def snake_test_env(tmp_path, base_config, data_factory): print(f"Config file created at: {config_path}") # Generate map of tiffs from the dynamically created data - map_of_tiffs = _create_map_of_tiffs(raw_data) + map_of_tiffs = create_map_of_tiffs(raw_data) print(f"Generated map_of_tiffs: {map_of_tiffs}") print("=== End of test environment setup ===\n") From 5843ae5437211be55b4d6ea4063734a93edc6638 Mon Sep 17 00:00:00 2001 From: lauraporta <29216006+lauraporta@users.noreply.github.com> Date: Fri, 6 Mar 2026 13:45:14 +0000 Subject: [PATCH 4/8] Transform the function in a proper fixture --- tests/conftest.py | 38 ++++++++++--------- tests/test_integration/test_whole_workflow.py | 5 +-- tests/test_unit/test_metadata.py | 11 +++--- 3 files changed, 29 insertions(+), 25 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 025f502..3d34b04 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -17,25 +17,29 @@ from tests.tree_helpers import tree as tree_lines -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", - ] +@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 + ) - result = subprocess.run( - cmd, cwd=workdir, capture_output=True, text=True, timeout=timeout - ) + return result - return result + return inner_run_photon_mosaic @pytest.fixture diff --git a/tests/test_integration/test_whole_workflow.py b/tests/test_integration/test_whole_workflow.py index 75216ef..c45c618 100644 --- a/tests/test_integration/test_whole_workflow.py +++ b/tests/test_integration/test_whole_workflow.py @@ -8,7 +8,6 @@ from tifffile import imread from photon_mosaic import get_snakefile_path -from tests.conftest import run_photon_mosaic def run_snakemake(workdir, configfile, dry_run=False): @@ -245,7 +244,7 @@ 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.""" result = run_photon_mosaic( snake_test_env["workdir"], @@ -258,7 +257,7 @@ 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.""" result = run_photon_mosaic( snake_test_env["workdir"], diff --git a/tests/test_unit/test_metadata.py b/tests/test_unit/test_metadata.py index 74318c4..adda669 100644 --- a/tests/test_unit/test_metadata.py +++ b/tests/test_unit/test_metadata.py @@ -12,7 +12,6 @@ import yaml from photon_mosaic.dataset_discovery import DatasetDiscoverer -from tests.conftest import run_photon_mosaic class TestMetadataFunctionality: @@ -185,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( @@ -208,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 @@ -232,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 @@ -322,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. From 3dc8f0b8b543e5bae59df9a0ab2c53ac4898ffd1 Mon Sep 17 00:00:00 2001 From: lauraporta <29216006+lauraporta@users.noreply.github.com> Date: Fri, 6 Mar 2026 13:59:39 +0000 Subject: [PATCH 5/8] Fix change in suite2p link in docs --- docs/source/user_guide/configuration.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/user_guide/configuration.md b/docs/source/user_guide/configuration.md index c441b27..686f479 100644 --- a/docs/source/user_guide/configuration.md +++ b/docs/source/user_guide/configuration.md @@ -110,7 +110,7 @@ Choose the value of `anatomical_only` based on the following table: | 3 | Use enhanced mean image | | 4 | Use maximum projection image | -For a complete list of all available Suite2p parameters, refer to the [official Suite2p documentation](https://suite2p.readthedocs.io/en/latest/settings.html). +For a complete list of all available Suite2p parameters, refer to the [official Suite2p documentation](https://suite2p.readthedocs.io/en/latest/parameters/). #### Cellpose 3 vs Cellpose 4 Photon-mosaic uses Cellpose 4 by default, with `cpsam` model. If you want to use Cellpose 3, you can uninstall the Cellpose 4 from your conda environment and install Cellpose 3: `pip uninstall cellpose` and `pip install cellpose==3.0.0`. In such a case remember to change the `flow_threshold` to 1.5. From 473f98f75866bfa53c7437a80c5839aabec7d993 Mon Sep 17 00:00:00 2001 From: Alessandro Felder Date: Fri, 6 Mar 2026 14:55:32 +0000 Subject: [PATCH 6/8] Set shell to bash for test action Specify bash as the shell for the test action. --- .github/workflows/test_and_deploy.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test_and_deploy.yml b/.github/workflows/test_and_deploy.yml index 2da77e0..50f01ff 100644 --- a/.github/workflows/test_and_deploy.yml +++ b/.github/workflows/test_and_deploy.yml @@ -40,6 +40,7 @@ jobs: # Run tests - uses: neuroinformatics-unit/actions/test@v2 with: + shell: bash python-version: ${{ matrix.python-version }} build_sdist_wheels: From 006a2f6f2254e6665402ed524bd161ab2274f733 Mon Sep 17 00:00:00 2001 From: alessandrofelder Date: Tue, 10 Mar 2026 16:24:14 +0000 Subject: [PATCH 7/8] revert unsuccessful speculative setting of bash shell --- .github/workflows/test_and_deploy.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/test_and_deploy.yml b/.github/workflows/test_and_deploy.yml index 50f01ff..2da77e0 100644 --- a/.github/workflows/test_and_deploy.yml +++ b/.github/workflows/test_and_deploy.yml @@ -40,7 +40,6 @@ jobs: # Run tests - uses: neuroinformatics-unit/actions/test@v2 with: - shell: bash python-version: ${{ matrix.python-version }} build_sdist_wheels: From 78b98d917c0171ab552f4db0ad234e34965b939d Mon Sep 17 00:00:00 2001 From: alessandrofelder Date: Tue, 10 Mar 2026 16:54:14 +0000 Subject: [PATCH 8/8] restore subprocess options that existed before --- tests/conftest.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index 3d34b04..4a2cf3f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -34,7 +34,13 @@ def inner_run_photon_mosaic(workdir, configfile, timeout=None): ] result = subprocess.run( - cmd, cwd=workdir, capture_output=True, text=True, timeout=timeout + cmd, + cwd=workdir, + capture_output=True, + text=True, + timeout=timeout, + encoding="utf-8", + errors="replace", ) return result