Skip to content

Commit

Permalink
TEST: Get tests working
Browse files Browse the repository at this point in the history
  • Loading branch information
effigies committed May 15, 2024
1 parent 774e0e2 commit 0dc05b3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 41 deletions.
49 changes: 10 additions & 39 deletions src/fmripost_aroma/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,64 +1,35 @@
"""Fixtures for the CircleCI tests."""

import base64
import importlib.resources
import os

import pytest


def pytest_addoption(parser):
"""Collect pytest parameters for running tests."""
parser.addoption(
'--data_dir',
action='store',
default='/home/runner/work/fmripost-aroma/fmripost-aroma/src/fmripost_aroma/tests/data',
)
parser.addoption(
'--output_dir',
action='store',
default='/home/runner/work/pytests/out',
)
parser.addoption(
'--working_dir',
action='store',
default='/home/runner/work/pytests/work',
)


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


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


@pytest.fixture(scope='session')
def output_dir(request):
"""Grab output directory."""
outdir = request.config.getoption('--output_dir')
os.makedirs(outdir, exist_ok=True)
return outdir
test_data = importlib.resources.files('fmripost_aroma.tests') / 'data'
with importlib.resources.as_file(test_data) as data:
yield data


@pytest.fixture(scope='session', autouse=True)
def _fslicense(working_dir):
def _fslicense(tmp_path_factory):
"""Set the FreeSurfer license as an environment variable."""
working_dir = tmp_path_factory.mktemp('fslicense')
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())

os.putenv('FS_LICENSE', FS_LICENSE)
return


@pytest.fixture(scope='session')
def base_config():
Expand Down
5 changes: 4 additions & 1 deletion src/fmripost_aroma/tests/test_base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Tests for fmripost_aroma.workflows."""

from fmripost_aroma import config
from fmripost_aroma.tests.tests import mock_config
from fmriprep.workflows.tests import mock_config


def test_init_ica_aroma_wf(tmp_path_factory):
Expand All @@ -12,6 +12,9 @@ def test_init_ica_aroma_wf(tmp_path_factory):
with mock_config():
config.workflow.fmripost_aroma_dir = tempdir / 'out'
config.workflow.work_dir = tempdir / 'work'
config.workflow.denoise_method = ['nonaggr', 'orthaggr']
config.workflow.melodic_dim = -200
config.workflow.err_on_warn = False

wf = init_ica_aroma_wf(
bold_file='sub-01_task-rest_bold.nii.gz',
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ deps =
min: pybids ==0.15.6
commands =
pytest --doctest-modules --cov fmripost_aroma --cov-report xml \
--junitxml=test-results.xml -v src/fmripost_aroma
--junitxml=test-results.xml -v src/fmripost_aroma {posargs}

[testenv:docs]
description = Build documentation site
Expand Down

0 comments on commit 0dc05b3

Please sign in to comment.