Skip to content

Commit

Permalink
parametrise integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sfmig committed Dec 7, 2023
1 parent 233c3df commit 8dd1374
Showing 1 changed file with 94 additions and 25 deletions.
119 changes: 94 additions & 25 deletions tests/test_integration/brainglobe_workflows/test_cellfinder.py
Original file line number Diff line number Diff line change
@@ -1,92 +1,161 @@
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
# (cellfinder cache directory is created in cwd)
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
Expand Down

0 comments on commit 8dd1374

Please sign in to comment.