From 0dc05b32b5c475608c58ab0c532dd4bb181d9b5d Mon Sep 17 00:00:00 2001 From: Chris Markiewicz Date: Wed, 15 May 2024 14:34:00 -0400 Subject: [PATCH] TEST: Get tests working --- src/fmripost_aroma/tests/conftest.py | 49 ++++++--------------------- src/fmripost_aroma/tests/test_base.py | 5 ++- tox.ini | 2 +- 3 files changed, 15 insertions(+), 41 deletions(-) diff --git a/src/fmripost_aroma/tests/conftest.py b/src/fmripost_aroma/tests/conftest.py index 16ee568..98738fe 100644 --- a/src/fmripost_aroma/tests/conftest.py +++ b/src/fmripost_aroma/tests/conftest.py @@ -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(): diff --git a/src/fmripost_aroma/tests/test_base.py b/src/fmripost_aroma/tests/test_base.py index 84f56cc..9dc8e64 100644 --- a/src/fmripost_aroma/tests/test_base.py +++ b/src/fmripost_aroma/tests/test_base.py @@ -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): @@ -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', diff --git a/tox.ini b/tox.ini index 945869d..2e8c1cc 100644 --- a/tox.ini +++ b/tox.ini @@ -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