From 8dd13744966bbb03362fdfefec01234118411736 Mon Sep 17 00:00:00 2001 From: sfmig <33267254+sfmig@users.noreply.github.com> Date: Thu, 7 Dec 2023 15:54:51 +0000 Subject: [PATCH] parametrise integration tests --- .../brainglobe_workflows/test_cellfinder.py | 119 ++++++++++++++---- 1 file changed, 94 insertions(+), 25 deletions(-) diff --git a/tests/test_integration/brainglobe_workflows/test_cellfinder.py b/tests/test_integration/brainglobe_workflows/test_cellfinder.py index 55e8b03d..a61f2316 100644 --- a/tests/test_integration/brainglobe_workflows/test_cellfinder.py +++ b/tests/test_integration/brainglobe_workflows/test_cellfinder.py @@ -1,22 +1,39 @@ import subprocess import sys from pathlib import Path +from typing import Optional import pytest from brainglobe_workflows.cellfinder import main -# TODO: test main with default and custom json (local and GIN)? -def test_main(monkeypatch: pytest.MonkeyPatch, tmp_path: Path): +@pytest.mark.parametrize( + "input_config", + [ + None, + "input_config_fetch_GIN", + "input_config_fetch_local", + ], +) +def test_main( + input_config: Optional[str], + monkeypatch: pytest.MonkeyPatch, + tmp_path: Path, + request: pytest.FixtureRequest, +): """Test main function for setting up and running cellfinder workflow Parameters ---------- + input_config : Optional[str] + Path to input config json file monkeypatch : pytest.MonkeyPatch Pytest fixture to use monkeypatching utils tmp_path : Path Pytest fixture providing a temporary path for each test + request : pytest.FixtureRequest + Pytest fixture to enable requesting fixtures by name """ # monkeypatch to change current directory to # pytest temporary directory @@ -24,69 +41,121 @@ def test_main(monkeypatch: pytest.MonkeyPatch, tmp_path: Path): monkeypatch.chdir(tmp_path) # run main - cfg = main() + if not input_config: + cfg = main() # use default config + else: + cfg = main(str(request.getfixturevalue(input_config))) - # check output files are those expected? + # check output files exist assert (cfg.detected_cells_path).is_file() -# TODO: test main CLI with default and specific json? -def test_app_wrapper(monkeypatch: pytest.MonkeyPatch, tmp_path: Path): +@pytest.mark.parametrize( + "input_config", + [ + None, + "input_config_fetch_GIN", + "input_config_fetch_local", + ], +) +def test_app_wrapper( + input_config: Optional[str], + monkeypatch: pytest.MonkeyPatch, + tmp_path: Path, + request: pytest.FixtureRequest, +): """Test running the cellfinder worklfow from the command line Parameters ---------- + input_config : Optional[str] + Path to input config json file monkeypatch : pytest.MonkeyPatch Pytest fixture to use monkeypatching utils tmp_path : Path Pytest fixture providing a temporary path for each test + request : pytest.FixtureRequest + Pytest fixture to enable requesting fixtures by name """ # monkeypatch to change current directory to # pytest temporary directory # (cellfinder cache directory is created in cwd) monkeypatch.chdir(tmp_path) - # run workflow script with no CLI arguments, + # define CLI input + script_path = ( + Path(__file__).resolve().parents[3] + / "brainglobe_workflows" + / "cellfinder.py" + ) + subprocess_input = [ + sys.executable, + str(script_path), + ] + # append config if required + if input_config: + subprocess_input.append("--config") + subprocess_input.append(str(request.getfixturevalue(input_config))) + + # run workflow script from the CLI subprocess_output = subprocess.run( - [ - sys.executable, - Path(__file__).resolve().parents[3] - / "brainglobe_workflows" - / "cellfinder.py", - ], - stdout=subprocess.PIPE, - stderr=subprocess.STDOUT, - text=True, - encoding="utf-8", + subprocess_input, + # stdout=subprocess.PIPE, + # stderr=subprocess.STDOUT, + # text=True, + # encoding="utf-8", ) # check returncode assert subprocess_output.returncode == 0 -# TODO: test main CLI with default and specific json? -def test_main_entry_point(monkeypatch: pytest.MonkeyPatch, tmp_path: Path): +@pytest.mark.parametrize( + "input_config", + [ + None, + "input_config_fetch_GIN", + "input_config_fetch_local", + ], +) +def test_main_entry_point( + input_config: Optional[str], + monkeypatch: pytest.MonkeyPatch, + tmp_path: Path, + request: pytest.FixtureRequest, +): """Test running the cellfinder workflow via the predefined entry point Parameters ---------- + input_config : Optional[str] + Path to input config json file monkeypatch : pytest.MonkeyPatch Pytest fixture to use monkeypatching utils tmp_path : Path Pytest fixture providing a temporary path for each test + request : pytest.FixtureRequest + Pytest fixture to enable requesting fixtures by name """ - # monkeypatch to change current directory to + # monkeypatch to change current directory to # pytest temporary directory # (cellfinder cache directory is created in cwd) monkeypatch.chdir(tmp_path) + # define CLI input + subprocess_input = ["cellfinder-workflow"] + # append config if required + if input_config: + subprocess_input.append("--config") + subprocess_input.append(str(request.getfixturevalue(input_config))) + # run workflow with no CLI arguments, subprocess_output = subprocess.run( - ["cellfinder-workflow"], - stdout=subprocess.PIPE, - stderr=subprocess.STDOUT, - text=True, - encoding="utf-8", + subprocess_input, + # stdout=subprocess.PIPE, + # stderr=subprocess.STDOUT, + # text=True, + # encoding="utf-8", ) # check returncode