Skip to content

Commit

Permalink
cosmetic changes to fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
sfmig committed Dec 21, 2023
1 parent 2f284ba commit bbc2274
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 46 deletions.
32 changes: 2 additions & 30 deletions tests/cellfinder_core/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,14 @@

import pytest

# @pytest.fixture()
# def default_input_config_cellfinder() -> Path: # do I need this?
# """Return path to default input config for cellfinder workflow

# Returns
# -------
# Path
# Path to default input config

# """
# from brainglobe_workflows.utils import
# DEFAULT_JSON_CONFIG_PATH_CELLFINDER

# return DEFAULT_JSON_CONFIG_PATH_CELLFINDER


@pytest.fixture(autouse=True)
def mock_home_directory(monkeypatch: pytest.MonkeyPatch):
# define mock home path
home_path = Path.home() # actual home path
mock_home_path = home_path / ".brainglobe-tests" # tmp_path #
mock_home_path = home_path / ".brainglobe-tests"

# create dir if it doesn't exist
# create directory if it doesn't exist
if not mock_home_path.exists():
mock_home_path.mkdir()

Expand All @@ -36,16 +21,3 @@ def mock_home():
return mock_home_path

monkeypatch.setattr(Path, "home", mock_home)


# @pytest.fixture() # Do I need this?
# def input_configs_dir() -> Path:
# """Return the directory path to the input configs
# used for testing

# Returns
# -------
# Path
# Test data directory path
# """
# return Path(__file__).parents[1] / "data"
83 changes: 67 additions & 16 deletions tests/cellfinder_core/test_unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,26 @@ def cellfinder_GIN_data() -> dict:


@pytest.fixture()
def config_GIN_dict(cellfinder_GIN_data):
def config_GIN_dict(cellfinder_GIN_data: dict) -> dict:
"""
Return a config pointing to the location where GIN would be by default
Return a config pointing to the location where GIN would be by default,
and download the data
"""

# read default config as dict
# read default config as a dictionary
with open(DEFAULT_JSON_CONFIG_PATH_CELLFINDER) as cfg:
config_dict = json.load(cfg)

# modify / ensure
# modify
# - add url
# - add data hash
# - remove input_data_dir
# - remove input_data_dir if present
config_dict["data_url"] = cellfinder_GIN_data["url"]
config_dict["data_hash"] = cellfinder_GIN_data["hash"]
if "input_data_dir" in config_dict.keys():
del config_dict["input_data_dir"]

# download data to default location for GIN
# download GIN data to default location for GIN
pooch.retrieve(
url=cellfinder_GIN_data["url"],
known_hash=cellfinder_GIN_data["hash"],
Expand All @@ -71,42 +72,49 @@ def config_GIN_dict(cellfinder_GIN_data):


@pytest.fixture()
def config_force_GIN_dict(cellfinder_GIN_data, tmp_path):
def config_force_GIN_dict(cellfinder_GIN_data: dict, tmp_path: Path) -> dict:
"""
Return a config pointing to the location where GIN would be by default
Return a config pointing to a temporary directory where to download GIN
data, without downloading the data first.
Since there is no data at the input_data_dir location, the GIN download
will be triggered
"""
# read default config as dict
with open(DEFAULT_JSON_CONFIG_PATH_CELLFINDER) as cfg:
config_dict = json.load(cfg)

# modify
# - add url
# - add data hash
# - point to a temporary directory in input_data_dir
config_dict["data_url"] = cellfinder_GIN_data["url"]
config_dict["data_hash"] = cellfinder_GIN_data["hash"]
config_dict["input_data_dir"] = tmp_path
# since the input_data_dir does not exist, it will
# download the GIN data there

return config_dict


@pytest.fixture()
def config_local_dict(cellfinder_GIN_data):
""" """
def config_local_dict(cellfinder_GIN_data: dict) -> dict:
"""
Return a config pointing to a local dataset,
and ensure the data is downloaded there
"""

# read default config as dict
# as dict because some paths are computed derived from input_data_dir
with open(DEFAULT_JSON_CONFIG_PATH_CELLFINDER) as cfg:
config_dict = json.load(cfg)

# modify dict
# - remove url
# - remove data hash
# - add input_data_dir
# - point to a local directory under home in input_data_dir
config_dict["data_url"] = None
config_dict["data_hash"] = None
config_dict["input_data_dir"] = Path.home() / "local_cellfinder_data"

# fetch data from GIN and download locally to local location?
# fetch data from GIN and download to the local location
pooch.retrieve(
url=cellfinder_GIN_data["url"],
known_hash=cellfinder_GIN_data["hash"],
Expand All @@ -123,7 +131,21 @@ def config_local_dict(cellfinder_GIN_data):


@pytest.fixture()
def config_missing_signal_dict(config_local_dict):
def config_missing_signal_dict(config_local_dict: dict) -> dict:
"""
Return a config pointing to a local dataset, whose signal directory
does not exist
Parameters
----------
config_local_dict : _type_
_description_
Returns
-------
dict
_description_
"""
config_dict = config_local_dict.copy()
config_dict["signal_subdir"] = "_"

Expand All @@ -132,6 +154,19 @@ def config_missing_signal_dict(config_local_dict):

@pytest.fixture()
def config_missing_background_dict(config_local_dict):
"""Return a config pointing to a local dataset, whose background directory
does not exist
Parameters
----------
config_local_dict : _type_
_description_
Returns
-------
_type_
_description_
"""
config_dict = config_local_dict.copy()
config_dict["background_subdir"] = "_"

Expand All @@ -140,7 +175,23 @@ def config_missing_background_dict(config_local_dict):

@pytest.fixture()
def config_not_GIN_nor_local_dict(config_local_dict):
"""Return a config pointing to a local dataset whose input_data_dir
directory does not exist, and with no references to a GIN dataset.
Parameters
----------
config_local_dict : _type_
_description_
Returns
-------
_type_
_description_
"""
config_dict = config_local_dict.copy()
config_dict["input_data_dir"] = "_"

config_dict["data_url"] = None
config_dict["data_hash"] = None

return config_dict

0 comments on commit bbc2274

Please sign in to comment.