Skip to content

Commit

Permalink
Set FreeSurfer license as pytest fixture (#801)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsalo authored Feb 14, 2023
1 parent 004eaef commit 99798ed
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 27 deletions.
1 change: 0 additions & 1 deletion .circleci/RunPyTests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ get_bids_data ${TESTDIR} sub01
get_bids_data ${TESTDIR} ds001419-fmriprep

CFG=${TESTDIR}/data/nipype.cfg
export FS_LICENSE=${TESTDIR}/data/license.txt

TESTNAME=run_pytest
setup_dir ${TESTDIR}/${TESTNAME}
Expand Down
11 changes: 1 addition & 10 deletions .circleci/get_data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,6 @@ run_xcpd_cmd () {
cfg_arg="-v ${CFG}:/nipype/nipype.cfg --env NIPYPE_CONFIG_DIR=/nipype"
fi

# Is there a Freesurfer license?
fslicense_arg=""
FS_LICENSE=$(printenv FS_LICENSE)
if [[ -n "${FS_LICENSE}" ]]; then
fslicense_arg="-v ${FS_LICENSE}:/license.txt --env FS_LICENSE=/license.txt"
fi

# Is there a BIDS filter file?
bids_filter_file_arg=""
BIDS_FILTER_FILE=$(printenv BIDS_FILTER_FILE)
Expand All @@ -94,7 +87,7 @@ run_xcpd_cmd () {
output_mount="-v ${output_dir}:/out:rw"
workdir_mount="-v ${workdir}:/work:rw"

XCPD_RUN="docker run --rm -u $(id -u) ${workdir_mount} ${patch_mount} ${cfg_arg} ${fslicense_arg} ${bids_filter_file_arg} ${bids_mount} ${output_mount} ${IMAGE} /bids-input/${bids_folder_name} /out participant -w /work"
XCPD_RUN="docker run --rm -u $(id -u) ${workdir_mount} ${patch_mount} ${cfg_arg} ${bids_filter_file_arg} ${bids_mount} ${output_mount} ${IMAGE} /bids-input/${bids_folder_name} /out participant -w /work"

fi
echo "${XCPD_RUN} --nthreads ${NTHREADS} --omp-nthreads ${OMP_NTHREADS}"
Expand All @@ -112,8 +105,6 @@ Default data:
data/nipype.cfg
Instructs nipype to stop on the first crash
data/license.txt
A freesurfer license file
DOC

Expand Down
33 changes: 25 additions & 8 deletions xcp_d/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Fixtures for the CircleCI tests."""
import base64
import os

import pytest
Expand All @@ -12,25 +13,29 @@ def pytest_addoption(parser):


# Set up the commandline options as fixtures
@pytest.fixture
@pytest.fixture(scope="session")
def data_dir(request):
"""Grab data directory."""
return request.config.getoption("--data_dir")


@pytest.fixture
@pytest.fixture(scope="session")
def working_dir(request):
"""Grab working directory."""
return request.config.getoption("--working_dir")
workdir = request.config.getoption("--working_dir")
os.makedirs(workdir, exist_ok=True)
return workdir


@pytest.fixture
@pytest.fixture(scope="session")
def output_dir(request):
"""Grab output directory."""
return request.config.getoption("--output_dir")
outdir = request.config.getoption("--output_dir")
os.makedirs(outdir, exist_ok=True)
return outdir


@pytest.fixture
@pytest.fixture(scope="session")
def datasets(data_dir):
"""Locate downloaded datasets."""
dsets = {}
Expand All @@ -43,7 +48,7 @@ def datasets(data_dir):
return dsets


@pytest.fixture
@pytest.fixture(scope="session")
def fmriprep_with_freesurfer_data(datasets):
"""Collect a list of files from ds001419 that will be used by misc. tests."""
subj_dir = os.path.join(datasets["ds001419"], "sub-01")
Expand Down Expand Up @@ -93,7 +98,7 @@ def fmriprep_with_freesurfer_data(datasets):
return files


@pytest.fixture
@pytest.fixture(scope="session")
def fmriprep_without_freesurfer_data(datasets):
"""Collect a list of fmriprepwithoutfreesurfer files that will be used by misc. tests."""
subj_dir = os.path.join(datasets["fmriprep_without_freesurfer"], "sub-01")
Expand All @@ -118,3 +123,15 @@ def fmriprep_without_freesurfer_data(datasets):
)

return files


@pytest.fixture(scope="session", autouse=True)
def fslicense(working_dir):
"""Set the FreeSurfer license as an environment variable."""
FS_LICENSE = os.path.join(working_dir, "license.txt")
os.environ["FS_LICENSE"] = FS_LICENSE
LICENSE_CODE = (
"bWF0dGhldy5jaWVzbGFrQHBzeWNoLnVjc2IuZWR1CjIwNzA2CipDZmVWZEg1VVQ4clkKRlNCWVouVWtlVElDdwo="
)
with open(FS_LICENSE, "w") as f:
f.write(base64.b64decode(LICENSE_CODE).decode())
4 changes: 0 additions & 4 deletions xcp_d/tests/data/license.txt

This file was deleted.

4 changes: 0 additions & 4 deletions xcp_d/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ def test_ds001419_nifti(datasets, output_dir, working_dir):
work_dir = os.path.join(working_dir, test_name)

test_data_dir = get_test_data_path()
os.environ["FS_LICENSE"] = os.path.join(test_data_dir, "license.txt")
filter_file = os.path.join(test_data_dir, "ds001419-fmriprep_nifti_filter.json")

parameters = [
Expand Down Expand Up @@ -85,7 +84,6 @@ def test_ds001419_cifti(datasets, output_dir, working_dir):
work_dir = os.path.join(working_dir, test_name)

test_data_dir = get_test_data_path()
os.environ["FS_LICENSE"] = os.path.join(test_data_dir, "license.txt")
filter_file = os.path.join(test_data_dir, "ds001419-fmriprep_cifti_filter.json")

parameters = [
Expand Down Expand Up @@ -163,7 +161,6 @@ def test_fmriprep_without_freesurfer(datasets, output_dir, working_dir):
os.makedirs(custom_confounds_dir, exist_ok=True)

test_data_dir = get_test_data_path()
os.environ["FS_LICENSE"] = os.path.join(test_data_dir, "license.txt")

# Create custom confounds folder
for run in [1, 2]:
Expand Down Expand Up @@ -214,7 +211,6 @@ def test_nibabies(datasets, output_dir, working_dir):
work_dir = os.path.join(working_dir, test_name)

test_data_dir = get_test_data_path()
os.environ["FS_LICENSE"] = os.path.join(test_data_dir, "license.txt")

parameters = [
data_dir,
Expand Down

0 comments on commit 99798ed

Please sign in to comment.