diff --git a/.github/workflows/run_tests_notebooks.yml b/.github/workflows/run_tests_notebooks.yml index 0395a246b..68dfa2382 100644 --- a/.github/workflows/run_tests_notebooks.yml +++ b/.github/workflows/run_tests_notebooks.yml @@ -33,7 +33,7 @@ jobs: uses: matlab-actions/setup-matlab@v1.2.4 with: # MATLAB release to set up R2020a - release: R2020a + release: R2023a - name: Clone bidspm uses: actions/checkout@v3 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 4a0f53d3c..7dcbee1b3 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -41,28 +41,28 @@ jobs: test_type: [system] script: [moae, facerep, fmriprep] os: [ubuntu-latest, macos-latest] - matlab: [R2022b] + matlab: [R2023a] include: # only run bms on ubuntu because of datalad setup - test_type: system os: ubuntu-latest - matlab: R2022b + matlab: R2023a script: bms - test_type: unit os: ubuntu-latest - matlab: R2022b + matlab: R2023a mode: fast - test_type: unit os: macos-latest - matlab: R2022b + matlab: R2023a mode: fast - test_type: unit os: ubuntu-latest - matlab: R2022b + matlab: R2023a mode: slow - test_type: unit os: macos-latest - matlab: R2022b + matlab: R2023a mode: slow fail-fast: false diff --git a/.github/workflows/tests_windows.yml b/.github/workflows/tests_windows.yml index c4de4fc90..3fb4bf515 100644 --- a/.github/workflows/tests_windows.yml +++ b/.github/workflows/tests_windows.yml @@ -39,17 +39,17 @@ jobs: strategy: matrix: test_type: [system] - script: [moae, facerep, fmriprep] + script: [moae, fmriprep] os: [windows-latest] - matlab: [R2022b] + matlab: [R2023a] include: - test_type: unit os: windows-latest - matlab: R2022b + matlab: R2023a mode: fast - test_type: unit os: windows-latest - matlab: R2022b + matlab: R2023a mode: slow fail-fast: false diff --git a/bidspm.m b/bidspm.m index 6dc1eba84..a04fc091a 100644 --- a/bidspm.m +++ b/bidspm.m @@ -325,6 +325,8 @@ function uninitBidspm() end testFolder = fullfile(pwd, 'tests', subfolder); + generateLayoutMat(); + returnCode = moxunit_runtests(testFolder, ... '-verbose', '-recursive', '-randomize_order', ... '-with_coverage', ... diff --git a/demos/face_repetition/test_face_rep.m b/demos/face_repetition/test_face_rep.m index 04e514fc3..4700b962e 100644 --- a/demos/face_repetition/test_face_rep.m +++ b/demos/face_repetition/test_face_rep.m @@ -9,12 +9,10 @@ clc; close all; -% skipping validation for now -% as raw data is not 100% valid -skip_validation = true; - download_data = true; +VERBOSITY = 0; + WD = fileparts(mfilename('fullpath')); addpath(fullfile(WD, '..', '..')); @@ -69,8 +67,8 @@ 'task', 'facerepetition', ... 'space', {'IXI549Space'}, ... 'ignore', ignore, ... - 'options', opt, ... - 'skip_validation', skip_validation); + 'verbosity', VERBOSITY, ... + 'options', opt); %% stats @@ -106,7 +104,7 @@ 'preproc_dir', [preproc_dir '-preproc'], ... 'model_file', newModel, ... 'options', opt, ... - 'skip_validation', skip_validation, ... + 'verbosity', VERBOSITY, ... 'concatenate', true); end diff --git a/src/IO/saveSpmScript.m b/src/IO/saveSpmScript.m index 140fb34a3..3aaba7f8b 100644 --- a/src/IO/saveSpmScript.m +++ b/src/IO/saveSpmScript.m @@ -8,8 +8,9 @@ % % :param input: a ``matlabbatch`` variable (cell) or the fullpath to a ``.mat`` file % containing such ``matlabbatch`` variable. + % % :param outputFilename: optional. Path to output file - % :type outputFilename: path + % :type outputFilename: path % % :returns: - :outputFilename: (path) % diff --git a/src/stats/subject_level/getConfoundsRegressorFilename.m b/src/stats/subject_level/getConfoundsRegressorFilename.m index a47952854..ce4d6a338 100644 --- a/src/stats/subject_level/getConfoundsRegressorFilename.m +++ b/src/stats/subject_level/getConfoundsRegressorFilename.m @@ -37,13 +37,13 @@ if numel(filenames) > 1 msg = ['Found several confounds files:', ... - bids.internal.create_unordered_list(filenames)]; + bids.internal.create_unordered_list(bids.internal.format_path(filenames))]; id = 'tooManyFiles'; logger('WARNING', msg, 'id', id, 'filename', mfilename(), 'options', opt); elseif isempty(filenames) msg = sprintf('No TSV file found in:\n\t%s\nfor query:%s\n', ... - BIDS.pth, ... + bids.internal.format_path(BIDS.pth), ... bids.internal.create_unordered_list(opt.query)); id = 'noFileFound'; logger('WARNING', msg, 'id', id, 'filename', mfilename(), 'options', opt); diff --git a/src/workflows/bidsQApreproc.m b/src/workflows/bidsQApreproc.m index 2cbf8e00c..d77a749a0 100644 --- a/src/workflows/bidsQApreproc.m +++ b/src/workflows/bidsQApreproc.m @@ -34,6 +34,7 @@ function bidsQApreproc(opt) [BIDS, opt] = setUpWorkflow(opt, 'preprocessing quality control'); + visible = 'off'; if opt.verbosity > 1 visible = 'on'; end diff --git a/tests/tests_batches/preproc/test_setBatchSTC.m b/tests/tests_batches/preproc/test_setBatchSTC.m index 5c4478d36..528d6a66c 100644 --- a/tests/tests_batches/preproc/test_setBatchSTC.m +++ b/tests/tests_batches/preproc/test_setBatchSTC.m @@ -5,9 +5,7 @@ test_functions = localfunctions(); %#ok<*NASGU> catch % no problem; early Matlab versions can use initTestSuite fine end - initTestSuite; - end function test_setBatchSTC_dual_task() diff --git a/tests/tests_batches/stats/test_setBatchSubjectLevelContrasts.m b/tests/tests_batches/stats/test_setBatchSubjectLevelContrasts.m index 5ce986e47..b096fd336 100644 --- a/tests/tests_batches/stats/test_setBatchSubjectLevelContrasts.m +++ b/tests/tests_batches/stats/test_setBatchSubjectLevelContrasts.m @@ -10,9 +10,6 @@ function test_setBatchSubjectLevelContrasts_F_contrast() - % TODO: fixturize - createDummyData(); - subLabel = '01'; opt = setOptions('vismotion', subLabel, 'pipelineType', 'stats'); @@ -46,9 +43,6 @@ function test_setBatchSubjectLevelContrasts_F_contrast() function test_setBatchSubjectLevelContrasts_basic() - % TODO: fixturize - createDummyData(); - subLabel = '01'; opt = setOptions('vismotion', subLabel, 'pipelineType', 'stats'); @@ -106,9 +100,6 @@ function test_setBatchSubjectLevelContrasts_basic() function test_setBatchSubjectLevelContrasts_select_node() - % TODO: fixturize - createDummyData(); - subLabel = '01'; opt = setOptions('vismotion', subLabel, 'pipelineType', 'stats'); diff --git a/tests/tests_batches/stats/test_setBatchSubjectLevelGLMSpec.m b/tests/tests_batches/stats/test_setBatchSubjectLevelGLMSpec.m index aef345849..ce961c464 100644 --- a/tests/tests_batches/stats/test_setBatchSubjectLevelGLMSpec.m +++ b/tests/tests_batches/stats/test_setBatchSubjectLevelGLMSpec.m @@ -5,9 +5,7 @@ test_functions = localfunctions(); %#ok<*NASGU> catch % no problem; early Matlab versions can use initTestSuite fine end - initTestSuite; - end % TODO add test to better cover setScans @@ -17,7 +15,9 @@ function test_setBatchSubjectLevelGLMSpec_slicetiming_metadata() %% GIVEN subLabel = '^01'; - opt = setOptions('vismotion', subLabel, 'pipelineType', 'stats'); + opt = setOptions('vismotion', subLabel, ... + 'pipelineType', 'stats', ... + 'useTempDir', true); % needed to update the options with the content of the model opt = checkOptions(opt); @@ -40,7 +40,9 @@ function test_setBatchSubjectLevelGLMSpec_vismotion_acq_1pt6acq() %% GIVEN subLabel = '^01'; - opt = setOptions('vismotion', subLabel, 'pipelineType', 'stats'); + opt = setOptions('vismotion', subLabel, ... + 'pipelineType', 'stats', ... + 'useTempDir', true); opt.model.file = spm_file(opt.model.file, 'basename', 'model-vismotion-desc-1pt6acq_smdl'); opt.model.bm = BidsModel('file', opt.model.file); @@ -65,7 +67,9 @@ function test_setBatchSubjectLevelGLMSpec_brain_mask() %% GIVEN subLabel = '^01'; - opt = setOptions('vislocalizer', subLabel, 'pipelineType', 'stats'); + opt = setOptions('vislocalizer', subLabel, ... + 'pipelineType', 'stats', ... + 'useTempDir', true); opt.model.bm.Nodes{1}.Model.Options.Mask = struct('desc', 'brain', 'suffix', 'mask'); @@ -120,7 +124,9 @@ function test_setBatchSubjectLevelGLMSpec_basic() %% GIVEN subLabel = '^01'; - opt = setOptions('vislocalizer', subLabel, 'pipelineType', 'stats'); + opt = setOptions('vislocalizer', subLabel, ... + 'pipelineType', 'stats', ... + 'useTempDir', true); opt.model.bm.Nodes{1}.Model.Options = rmfield(opt.model.bm.Nodes{1}.Model.Options, ... 'Mask'); diff --git a/tests/tests_batches/stats/test_setBatchSubjectLevelResults.m b/tests/tests_batches/stats/test_setBatchSubjectLevelResults.m index 017d27e4f..823f7c2ce 100644 --- a/tests/tests_batches/stats/test_setBatchSubjectLevelResults.m +++ b/tests/tests_batches/stats/test_setBatchSubjectLevelResults.m @@ -10,9 +10,6 @@ function test_setBatchSubjectLevelResults_basic() - % TODO: fixturize - createDummyData(); - % IF contrast_name = 'VisMot'; [subLabel, opt, result] = setUp('vismotion', contrast_name); @@ -55,9 +52,6 @@ function test_setBatchSubjectLevelResults_basic() function test_setBatchSubjectLevelResults_missing_contrast_name() - % TODO: fixturize - createDummyData(); - if bids.internal.is_octave() moxunit_throw_test_skipped_exception('Octave:mixed-string-concat warning thrown'); end @@ -77,9 +71,6 @@ function test_setBatchSubjectLevelResults_missing_contrast_name() function test_setBatchSubjectLevelResults_error_no_matching_contrast() - % TODO: fixturize - createDummyData(); - if bids.internal.is_octave() moxunit_throw_test_skipped_exception('Octave:mixed-string-concat warning thrown'); end diff --git a/tests/tests_batches/test_saveMatlabBatch.m b/tests/tests_batches/test_saveMatlabBatch.m index 4222a111a..fabd93ba4 100644 --- a/tests/tests_batches/test_saveMatlabBatch.m +++ b/tests/tests_batches/test_saveMatlabBatch.m @@ -41,11 +41,10 @@ function test_saveMatlabBatch_group() matlabbatch = struct('test', 1); expectedOutput = fullfile(opt.dir.jobs, 'group', ... - ['batch_groupTest_' datestr(now, 'yyyy-mm-ddTHH-MM') '.mat']); + ['batch_groupTest_' datestr(now, 'yyyy_mm_ddTHH_MM') '.m']); saveMatlabBatch(matlabbatch, 'groupTest', opt); - assertEqual(exist(expectedOutput, 'file'), 0); - assertEqual(exist(spm_file(strrep(expectedOutput, '-', '_'), 'ext', '.m'), 'file'), 2); + assertEqual(exist(expectedOutput, 'file'), 2); end diff --git a/tests/tests_batches/test_setBachRename.m b/tests/tests_batches/test_setBachRename.m index b35331b7d..218b869f6 100644 --- a/tests/tests_batches/test_setBachRename.m +++ b/tests/tests_batches/test_setBachRename.m @@ -1,25 +1,19 @@ function test_suite = test_setBachRename %#ok<*STOUT> - % - % (C) Copyright 2022 bidspm developers - try % assignment of 'localfunctions' is necessary in Matlab >= 2016 test_functions = localfunctions(); %#ok<*NASGU> catch % no problem; early Matlab versions can use initTestSuite fine end - initTestSuite; - end function test_setBachRename_basic() % GIVEN - filename = 'sub-01_T1w_seg8.mat'; - setUp(filename); + moveTo = tempName(); + files = fullfile(moveTo, 'sub-01_T1w_seg8.mat'); + touch(files); - files = {fullfile(pwd, filename)}; - moveTo = {pwd}; patternReplace(1).pattern = 'T1w'; patternReplace(1).repl = 'label-T1w'; patternReplace(2).pattern = 'seg8'; @@ -27,26 +21,12 @@ function test_setBachRename_basic() % WHEN matlabbatch = {}; - matlabbatch = setBachRename(matlabbatch, files, moveTo, patternReplace); + matlabbatch = setBachRename(matlabbatch, {files}, {moveTo}, patternReplace); spm_jobman('run', matlabbatch); % THEN expectedFile = 'sub-01_label-T1w_segparam.mat'; - assert(exist(fullfile(pwd, expectedFile), 'file') == 2); - - cleanUp(expectedFile); - -end - -function setUp(filename) - - system(sprintf('touch %s', filename)); - -end - -function cleanUp(filename) - - delete(fullfile(pwd, filename)); + assert(exist(fullfile(moveTo, expectedFile), 'file') == 2); end diff --git a/tests/tests_batches/test_setBatchInverseNormalize.m b/tests/tests_batches/test_setBatchInverseNormalize.m index 909e35f67..cfbb0a4ff 100644 --- a/tests/tests_batches/test_setBatchInverseNormalize.m +++ b/tests/tests_batches/test_setBatchInverseNormalize.m @@ -7,6 +7,29 @@ initTestSuite; end +function test_setBatchInverseNormalize_basic() + + subLabel = '^01'; + + opt = setOptions('vismotion', subLabel); + + BIDS = getLayout(opt); + + imgToResample = {'foo'}; + + matlabbatch = {}; + matlabbatch = setBatchInverseNormalize(matlabbatch, BIDS, opt, subLabel, imgToResample); + + deformationField = fullfile(BIDS.pth, 'sub-01', 'ses-01', 'anat', ... + 'sub-01_ses-01_from-IXI549Space_to-T1w_mode-image_xfm.nii'); + + assertEqual(matlabbatch{1}.spm.spatial.normalise.write.subj.def(1), {deformationField}); + assertEqual(matlabbatch{1}.spm.spatial.normalise.write.woptions.vox, nan(1, 3)); + assertEqual(matlabbatch{1}.spm.spatial.normalise.write.subj.resample(1), {'foo'}); + assertEqual(matlabbatch{1}.spm.spatial.normalise.write.woptions.bb, nan(2, 3)); + +end + function test_setBatchInverseNormalize_warning() opt = setOptions('vismotion'); diff --git a/tests/tests_bids/test_fileFilterForBold.m b/tests/tests_bids/test_fileFilterForBold.m index 6dc516ffc..50efff7f5 100644 --- a/tests/tests_bids/test_fileFilterForBold.m +++ b/tests/tests_bids/test_fileFilterForBold.m @@ -7,9 +7,7 @@ test_functions = localfunctions(); %#ok<*NASGU> catch % no problem; early Matlab versions can use initTestSuite fine end - initTestSuite; - end function test_fileFilterForBold_events() diff --git a/tests/tests_bids/test_getROIs.m b/tests/tests_bids/test_getROIs.m index d4d78f7ab..39c01d3d6 100644 --- a/tests/tests_bids/test_getROIs.m +++ b/tests/tests_bids/test_getROIs.m @@ -7,9 +7,7 @@ test_functions = localfunctions(); %#ok<*NASGU> catch % no problem; early Matlab versions can use initTestSuite fine end - initTestSuite; - end function test_getROIs_individual_space_no_subject() diff --git a/tests/tests_bids/test_initBids.m b/tests/tests_bids/test_initBids.m index f1379a248..579ddca52 100644 --- a/tests/tests_bids/test_initBids.m +++ b/tests/tests_bids/test_initBids.m @@ -1,27 +1,20 @@ function test_suite = test_initBids %#ok<*STOUT> - % - % (C) Copyright 2022 bidspm developers - try % assignment of 'localfunctions' is necessary in Matlab >= 2016 test_functions = localfunctions(); %#ok<*NASGU> catch % no problem; early Matlab versions can use initTestSuite fine end - initTestSuite; - end function test_initBids_basic() % GIVEN - opt.dir.output = fullfile(pwd, 'foo'); + opt.dir.output = fullfile(tempName(), 'foo'); opt.pipeline.name = 'bidspm'; opt.pipeline.type = ''; opt.verbosity = 0; - cleanUp(opt); - % WHEN initBids(opt); @@ -36,20 +29,16 @@ function test_initBids_basic() assertEqual(content.GeneratedBy.Name, 'bidspm'); assertEqual(content.GeneratedBy.Description, ''); - cleanUp(opt); - end function test_initBids_name_description() % GIVEN - opt.dir.output = fullfile(pwd, 'foo'); + opt.dir.output = fullfile(tempName(), 'foo'); opt.pipeline.name = 'bidspm'; opt.pipeline.type = 'stats'; opt.verbosity = 0; - cleanUp(opt); - % WHEN initBids(opt, 'description', 'subject level stats'); @@ -59,20 +48,16 @@ function test_initBids_name_description() assertEqual(content.GeneratedBy.Name, 'bidspm-stats'); assertEqual(content.GeneratedBy.Description, 'subject level stats'); - cleanUp(opt); - end function test_initBids_force() % GIVEN - opt.dir.output = fullfile(pwd, 'foo'); + opt.dir.output = fullfile(tempName(), 'foo'); opt.pipeline.name = 'bidspm'; opt.pipeline.type = 'stats'; opt.verbosity = 0; - cleanUp(opt); - % WHEN initBids(opt, 'description', 'subject level stats'); @@ -84,16 +69,4 @@ function test_initBids_force() content = bids.util.jsondecode(fullfile(opt.dir.output, 'dataset_description.json')); assertEqual(content.GeneratedBy.Description, ''); - cleanUp(opt); - -end - -function setUp() - -end - -function cleanUp(opt) - if isdir(opt.dir.output) - rmdir(opt.dir.output, 's'); - end end diff --git a/tests/tests_bids_model/test_createDefaultStatsModel.m b/tests/tests_bids_model/test_createDefaultStatsModel.m index 0ce98af5c..15b32a896 100644 --- a/tests/tests_bids_model/test_createDefaultStatsModel.m +++ b/tests/tests_bids_model/test_createDefaultStatsModel.m @@ -14,14 +14,14 @@ function test_createDefaultStatsModel_basic() BIDS = getLayout(opt); - opt.dir.derivatives = pwd; + opt.dir.derivatives = tempName(); opt.space = {'IXI549Space'}; opt.taskName = {'vislocalizer'}; createDefaultStatsModel(BIDS, opt); % make sure the file was created where expected - expectedFilename = fullfile(pwd, 'models', 'model-defaultVislocalizer_smdl.json'); + expectedFilename = fullfile(opt.dir.derivatives, 'models', 'model-defaultVislocalizer_smdl.json'); assertEqual(exist(expectedFilename, 'file'), 2); % check it has the right content @@ -57,8 +57,6 @@ function test_createDefaultStatsModel_basic() assertEqual(content.Input, expectedContent.Input); end - cleanUp(fullfile(pwd, 'models')); - end function test_createDefaultStatsModel_ignore() @@ -67,7 +65,7 @@ function test_createDefaultStatsModel_ignore() BIDS = getLayout(opt); - opt.dir.derivatives = pwd; + opt.dir.derivatives = tempName(); opt.space = {'IXI549Space'}; opt.taskName = {'vislocalizer'}; @@ -81,6 +79,4 @@ function test_createDefaultStatsModel_ignore() assertEqual(numel(content.Nodes), 2); assertEqual(numel(content.Edges), 1); - cleanUp(fullfile(pwd, 'models')); - end diff --git a/tests/tests_cli/test_bidspm_boilderplate.m b/tests/tests_cli/test_bidspm_boilderplate.m index 47a73f86a..3b3ce860d 100644 --- a/tests/tests_cli/test_bidspm_boilderplate.m +++ b/tests/tests_cli/test_bidspm_boilderplate.m @@ -6,9 +6,7 @@ test_functions = localfunctions(); %#ok<*NASGU> catch % no problem; early Matlab versions can use initTestSuite fine end - initTestSuite; - end function test_boilerplate_only_stats() diff --git a/tests/tests_infra/test_bugReport.m b/tests/tests_infra/test_bugReport.m index 68d43829e..ace361ea4 100644 --- a/tests/tests_infra/test_bugReport.m +++ b/tests/tests_infra/test_bugReport.m @@ -9,39 +9,33 @@ function test_bugReport_output_dir() - %% opt.dryRun = false; opt.verbosity = 0; - opt.dir.output = fullfile(pwd, 'tmp'); + opt.dir.output = fullfile(tempName(), 'tmp'); opt = checkOptions(opt); bugReport(opt); - cleanUp('tmp'); - end function test_bugReport_basic() - %% - bugReport(); - - %% opt.dryRun = false; opt.verbosity = 0; + opt.dir.output = tempName(); opt = checkOptions(opt); bugReport(opt); - cleanUp('error_logs'); + assert(isdir(fullfile(opt.dir.output, 'error_logs'))); end function test_bugReport_error() - %% opt.dryRun = false; opt.verbosity = 0; + opt.dir.output = tempName(); opt = checkOptions(opt); try @@ -50,6 +44,4 @@ function test_bugReport_error() bugReport(opt, ME); end - cleanUp('error_logs'); - end diff --git a/tests/tests_infra/test_checkToolbox.m b/tests/tests_infra/test_checkToolbox.m index 43f775553..023937c2e 100644 --- a/tests/tests_infra/test_checkToolbox.m +++ b/tests/tests_infra/test_checkToolbox.m @@ -7,9 +7,7 @@ test_functions = localfunctions(); %#ok<*NASGU> catch % no problem; early Matlab versions can use initTestSuite fine end - initTestSuite; - end function test_checkToolbox_mp2rage() diff --git a/tests/tests_infra/test_elapsedTime.m b/tests/tests_infra/test_elapsedTime.m index a241c5893..7e58c8b8f 100644 --- a/tests/tests_infra/test_elapsedTime.m +++ b/tests/tests_infra/test_elapsedTime.m @@ -1,8 +1,5 @@ function test_suite = test_elapsedTime %#ok<*STOUT> - % - % (C) Copyright 2020 bidspm developers - try % assignment of 'localfunctions' is necessary in Matlab >= 2016 test_functions = localfunctions(); %#ok<*NASGU> catch % no problem; early Matlab versions can use initTestSuite fine @@ -23,11 +20,11 @@ function test_elapsedTime_basic() subLabel = opt.subjects{iSub}; printProcessingSubject(iSub, subLabel, opt); subjectStart = elapsedTime(opt, 'start'); - pause(0.05); + pause(0.01); [~, runTime] = elapsedTime(opt, 'stop', subjectStart, runTime, nbIteration); end - pause(1); + pause(0.2); cleanUpWorkflow(opt); diff --git a/tests/tests_reports/test_boilerplate.m b/tests/tests_reports/test_boilerplate.m index 2dae0ddd5..68eee2484 100644 --- a/tests/tests_reports/test_boilerplate.m +++ b/tests/tests_reports/test_boilerplate.m @@ -7,9 +7,7 @@ test_functions = localfunctions(); %#ok<*NASGU> catch % no problem; early Matlab versions can use initTestSuite fine end - initTestSuite; - end function test_boilerplate_spatial_preproc() diff --git a/tests/tests_batches/stats/test_setBatchFactorialDesign.m b/tests/tests_slow/tests_batches/stats/test_setBatchFactorialDesign.m similarity index 91% rename from tests/tests_batches/stats/test_setBatchFactorialDesign.m rename to tests/tests_slow/tests_batches/stats/test_setBatchFactorialDesign.m index 09d21ef61..f75eca068 100644 --- a/tests/tests_batches/stats/test_setBatchFactorialDesign.m +++ b/tests/tests_slow/tests_batches/stats/test_setBatchFactorialDesign.m @@ -10,8 +10,9 @@ function test_setBatchFactorialDesign_within_group() - % TODO: fixturize - createDummyData(); + if ~usingSlowTestMode() + moxunit_throw_test_skipped_exception('slow test only'); + end opt = setOptions('vislocalizer', '', 'pipelineType', 'stats'); @@ -34,8 +35,9 @@ function test_setBatchFactorialDesign_within_group() function test_setBatchFactorialDesign_complex() - % TODO: fixturize - createDummyData(); + if ~usingSlowTestMode() + moxunit_throw_test_skipped_exception('slow test only'); + end opt = setOptions('vismotion', {'^01'}, 'pipelineType', 'stats'); @@ -81,8 +83,9 @@ function test_setBatchFactorialDesign_complex() function test_setBatchFactorialDesign_basic() - % TODO: fixturize - createDummyData(); + if ~usingSlowTestMode() + moxunit_throw_test_skipped_exception('slow test only'); + end opt = setOptions('vismotion', {'01' 'ctrl01'}, 'pipelineType', 'stats'); @@ -108,6 +111,10 @@ function test_setBatchFactorialDesign_basic() function test_setBatchFactorialDesign_wrong_model_design_matrix() + if ~usingSlowTestMode() + moxunit_throw_test_skipped_exception('slow test only'); + end + opt = setOptions('vismotion', {'^01'}, 'pipelineType', 'stats'); opt.verbosity = 1; diff --git a/tests/tests_slow/tests_batches/stats/test_setBatchSubjectLevelGLMSpec.m b/tests/tests_slow/tests_batches/stats/test_setBatchSubjectLevelGLMSpec.m index 2f6212c06..9f64e4f89 100644 --- a/tests/tests_slow/tests_batches/stats/test_setBatchSubjectLevelGLMSpec.m +++ b/tests/tests_slow/tests_batches/stats/test_setBatchSubjectLevelGLMSpec.m @@ -5,9 +5,7 @@ test_functions = localfunctions(); %#ok<*NASGU> catch % no problem; early Matlab versions can use initTestSuite fine end - initTestSuite; - end function test_setBatchSubjectLevelGLMSpec_design_only() @@ -19,7 +17,9 @@ function test_setBatchSubjectLevelGLMSpec_design_only() %% GIVEN subLabel = '^01'; - opt = setOptions('vislocalizer', subLabel, 'pipelineType', 'stats'); + opt = setOptions('vislocalizer', subLabel, ... + 'pipelineType', 'stats', ... + 'useTempDir', true); opt.model.designOnly = true; @@ -46,6 +46,4 @@ function test_setBatchSubjectLevelGLMSpec_design_only() assertEqual(matlabbatch{1}.spm.stats.fmri_design.cvi, 'FAST'); assertEqual(matlabbatch{1}.spm.stats.fmri_design.bases.hrf.derivs, [1 0]); - createDummyData(); - end diff --git a/tests/tests_slow/tests_batches/test_setBatchInverseNormalize.m b/tests/tests_slow/tests_batches/test_setBatchInverseNormalize.m deleted file mode 100644 index 0346db225..000000000 --- a/tests/tests_slow/tests_batches/test_setBatchInverseNormalize.m +++ /dev/null @@ -1,50 +0,0 @@ -function test_suite = test_setBatchInverseNormalize %#ok<*STOUT> - % (C) Copyright 2022 bidspm developers - try % assignment of 'localfunctions' is necessary in Matlab >= 2016 - test_functions = localfunctions(); %#ok<*NASGU> - catch % no problem; early Matlab versions can use initTestSuite fine - end - initTestSuite; -end - -function test_setBatchInverseNormalize_basic() - - if ~usingSlowTestMode() - moxunit_throw_test_skipped_exception('slow test only'); - end - - subLabel = '^01'; - - opt = setOptions('vismotion', subLabel); - - BIDS = getLayout(opt); - - imgToResample = {'foo'}; - - matlabbatch = {}; - matlabbatch = setBatchInverseNormalize(matlabbatch, BIDS, opt, subLabel, imgToResample); - - deformationField = fullfile(BIDS.pth, 'sub-01', 'ses-01', 'anat', ... - 'sub-01_ses-01_from-IXI549Space_to-T1w_mode-image_xfm.nii'); - - assertEqual(matlabbatch{1}.spm.spatial.normalise.write.subj.def(1), {deformationField}); - assertEqual(matlabbatch{1}.spm.spatial.normalise.write.woptions.vox, nan(1, 3)); - assertEqual(matlabbatch{1}.spm.spatial.normalise.write.subj.resample(1), {'foo'}); - assertEqual(matlabbatch{1}.spm.spatial.normalise.write.woptions.bb, nan(2, 3)); - -end - -function test_setBatchInverseNormalize_warning() - - opt = setOptions('vismotion'); - - opt.verbosity = 1; - - BIDS = getLayout(opt); - subLabel = '99'; - imgToResample = {'foo'}; - matlabbatch = {}; - assertWarning(@()setBatchInverseNormalize(matlabbatch, BIDS, opt, subLabel, imgToResample), ... - 'setBatchInverseNormalize:noDeformationField'); - -end diff --git a/tests/tests_slow/tests_cli/test_bidspm_copy.m b/tests/tests_slow/tests_cli/test_bidspm_copy.m index 4435b6ac8..8f9365510 100644 --- a/tests/tests_slow/tests_cli/test_bidspm_copy.m +++ b/tests/tests_slow/tests_cli/test_bidspm_copy.m @@ -6,9 +6,7 @@ test_functions = localfunctions(); %#ok<*NASGU> catch % no problem; early Matlab versions can use initTestSuite fine end - initTestSuite; - end function test_copy_filter() diff --git a/tests/tests_slow/tests_cli/test_bidspm_create_roi.m b/tests/tests_slow/tests_cli/test_bidspm_create_roi.m index 06686e1a4..d1eb80502 100644 --- a/tests/tests_slow/tests_cli/test_bidspm_create_roi.m +++ b/tests/tests_slow/tests_cli/test_bidspm_create_roi.m @@ -6,9 +6,7 @@ test_functions = localfunctions(); %#ok<*NASGU> catch % no problem; early Matlab versions can use initTestSuite fine end - initTestSuite; - end function test_bidsCreateROI_boilerplate_only() @@ -135,10 +133,6 @@ function test_bidsCreateROI_neuromorphometrics_inv_norm() % 'space', {'individual'}, ... % 'verbosity', 0); % - % cleanUp(fullfile(pwd, 'tmp')); - % cleanUp(fullfile(pwd, 'options')); - % cleanUp(fullfile(pwd, 'error_logs')); - % % end end diff --git a/tests/tests_slow/tests_cli/test_bidspm_default_stats_model.m b/tests/tests_slow/tests_cli/test_bidspm_default_stats_model.m index 49e3ad4ca..a99cfddbf 100644 --- a/tests/tests_slow/tests_cli/test_bidspm_default_stats_model.m +++ b/tests/tests_slow/tests_cli/test_bidspm_default_stats_model.m @@ -6,9 +6,7 @@ test_functions = localfunctions(); %#ok<*NASGU> catch % no problem; early Matlab versions can use initTestSuite fine end - initTestSuite; - end function test_createDefaultStatsModel_CLI() diff --git a/tests/tests_slow/tests_cli/test_bidspm_smooth.m b/tests/tests_slow/tests_cli/test_bidspm_smooth.m index 358a6c7dc..fe155dc6b 100644 --- a/tests/tests_slow/tests_cli/test_bidspm_smooth.m +++ b/tests/tests_slow/tests_cli/test_bidspm_smooth.m @@ -6,9 +6,7 @@ test_functions = localfunctions(); %#ok<*NASGU> catch % no problem; early Matlab versions can use initTestSuite fine end - initTestSuite; - end function test_smooth() diff --git a/tests/tests_slow/tests_workflows/stats/test_bidsFFX.m b/tests/tests_slow/tests_workflows/stats/test_bidsFFX.m index 45ab037d0..b6f723589 100644 --- a/tests/tests_slow/tests_workflows/stats/test_bidsFFX.m +++ b/tests/tests_slow/tests_workflows/stats/test_bidsFFX.m @@ -18,6 +18,10 @@ function test_bidsFFX_bug_642() opt.model.bm = BidsModel('file', opt.model.file); opt.model.bm.Input.space = char(opt.model.bm.Input.space); + tmpDir = tempName(); + opt.dir.stats = fullfile(tmpDir); + opt.dir.output = opt.dir.stats; + bidsFFX('specifyAndEstimate', opt); end @@ -33,16 +37,17 @@ function test_bidsFFX_individual() for i = 1 opt = setOptions(task{i}, '', 'pipelineType', 'stats'); + + tmpDir = tempName(); + opt.dir.stats = fullfile(tmpDir); + opt.dir.output = opt.dir.stats; + opt.model.file = fullfile(getTestDataDir(), 'models', ... ['model-' strjoin(task, '') 'SpaceIndividual_smdl.json']); opt.model.bm = BidsModel('file', opt.model.file); opt.fwhm.func = 0; opt.stc.skip = 1; - if exist(opt.dir.stats, 'dir') - rmdir(opt.dir.stats, 's'); - end - [matlabbatch, opt] = bidsFFX('specifyAndEstimate', opt); bf = bids.File(matlabbatch{1}.spm.stats.fmri_spec.sess(1).scans{1}); @@ -53,8 +58,6 @@ function test_bidsFFX_individual() end - createDummyData(); - end function test_bidsFFX_skip_subject_no_data() @@ -64,6 +67,11 @@ function test_bidsFFX_skip_subject_no_data() end opt = setOptions('vislocalizer', '^01', 'pipelineType', 'stats'); + + tmpDir = tempName(); + opt.dir.stats = fullfile(tmpDir); + opt.dir.output = opt.dir.stats; + opt.model.file = fullfile(getTestDataDir(), 'models', ... 'model-vislocalizerWrongSpace_smdl.json'); opt.model.bm = BidsModel('file', opt.model.file); @@ -82,39 +90,6 @@ function test_bidsFFX_skip_subject_no_data() end -function test_bidsFFX_contrasts_select_node() - - if ~usingSlowTestMode() - moxunit_throw_test_skipped_exception('slow test only'); - end - - opt = setOptions('vislocalizer', '', 'pipelineType', 'stats'); - opt.stc.skip = 1; - - matlabbatch = bidsFFX('contrasts', opt, ... - 'nodeName', 'subject_level'); - - assertEqual(numel(matlabbatch{1}.spm.stats.con.consess), 4); - -end - -function test_bidsFFX_contrasts() - - if ~usingSlowTestMode() - moxunit_throw_test_skipped_exception('slow test only'); - end - - opt = setOptions('vislocalizer', '', 'pipelineType', 'stats'); - opt.stc.skip = 1; - - [matlabbatch, opt] = bidsFFX('contrasts', opt); - - assertEqual(numel(matlabbatch{1}.spm.stats.con.consess), 8); - - assertEqual(opt.dir.jobs, fullfile(opt.dir.stats, 'jobs', 'vislocalizer')); - -end - function test_bidsFFX_fmriprep_no_smoothing() if ~usingSlowTestMode() @@ -151,8 +126,6 @@ function test_bidsFFX_fmriprep_no_smoothing() cleanUp(opt.dir.preproc); - createDummyData(); - end function test_bidsFFX_mni() @@ -171,9 +144,9 @@ function test_bidsFFX_mni() opt = setOptions(task{i}, '', 'pipelineType', 'stats'); opt.stc.skip = 1; - if exist(opt.dir.stats, 'dir') - rmdir(opt.dir.stats, 's'); - end + tmpDir = tempName(); + opt.dir.stats = fullfile(tmpDir); + opt.dir.output = opt.dir.stats; [matlabbatch, opt] = bidsFFX('specifyAndEstimate', opt); @@ -185,6 +158,4 @@ function test_bidsFFX_mni() end - createDummyData(); - end diff --git a/tests/tests_slow/tests_workflows/stats/test_bidsFFX_PPI.m b/tests/tests_slow/tests_workflows/stats/test_bidsFFX_PPI.m index 1ba026ca3..e7a275a59 100644 --- a/tests/tests_slow/tests_workflows/stats/test_bidsFFX_PPI.m +++ b/tests/tests_slow/tests_workflows/stats/test_bidsFFX_PPI.m @@ -14,6 +14,11 @@ function test_bidsFFX_PPI_basic() moxunit_throw_test_skipped_exception('slow test only'); end + if bids.internal.is_octave() + moxunit_throw_test_skipped_exception('set up unzipped files with octave fails'); + % TODO unzip the relevant files first + end + opt = setOptions('MoAE-fmriprep', '', 'pipelineType', 'stats'); tempPath = tempName(); diff --git a/tests/tests_slow/tests_workflows/stats/test_bidsFFX_contrasts.m b/tests/tests_slow/tests_workflows/stats/test_bidsFFX_contrasts.m new file mode 100644 index 000000000..cdc660ea8 --- /dev/null +++ b/tests/tests_slow/tests_workflows/stats/test_bidsFFX_contrasts.m @@ -0,0 +1,41 @@ +function test_suite = test_bidsFFX_contrasts %#ok<*STOUT> + % (C) Copyright 2021 bidspm developers + try % assignment of 'localfunctions' is necessary in Matlab >= 2016 + test_functions = localfunctions(); %#ok<*NASGU> + catch % no problem; early Matlab versions can use initTestSuite fine + end + initTestSuite; +end + +function test_bidsFFX_contrasts_select_node() + + if ~usingSlowTestMode() + moxunit_throw_test_skipped_exception('slow test only'); + end + + opt = setOptions('vislocalizer', '', 'pipelineType', 'stats'); + opt.stc.skip = 1; + + matlabbatch = bidsFFX('contrasts', opt, ... + 'nodeName', 'subject_level'); + + assertEqual(numel(matlabbatch{1}.spm.stats.con.consess), 4); + +end + +function test_bidsFFX_contrasts_basic() + + if ~usingSlowTestMode() + moxunit_throw_test_skipped_exception('slow test only'); + end + + opt = setOptions('vislocalizer', '', 'pipelineType', 'stats'); + opt.stc.skip = 1; + + [matlabbatch, opt] = bidsFFX('contrasts', opt); + + assertEqual(numel(matlabbatch{1}.spm.stats.con.consess), 8); + + assertEqual(opt.dir.jobs, fullfile(opt.dir.stats, 'jobs', 'vislocalizer')); + +end diff --git a/tests/tests_slow/tests_workflows/stats/test_bidsModelSelection.m b/tests/tests_slow/tests_workflows/stats/test_bidsModelSelection.m index 9fd1a466e..0285694c6 100644 --- a/tests/tests_slow/tests_workflows/stats/test_bidsModelSelection.m +++ b/tests/tests_slow/tests_workflows/stats/test_bidsModelSelection.m @@ -7,9 +7,7 @@ test_functions = localfunctions(); %#ok<*NASGU> catch % no problem; early Matlab versions can use initTestSuite fine end - initTestSuite; - end function test_bidsModelSelection_basic() @@ -28,7 +26,7 @@ function test_bidsModelSelection_basic() 'models', ... 'model-vismotionGlobalSignal_smdl.json')}; - opt.verbosity = 3; + opt.verbosity = 0; % WHEN matlabbatch = bidsModelSelection(opt); diff --git a/tests/tests_slow/tests_workflows/stats/test_bidsRoiBasedGLM.m b/tests/tests_slow/tests_workflows/stats/test_bidsRoiBasedGLM.m index 874acd17f..ae7fc4d21 100644 --- a/tests/tests_slow/tests_workflows/stats/test_bidsRoiBasedGLM.m +++ b/tests/tests_slow/tests_workflows/stats/test_bidsRoiBasedGLM.m @@ -59,8 +59,6 @@ function test_bidsRoiBasedGLM_run() bidsFFX('specify', opt); - % rmdir(fullfile(pwd, 'options'), 's'); - opt.dir.roi = fullfile(opt.dir.derivatives, 'bidspm-roi'); opt.roi.atlas = 'wang'; diff --git a/tests/tests_slow/tests_workflows/test_bidsChangeSuffix.m b/tests/tests_slow/tests_workflows/test_bidsChangeSuffix.m index e6b8295f1..4c1948d45 100644 --- a/tests/tests_slow/tests_workflows/test_bidsChangeSuffix.m +++ b/tests/tests_slow/tests_workflows/test_bidsChangeSuffix.m @@ -18,13 +18,7 @@ function test_bidsChangeSuffix_basic() dataDir = getBidsExample('ds001'); - tmpDir = fullfile(dataDir, '..', '..', 'tmp'); - - if isdir(tmpDir) - rmdir(tmpDir, 's'); - end - - bids.util.mkdir(tmpDir); + tmpDir = tempName(); copyfile(dataDir, tmpDir); bidsDir = tmpDir; @@ -62,6 +56,4 @@ function test_bidsChangeSuffix_basic() metadata = bids.query(BIDS_after, 'metadata', 'suffix', 'vaso'); assertEqual(metadata, expected_metadata); - rmdir(tmpDir, 's'); - end diff --git a/tests/tests_slow/tests_workflows/test_bidsConcatBetaTmaps.m b/tests/tests_slow/tests_workflows/test_bidsConcatBetaTmaps.m index f9fc52b94..3d78c427e 100644 --- a/tests/tests_slow/tests_workflows/test_bidsConcatBetaTmaps.m +++ b/tests/tests_slow/tests_workflows/test_bidsConcatBetaTmaps.m @@ -17,17 +17,14 @@ function test_bidsConcatBetaTmapsBasic() subLabel = '01'; - opt = setOptions('vismotion', subLabel, 'pipelineType', 'stats'); + opt = setOptions('vismotion', subLabel, ... + 'pipelineType', 'stats', ... + 'useTempDir', true); opt.dryRun = true; opt.model.file = spm_file(opt.model.file, 'filename', 'model-vismotionMVPA_smdl.json'); opt.model.bm = BidsModel('file', opt.model.file); - tmpDir = tempName(); - copyfile(opt.dir.stats, tmpDir); - - opt.dir.stats = tmpDir; - % update content of FFX dir to mock 2 sessions targetDir = fullfile(opt.dir.stats, ... ['sub-' subLabel], ... diff --git a/tests/tests_slow/tests_workflows/test_bidsCopyInputFolder.m b/tests/tests_slow/tests_workflows/test_bidsCopyInputFolder.m index ef058cb3e..1d993e9a2 100644 --- a/tests/tests_slow/tests_workflows/test_bidsCopyInputFolder.m +++ b/tests/tests_slow/tests_workflows/test_bidsCopyInputFolder.m @@ -74,7 +74,7 @@ function test_bidsCopyInputFolder_fmriprep() assertEqual(size(data, 1), 16); % ensure that by default data are not overwritten - opt.verbosity = 3; + opt.verbosity = 0; bidsCopyInputFolder(opt, 'unzip', false); % or that they are diff --git a/tests/tests_slow/tests_workflows/test_bidsCreateROI.m b/tests/tests_slow/tests_workflows/test_bidsCreateROI.m index 14382c399..f6a0aff9b 100644 --- a/tests/tests_slow/tests_workflows/test_bidsCreateROI.m +++ b/tests/tests_slow/tests_workflows/test_bidsCreateROI.m @@ -22,12 +22,12 @@ function test_bidsCreateROI_neuromorphometrics() opt.roi.atlas = 'neuromorphometrics'; opt.roi.name = {'Amygdala'}; + opt.roi.hemi = {'L', 'R'}; opt.roi.space = {'IXI549Space', 'individual'}; - opt.dir.roi = spm_file(fullfile(opt.dir.derivatives, 'bidspm-roi'), 'cpath'); - opt.dryRun = false; + opt.dir.roi = fullfile(tempName(), 'bidspm-roi'); - cleanUp(opt.dir.roi); + opt.dryRun = false; bidsCreateROI(opt); @@ -38,8 +38,6 @@ function test_bidsCreateROI_neuromorphometrics() assertEqual(size(roiImages, 1), 2); - cleanUp(opt.dir.roi); - end function test_bidsCreateROI_wang() @@ -56,13 +54,12 @@ function test_bidsCreateROI_wang() opt.roi.atlas = 'wang'; opt.roi.name = {'V1v', 'V1d'}; + opt.roi.hemi = {'L', 'R'}; opt.roi.space = {'IXI549Space', 'individual'}; - opt.dir.roi = spm_file(fullfile(opt.dir.derivatives, 'bidspm-roi'), 'cpath'); + opt.dir.roi = fullfile(tempName(), 'bidspm-roi'); opt.dryRun = false; - cleanUp(opt.dir.roi); - bidsCreateROI(opt); BIDS = bids.layout(opt.dir.roi, ... @@ -72,6 +69,4 @@ function test_bidsCreateROI_wang() assertEqual(size(roiImages, 1), 4); - cleanUp(opt.dir.roi); - end diff --git a/tests/tests_slow/tests_workflows/test_bidsRename.m b/tests/tests_slow/tests_workflows/test_bidsRename.m index 20e2a5d59..78295132b 100644 --- a/tests/tests_slow/tests_workflows/test_bidsRename.m +++ b/tests/tests_slow/tests_workflows/test_bidsRename.m @@ -41,7 +41,7 @@ function test_bidsRename_basic() end opt.dryRun = false; - opt.verbosity = 2; + opt.verbosity = 0; createdFiles = bidsRename(opt); diff --git a/tests/tests_slow/tests_workflows/test_bidsReport.m b/tests/tests_slow/tests_workflows/test_bidsReport.m index af73ca7b7..7bf67134c 100644 --- a/tests/tests_slow/tests_workflows/test_bidsReport.m +++ b/tests/tests_slow/tests_workflows/test_bidsReport.m @@ -1,8 +1,5 @@ function test_suite = test_bidsReport %#ok<*STOUT> - % - % (C) Copyright 2021 bidspm developers - try % assignment of 'localfunctions' is necessary in Matlab >= 2016 test_functions = localfunctions(); %#ok<*NASGU> catch % no problem; early Matlab versions can use initTestSuite fine @@ -18,19 +15,17 @@ function test_bidsReport_smoke_test() opt = setOptions('vismotion'); - cleanUp(fullfile(opt.dir.preproc, 'reports')); + opt.dir.output = tempName(); bidsReport(opt); - assertEqual(exist(fullfile(opt.dir.preproc, ... + assertEqual(exist(fullfile(opt.dir.output, ... 'reports', ... 'sub-ctrl01', ... 'dataset-bidspm-raw_bids-matlab_report.md'), ... 'file'), ... 2); - cleanUp(fullfile(opt.dir.preproc, 'reports')); - end function test_bidsReport_basic() @@ -41,17 +36,15 @@ function test_bidsReport_basic() opt = setOptions('MoAE'); - cleanUp(fullfile(opt.dir.preproc, 'reports')); + opt.dir.output = tempName(); bidsReport(opt); - assertEqual(exist(fullfile(opt.dir.preproc, ... + assertEqual(exist(fullfile(opt.dir.output, ... 'reports', ... 'sub-01', ... 'dataset-raw_bids-matlab_report.md'), ... 'file'), ... 2); - cleanUp(fullfile(opt.dir.preproc, 'reports')); - end diff --git a/tests/tests_stats/subject_level/test_allRunsHaveSameNbRegressors.m b/tests/tests_stats/subject_level/test_allRunsHaveSameNbRegressors.m index 993f8813f..94face7af 100644 --- a/tests/tests_stats/subject_level/test_allRunsHaveSameNbRegressors.m +++ b/tests/tests_stats/subject_level/test_allRunsHaveSameNbRegressors.m @@ -7,9 +7,7 @@ test_functions = localfunctions(); %#ok<*NASGU> catch % no problem; early Matlab versions can use initTestSuite fine end - initTestSuite; - end function test_allRunsHaveSameNbRegressors_basic() diff --git a/tests/tests_stats/subject_level/test_concatenateRuns.m b/tests/tests_stats/subject_level/test_concatenateRuns.m index 1f72c2211..07105d2d9 100644 --- a/tests/tests_stats/subject_level/test_concatenateRuns.m +++ b/tests/tests_stats/subject_level/test_concatenateRuns.m @@ -1,13 +1,10 @@ function test_suite = test_concatenateRuns %#ok<*STOUT> % (C) Copyright 2023 bidspm developers - try % assignment of 'localfunctions' is necessary in Matlab >= 2016 test_functions = localfunctions(); %#ok<*NASGU> catch % no problem; early Matlab versions can use initTestSuite fine end - initTestSuite; - end function test_concatenateRuns_basic() diff --git a/tests/tests_stats/subject_level/test_convertOnsetTsvToMat.m b/tests/tests_stats/subject_level/test_convertOnsetTsvToMat.m index 1a1a33eb6..0b341a289 100644 --- a/tests/tests_stats/subject_level/test_convertOnsetTsvToMat.m +++ b/tests/tests_stats/subject_level/test_convertOnsetTsvToMat.m @@ -1,59 +1,44 @@ function test_suite = test_convertOnsetTsvToMat %#ok<*STOUT> - % - % (C) Copyright 2022 bidspm developers - try % assignment of 'localfunctions' is necessary in Matlab >= 2016 test_functions = localfunctions(); %#ok<*NASGU> catch % no problem; early Matlab versions can use initTestSuite fine end - initTestSuite; - end function test_convertOnsetTsvToMat_exclude_late_events() % GIVEN - tsvFile = fullfile(getTestDataDir(), ... - 'tsv_files', ... - 'sub-01_task-vismotion_events.tsv'); opt = setOptions('vismotion'); - opt.model.bm = BidsModel('file', opt.model.file); + [opt, tmpDir] = setUp(opt); + tsvFile = fullfile(tmpDir, 'sub-01_task-vismotion_events.tsv'); % WHEN runDuration = 3; fullpathOnsetFilename = convertOnsetTsvToMat(opt, tsvFile, runDuration); % THEN - assertEqual(fullfile(getTestDataDir(), ... - 'tsv_files', ... - 'sub-01_task-vismotion_onsets.mat'), ... + assertEqual(fullfile(tmpDir, 'sub-01_task-vismotion_onsets.mat'), ... fullpathOnsetFilename); assertEqual(exist(fullpathOnsetFilename, 'file'), 2); - load(fullpathOnsetFilename); + load(fullpathOnsetFilename, 'names', 'onsets', 'durations'); assertEqual(names, {'VisMot'}); assertEqual(onsets, {2}); assertEqual(durations, {2}); - cleanUp(fullpathOnsetFilename); - end function test_convertOnsetTsvToMat_parametric_modulation() % GIVEN - tsvFile = fullfile(getTestDataDir(), ... - 'tsv_files', ... - 'sub-01_task-vismotion_events.tsv'); opt = setOptions('vismotion'); - opt.model.file = fullfile(fileparts(opt.model.file), ... 'model-vismotion_desc-parametric_smdl.json'); - - opt.model.bm = BidsModel('file', opt.model.file); + [opt, tmpDir] = setUp(opt); + tsvFile = fullfile(tmpDir, 'sub-01_task-vismotion_events.tsv'); % WHEN fullpathOnsetFilename = convertOnsetTsvToMat(opt, tsvFile); @@ -86,8 +71,8 @@ function test_convertOnsetTsvToMat_parametric_modulation() %% bm = opt.model.bm; bm.Nodes{1}.Model.Software.SPM.ParametricModulations(2) = []; - bm.write('tmp.json'); - opt.model.file = fullfile(pwd, 'tmp.json'); + bm.write(fullfile(tmpDir, 'tmp.json')); + opt.model.file = fullfile(tmpDir, 'tmp.json'); opt.model.bm = BidsModel('file', opt.model.file); fullpathOnsetFilename = convertOnsetTsvToMat(opt, tsvFile); @@ -98,21 +83,14 @@ function test_convertOnsetTsvToMat_parametric_modulation() assertEqual(pmod(1).param(1), {3}); assertEqual(pmod(1).poly(1), {1}); - cleanUp(fullpathOnsetFilename); - - delete('tmp.json'); - end function test_convertOnsetTsvToMat_globbing_conditions() % GIVEN - tsvFile = fullfile(getTestDataDir(), ... - 'tsv_files', ... - 'sub-01_task-FaceRepetitionAfter_events.tsv'); opt = setOptions('vismotion'); - - opt.model.bm = BidsModel('file', opt.model.file); + [opt, tmpDir] = setUp(opt); + tsvFile = fullfile(tmpDir, 'sub-01_task-FaceRepetitionAfter_events.tsv'); opt.model.bm.Input.task = {'FaceRepetitionAfter'}; opt.model.bm.Nodes{1}.Model.X = { @@ -130,31 +108,25 @@ function test_convertOnsetTsvToMat_globbing_conditions() fullpathOnsetFilename = convertOnsetTsvToMat(opt, tsvFile); % THEN - assertEqual(fullfile(getTestDataDir(), ... - 'tsv_files', ... - 'sub-01_task-FaceRepetitionAfter_onsets.mat'), ... + assertEqual(fullfile(tmpDir, 'sub-01_task-FaceRepetitionAfter_onsets.mat'), ... fullpathOnsetFilename); assertEqual(exist(fullpathOnsetFilename, 'file'), 2); - load(fullpathOnsetFilename); + load(fullpathOnsetFilename, 'names', 'onsets', 'durations'); assertEqual(names, {'N1', 'N2', 'F1', 'F2'}); assertEqual(cellfun('size', onsets, 2), [26 26 26 26]); assertEqual(cellfun('size', durations, 2), [26 26 26 26]); - cleanUp(fullpathOnsetFilename); - end function test_convertOnsetTsvToMat_warning_missing_variable_to_convolve - tsvFile = fullfile(getTestDataDir(), ... - 'tsv_files', ... - 'sub-01_task-vismotion_events.tsv'); opt = setOptions('vismotion'); opt.model.file = fullfile(getTestDataDir(), 'models', ... 'model-vismotionWithExtraVariable_smdl.json'); - opt.model.bm = BidsModel('file', opt.model.file); + [opt, tmpDir] = setUp(opt); + tsvFile = fullfile(tmpDir, 'sub-01_task-vismotion_events.tsv'); opt.verbosity = 1; @@ -169,13 +141,11 @@ function test_convertOnsetTsvToMat_globbing_conditions() function test_convertOnsetTsvToMat_transformers_with_dummy_regressors % GIVEN - tsvFile = fullfile(getTestDataDir(), ... - 'tsv_files', ... - 'sub-01_task-vismotion_events.tsv'); opt = setOptions('vismotion'); opt.model.file = fullfile(getTestDataDir(), 'models', ... 'model-vismotionWithExtraVariable_smdl.json'); - opt.model.bm = BidsModel('file', opt.model.file); + [opt, tmpDir] = setUp(opt); + tsvFile = fullfile(tmpDir, 'sub-01_task-vismotion_events.tsv'); opt.glm.useDummyRegressor = true; @@ -183,84 +153,71 @@ function test_convertOnsetTsvToMat_globbing_conditions() fullpathOnsetFilename = convertOnsetTsvToMat(opt, tsvFile); % THEN - load(fullpathOnsetFilename); + load(fullpathOnsetFilename, 'names'); assertEqual(names, {'VisMot', 'VisStat', 'dummyRegressor'}); - cleanUp(fullpathOnsetFilename); - end function test_convertOnsetTsvToMat_basic() % GIVEN - tsvFile = fullfile(getTestDataDir(), ... - 'tsv_files', ... - 'sub-01_task-vismotion_events.tsv'); opt = setOptions('vismotion'); - opt.model.bm = BidsModel('file', opt.model.file); + [opt, tmpDir] = setUp(opt); + tsvFile = fullfile(tmpDir, 'sub-01_task-vismotion_events.tsv'); % WHEN fullpathOnsetFilename = convertOnsetTsvToMat(opt, tsvFile); % THEN - assertEqual(fullfile(getTestDataDir(), ... - 'tsv_files', ... - 'sub-01_task-vismotion_onsets.mat'), ... + assertEqual(fullfile(tmpDir, 'sub-01_task-vismotion_onsets.mat'), ... fullpathOnsetFilename); assertEqual(exist(fullpathOnsetFilename, 'file'), 2); - load(fullpathOnsetFilename); + load(fullpathOnsetFilename, 'names', 'onsets', 'durations'); assertEqual(names, {'VisMot', 'VisStat'}); assertEqual(onsets, {2, 4}); assertEqual(durations, {2, 2}); - cleanUp(fullpathOnsetFilename); - end function test_convertOnsetTsvToMat_input_from_non_trial_type_column % GIVEN - tsvFile = fullfile(getTestDataDir(), 'tsv_files', 'sub-01_task-FaceRepetitionBefore_events.tsv'); opt = setOptions('vismotion'); opt.model.file = fullfile(getTestDataDir(), 'models', ... 'model-faceRepetitionNoTrialType_smdl.json'); - opt.model.bm = BidsModel('file', opt.model.file); + [opt, tmpDir] = setUp(opt); + tsvFile = fullfile(tmpDir, 'sub-01_task-FaceRepetitionBefore_events.tsv'); % WHEN fullpathOnsetFilename = convertOnsetTsvToMat(opt, tsvFile); % THEN - load(fullpathOnsetFilename); + load(fullpathOnsetFilename, 'names', 'onsets', 'durations'); assertEqual(names, {'famous', 'unfamiliar'}); assertEqual(numel(onsets{1}), 52); assertEqual(durations, {zeros(1, 52), zeros(1, 52)}); - cleanUp(fullpathOnsetFilename); - end function test_convertOnsetTsvToMat_no_condition_in_design_matrix % GIVEN - tsvFile = fullfile(getTestDataDir(), ... - 'tsv_files', ... - 'sub-01_task-vismotion_events.tsv'); - opt = setOptions('vismotion'); opt.model.file = fullfile(getTestDataDir(), 'models', ... 'model-vismotionNoCondition_smdl.json'); - opt.model.bm = BidsModel('file', opt.model.file); + [opt, tmpDir] = setUp(opt); + tsvFile = fullfile(tmpDir, 'sub-01_task-vismotion_events.tsv'); opt.verbosity = 1; % WHEN fullpathOnsetFilename = convertOnsetTsvToMat(opt, tsvFile); - load(fullpathOnsetFilename); + load(fullpathOnsetFilename, 'names', 'onsets', 'durations'); assertEqual(names, {}); assertEqual(onsets, {}); @@ -271,12 +228,10 @@ function test_convertOnsetTsvToMat_basic() function test_convertOnsetTsvToMat_dummy_regressor() % GIVEN - tsvFile = fullfile(getTestDataDir(), ... - 'tsv_files', ... - 'sub-01_task-vismotion_events.tsv'); opt = setOptions('vismotion'); + [opt, tmpDir] = setUp(opt); + tsvFile = fullfile(tmpDir, 'sub-01_task-vismotion_events.tsv'); - opt.model.bm = BidsModel('file', opt.model.file); opt.model.bm.Nodes{1}.Model.X{1} = 'trial_type.foo'; opt.model.bm.Nodes{1}.Model.HRF.Variables{1} = 'trial_type.foo'; @@ -286,25 +241,21 @@ function test_convertOnsetTsvToMat_dummy_regressor() fullpathOnsetFilename = convertOnsetTsvToMat(opt, tsvFile); % THEN - load(fullpathOnsetFilename); + load(fullpathOnsetFilename, 'names', 'onsets', 'durations'); assertEqual(names, {'dummyRegressor', 'VisStat'}); assertEqual(onsets, {nan, 4}); assertEqual(durations, {nan, 2}); - cleanUp(fullpathOnsetFilename); - end function test_convertOnsetTsvToMat_missing_trial_type() % GIVEN - tsvFile = fullfile(getTestDataDir(), ... - 'tsv_files', ... - 'sub-01_task-vismotion_events.tsv'); opt = setOptions('vismotion'); + [opt, tmpDir] = setUp(opt); + tsvFile = fullfile(tmpDir, 'sub-01_task-vismotion_events.tsv'); - opt.model.bm = BidsModel('file', opt.model.file); opt.model.bm.Nodes{1}.Model.X{1} = 'trial_type.foo'; opt.model.bm.Nodes{1}.Model.HRF.Variables{1} = 'trial_type.foo'; @@ -319,10 +270,12 @@ function test_convertOnsetTsvToMat_missing_trial_type() end -function opt = setUp(opt) +function [opt, tmpDir] = setUp(opt) opt.model.bm = BidsModel('file', opt.model.file); -end + tmpDir = tempName(); + copyfile(fullfile(getTestDataDir(), 'tsv_files'), tmpDir); + if bids.internal.is_octave() + tmpDir = fullfile(tmpDir, 'tsv_files'); + end -function cleanUp(inputFile) - delete(inputFile); end diff --git a/tests/tests_stats/subject_level/test_createAndReturnCounfoundMatFile.m b/tests/tests_stats/subject_level/test_createAndReturnCounfoundMatFile.m index eac5f22c4..beb4fb4ea 100644 --- a/tests/tests_stats/subject_level/test_createAndReturnCounfoundMatFile.m +++ b/tests/tests_stats/subject_level/test_createAndReturnCounfoundMatFile.m @@ -1,6 +1,5 @@ -% (C) Copyright 2021 bidspm developers - function test_suite = test_createAndReturnCounfoundMatFile %#ok<*STOUT> + % (C) Copyright 2021 bidspm developers try % assignment of 'localfunctions' is necessary in Matlab >= 2016 test_functions = localfunctions(); %#ok<*NASGU> catch % no problem; early Matlab versions can use initTestSuite fine diff --git a/tests/tests_stats/subject_level/test_getEventSpecificationRoiGlm.m b/tests/tests_stats/subject_level/test_getEventSpecificationRoiGlm.m index b72fd7a39..b8c9fc16d 100644 --- a/tests/tests_stats/subject_level/test_getEventSpecificationRoiGlm.m +++ b/tests/tests_stats/subject_level/test_getEventSpecificationRoiGlm.m @@ -1,15 +1,10 @@ function test_suite = test_getEventSpecificationRoiGlm %#ok<*STOUT> - % - % (C) Copyright 2019 bidspm developers - try % assignment of 'localfunctions' is necessary in Matlab >= 2016 test_functions = localfunctions(); %#ok<*NASGU> catch % no problem; early Matlab versions can use initTestSuite fine end - initTestSuite; - end % TODO @@ -46,8 +41,6 @@ function test_getEventSpecificationRoiGlm_basic() assertEqual(event_specification(5).eventSpec, [1 1 1 1; 1 2 3 4]); assertEqual(event_specification(5).duration, 0); - cleanUp(); - end function test_getEventSpecificationRoiGlm_warning_complex_contrasts() @@ -74,7 +67,3 @@ function test_getEventSpecificationRoiGlm_warning_complex_contrasts() 'model-faceRepetition_smdl.json'); end - -function cleanUp() - -end diff --git a/tests/tests_stats/subject_level/test_orderAndPadCounfoundMatFile.m b/tests/tests_stats/subject_level/test_orderAndPadCounfoundMatFile.m index 9abc0b1ea..2c624acc4 100644 --- a/tests/tests_stats/subject_level/test_orderAndPadCounfoundMatFile.m +++ b/tests/tests_stats/subject_level/test_orderAndPadCounfoundMatFile.m @@ -1,25 +1,24 @@ function test_suite = test_orderAndPadCounfoundMatFile %#ok<*STOUT> - % - % (C) Copyright 2022 bidspm developers - try % assignment of 'localfunctions' is necessary in Matlab >= 2016 test_functions = localfunctions(); %#ok<*NASGU> catch % no problem; early Matlab versions can use initTestSuite fine end - initTestSuite; - end function test_orderAndPadCounfoundMatFile_different_nb_confounds() + tmpDir = tempName(); + copyfile(fullfile(getTestDataDir, 'mat_files'), tmpDir); + if bids.internal.is_octave() + tmpDir = fullfile(tmpDir, 'mat_files'); + end + % GIVEN - spmSess(1).counfoundMatFile = fullfile(getTestDataDir, ... - 'mat_files', ... + spmSess(1).counfoundMatFile = fullfile(tmpDir, ... 'task-olfid_desc-confounds_regressors.mat'); - spmSess(2).counfoundMatFile = fullfile(getTestDataDir, ... - 'mat_files', ... + spmSess(2).counfoundMatFile = fullfile(tmpDir, ... 'task-olfid_motion.mat'); opt.glm.useDummyRegressor = true; @@ -33,8 +32,6 @@ function test_orderAndPadCounfoundMatFile_different_nb_confounds() assertLessThan(numel(in.names), numel(out.names)); assertEqual(numel(out.names), size(out.R, 2)); - delete(spmSessOut(2).counfoundMatFile); - end function test_orderAndPadCounfoundMatFile_one_session() @@ -66,11 +63,3 @@ function test_orderAndPadCounfoundMatFile_no_dummy_required() assertEqual(spmSessOut, spmSess); end - -function setUp() - -end - -function cleanUp() - -end diff --git a/tests/tests_stats/subject_level/test_reorderCounfounds.m b/tests/tests_stats/subject_level/test_reorderCounfounds.m index e3a740991..f8a1652b3 100644 --- a/tests/tests_stats/subject_level/test_reorderCounfounds.m +++ b/tests/tests_stats/subject_level/test_reorderCounfounds.m @@ -7,9 +7,7 @@ test_functions = localfunctions(); %#ok<*NASGU> catch % no problem; early Matlab versions can use initTestSuite fine end - initTestSuite; - end function test_reorderCounfounds_missing() diff --git a/tests/tests_stats/subject_level/test_sanitizeConfounds.m b/tests/tests_stats/subject_level/test_sanitizeConfounds.m index 4a79693c1..212e0450e 100644 --- a/tests/tests_stats/subject_level/test_sanitizeConfounds.m +++ b/tests/tests_stats/subject_level/test_sanitizeConfounds.m @@ -5,9 +5,7 @@ test_functions = localfunctions(); %#ok<*NASGU> catch % no problem; early Matlab versions can use initTestSuite fine end - initTestSuite; - end function test_sanitizeConfounds_basic() diff --git a/tests/tests_stats/subject_level/test_saveRoiGlmSummaryTable.m b/tests/tests_stats/subject_level/test_saveRoiGlmSummaryTable.m index 6d7abe1e4..9e0316d0e 100644 --- a/tests/tests_stats/subject_level/test_saveRoiGlmSummaryTable.m +++ b/tests/tests_stats/subject_level/test_saveRoiGlmSummaryTable.m @@ -7,9 +7,7 @@ test_functions = localfunctions(); %#ok<*NASGU> catch % no problem; early Matlab versions can use initTestSuite fine end - initTestSuite; - end function test_saveRoiGlmSummaryTable_checks() diff --git a/tests/tests_stats/subject_level/test_specifyContrasts.m b/tests/tests_stats/subject_level/test_specifyContrasts.m index f75e2395a..62f6fc42e 100644 --- a/tests/tests_stats/subject_level/test_specifyContrasts.m +++ b/tests/tests_stats/subject_level/test_specifyContrasts.m @@ -13,9 +13,6 @@ function test_specifyContrasts_vismotion_F_contrast() % Note requires an SPM.mat to run % - % TODO: fixturize - createDummyData(); - % GIVEN subLabel = '01'; @@ -112,9 +109,6 @@ function test_specifyContrasts_subject_level_F_contrast() function test_specifyContrasts_bug_854() - % TODO: fixturize - createDummyData(); - % GIVEN subLabel = '01'; @@ -491,9 +485,6 @@ function test_specifyContrasts_vismotion() % Note requires an SPM.mat to run % - % TODO: fixturize - createDummyData(); - % GIVEN subLabel = '01'; @@ -543,9 +534,6 @@ function test_specifyContrasts_vislocalizer() % Note requires an SPM.mat to run % - % TODO: fixturize - createDummyData(); - % GIVEN subLabel = '01'; diff --git a/tests/tests_stats/unit_tests/test_concatenateConfounds.m b/tests/tests_stats/unit_tests/test_concatenateConfounds.m index e3a0af9a7..58b874590 100644 --- a/tests/tests_stats/unit_tests/test_concatenateConfounds.m +++ b/tests/tests_stats/unit_tests/test_concatenateConfounds.m @@ -5,9 +5,7 @@ test_functions = localfunctions(); %#ok<*NASGU> catch % no problem; early Matlab versions can use initTestSuite fine end - initTestSuite; - end function test_concatenateConfounds_basic() diff --git a/tests/tests_stats/unit_tests/test_concatenateImages.m b/tests/tests_stats/unit_tests/test_concatenateImages.m index 187f7f953..739afade2 100644 --- a/tests/tests_stats/unit_tests/test_concatenateImages.m +++ b/tests/tests_stats/unit_tests/test_concatenateImages.m @@ -5,9 +5,7 @@ test_functions = localfunctions(); %#ok<*NASGU> catch % no problem; early Matlab versions can use initTestSuite fine end - initTestSuite; - end function test_concatenateImages_basic() diff --git a/tests/tests_stats/unit_tests/test_concatenateOnsets.m b/tests/tests_stats/unit_tests/test_concatenateOnsets.m index 18d709568..215389351 100644 --- a/tests/tests_stats/unit_tests/test_concatenateOnsets.m +++ b/tests/tests_stats/unit_tests/test_concatenateOnsets.m @@ -5,9 +5,7 @@ test_functions = localfunctions(); %#ok<*NASGU> catch % no problem; early Matlab versions can use initTestSuite fine end - initTestSuite; - end function test_concatenateOnsets_basic() diff --git a/tests/tests_stats/unit_tests/test_designMatrixFigureName.m b/tests/tests_stats/unit_tests/test_designMatrixFigureName.m index 66a6a1b2a..3957aa5f8 100644 --- a/tests/tests_stats/unit_tests/test_designMatrixFigureName.m +++ b/tests/tests_stats/unit_tests/test_designMatrixFigureName.m @@ -7,9 +7,7 @@ test_functions = localfunctions(); %#ok<*NASGU> catch % no problem; early Matlab versions can use initTestSuite fine end - initTestSuite; - end function test_designMatrixFigureName_basic() diff --git a/tests/tests_stats/utils/test_printAvailableContrasts.m b/tests/tests_stats/utils/test_printAvailableContrasts.m index 6963d368b..58485f0ea 100644 --- a/tests/tests_stats/utils/test_printAvailableContrasts.m +++ b/tests/tests_stats/utils/test_printAvailableContrasts.m @@ -18,12 +18,12 @@ function test_printAvailableContrasts_basic() printAvailableContrasts(SPM, opt); - save(fullfile(pwd, 'SPM.mat'), 'SPM'); + tmpDir = tempName(); - printAvailableContrasts(fullfile(pwd, 'SPM.mat'), opt); + save(fullfile(tmpDir, 'SPM.mat'), 'SPM'); - printAvailableContrasts(SPM); + printAvailableContrasts(fullfile(tmpDir, 'SPM.mat'), opt); - delete(fullfile(pwd, 'SPM.mat')); + printAvailableContrasts(SPM); end diff --git a/tests/tests_unit/IO/test_saveOptions.m b/tests/tests_unit/IO/test_saveOptions.m index fca41ed76..92cb6d943 100644 --- a/tests/tests_unit/IO/test_saveOptions.m +++ b/tests/tests_unit/IO/test_saveOptions.m @@ -1,6 +1,5 @@ -% (C) Copyright 2020 bidspm developers - function test_suite = test_saveOptions %#ok<*STOUT> + % (C) Copyright 2020 bidspm developers try % assignment of 'localfunctions' is necessary in Matlab >= 2016 test_functions = localfunctions(); %#ok<*NASGU> catch % no problem; early Matlab versions can use initTestSuite fine @@ -11,6 +10,7 @@ function test_saveOptions_basic() opt = setOptions('dummy'); + opt.dir.derivatives = tempName(); saveOptions(opt); @@ -18,6 +18,4 @@ function test_saveOptions_basic() assertEqual(exist(expected, 'file'), 2); - cleanUp(fullfile(opt.dir.derivatives, 'options')); - end diff --git a/tests/tests_unit/IO/test_saveSpmScript.m b/tests/tests_unit/IO/test_saveSpmScript.m index bde5470b3..c58674e18 100644 --- a/tests/tests_unit/IO/test_saveSpmScript.m +++ b/tests/tests_unit/IO/test_saveSpmScript.m @@ -1,19 +1,16 @@ function test_suite = test_saveSpmScript %#ok<*STOUT> - % - % (C) Copyright 2022 bidspm developers - try % assignment of 'localfunctions' is necessary in Matlab >= 2016 test_functions = localfunctions(); %#ok<*NASGU> catch % no problem; early Matlab versions can use initTestSuite fine end - initTestSuite; - end function test_saveSpmScript_basic() + PWD = setUp(); + % GIVEN matlabbatch{1}.cfg_basicio.cfg_named_file.name = 'Anatomical'; anatFile = fullfile('home', 'smith', 'raw', 'sub-01', 'anat', 'sub-01_T1w.nii'); @@ -40,12 +37,14 @@ function test_saveSpmScript_basic() assertEqual(actualContent, expectedContent); - cleanUp(); + cd(PWD); end function test_saveSpmScript_output_name() + PWD = setUp(); + % GIVEN matlabbatch{1}.cfg_basicio.cfg_named_file.name = 'Anatomical'; anatFile = fullfile('home', 'smith', 'raw', 'sub-01', 'anat', 'sub-01_T1w.nii'); @@ -61,7 +60,7 @@ function test_saveSpmScript_output_name() expectedContent = fullfile(getTestDataDir(), 'dummy_batch.m'); compareContent(outputFilename, expectedFile); - cleanUp(); + cd(PWD); end @@ -69,21 +68,23 @@ function test_saveSpmScript_from_file() % TODO add tests to overwrite output filename + tmpDir = tempName(); + copyfile(fullfile(getTestDataDir(), 'mat_files'), tmpDir); + if bids.internal.is_octave + tmpDir = fullfile(tmpDir, 'mat_files'); + end + % GIVEN - inputMatFile = fullfile(getTestDataDir(), 'mat_files', 'dummy_batch.mat'); + inputMatFile = fullfile(tmpDir, 'dummy_batch.mat'); % WHEN outputFilename = saveSpmScript(inputMatFile); % THEN - expectedFile = fullfile(getTestDataDir(), 'mat_files', 'dummy_batch.m'); + expectedFile = fullfile(tmpDir, 'dummy_batch.m'); assertEqual(exist(expectedFile, 'file'), 2); - - expectedFile = fullfile(getTestDataDir(), 'dummy_batch.m'); compareContent(outputFilename, expectedFile); - cleanUp(); - end function compareContent(actualFile, expectedFile) @@ -100,13 +101,9 @@ function compareContent(actualFile, expectedFile) end -function setUp() - -end - -function cleanUp() - - delete batch*.m; - delete(fullfile(getTestDataDir(), 'mat_files', 'dummy_batch.m')); - +function PWD = setUp() + PWD = pwd; + tmpDir = tempName(); + cd(tmpDir); + spm_mkdir cfg; end diff --git a/tests/tests_unit/test_cleanCrash.m b/tests/tests_unit/test_cleanCrash.m index a0e463496..cf198a824 100644 --- a/tests/tests_unit/test_cleanCrash.m +++ b/tests/tests_unit/test_cleanCrash.m @@ -1,6 +1,5 @@ -% (C) Copyright 2020 bidspm developers - function test_suite = test_cleanCrash %#ok<*STOUT> + % (C) Copyright 2020 bidspm developers try % assignment of 'localfunctions' is necessary in Matlab >= 2016 test_functions = localfunctions(); %#ok<*NASGU> catch % no problem; early Matlab versions can use initTestSuite fine @@ -10,14 +9,18 @@ function test_cleanCrash_basic() - system('touch spm_001.png'); - system('touch 001.png'); + tmpDir = tempName(); + PWD = pwd; + cd(tmpDir); + + touch('spm_001.png'); + touch('001.png'); cleanCrash(); - assertEqual(exist(fullfile(pwd, '001.png'), 'file'), 2); - assertEqual(exist(fullfile(pwd, 'spm_001.png'), 'file'), 0); + assertEqual(exist(fullfile(tmpDir, '001.png'), 'file'), 2); + assertEqual(exist(fullfile(tmpDir, 'spm_001.png'), 'file'), 0); - delete(fullfile(pwd, '001.png')); + cd(PWD); end diff --git a/tests/tests_unit/test_copyGraphWindownOutput.m b/tests/tests_unit/test_copyGraphWindownOutput.m index bfc69fe4e..7699595a0 100644 --- a/tests/tests_unit/test_copyGraphWindownOutput.m +++ b/tests/tests_unit/test_copyGraphWindownOutput.m @@ -1,6 +1,5 @@ -% (C) Copyright 2020 bidspm developers - function test_suite = test_copyGraphWindownOutput %#ok<*STOUT> + % (C) Copyright 2020 bidspm developers try % assignment of 'localfunctions' is necessary in Matlab >= 2016 test_functions = localfunctions(); %#ok<*NASGU> catch % no problem; early Matlab versions can use initTestSuite fine @@ -10,26 +9,25 @@ function test_copyGraphWindownOutput_basic() - [opt, subLabel, action] = setUp(); + [opt, subLabel, action, PWD] = setUp(); imgNb = 1:2; - system('touch spm_001.png'); - system('touch spm_002.png'); + touch(fullfile(opt.dir.preproc, 'spm_001.png')); + touch(fullfile(opt.dir.preproc, 'spm_002.png')); imgNb = copyGraphWindownOutput(opt, subLabel, action, imgNb); assertEqual(imgNb, 3); - files = spm_select( ... - 'List', ... + files = spm_select('List', ... fullfile(opt.dir.preproc, ['sub-' subLabel], 'figures'), ... ['^' datestr(now, 'yyyymmddHH') '.*_[0-9]_sub-01_task-dummy_testStep.png']); assert(~isempty(files)); assertEqual(size(files, 1), 2); - cleanUp(fullfile(opt.dir.preproc, ['sub-' subLabel])); + cd(PWD); end @@ -39,36 +37,34 @@ function test_copyGraphWindownOutput_warning() moxunit_throw_test_skipped_exception('Octave:mixed-string-concat warning thrown'); end - [opt, subLabel, action] = setUp(); + [opt, subLabel, action, PWD] = setUp(); opt.verbosity = 1; - system('touch spm_002.png'); - system('touch spm_test_002.png'); + touch(fullfile(opt.dir.preproc, 'spm_002.png')); + touch(fullfile(opt.dir.preproc, 'spm_test_002.png')); - assertWarning( ... - @()copyGraphWindownOutput(opt, subLabel, action, 2), ... + assertWarning(@()copyGraphWindownOutput(opt, subLabel, action, 2), ... 'copyGraphWindownOutput:tooManyFiles'); - assertWarning( ... - @()copyGraphWindownOutput(opt, subLabel, action, 3), ... + assertWarning(@()copyGraphWindownOutput(opt, subLabel, action, 3), ... 'copyGraphWindownOutput:noFile'); - cleanUp(fullfile(opt.dir.preproc, ['sub-' subLabel])); + cd(PWD); end -function [opt, subLabel, action] = setUp() - - delete('*.png'); +function [opt, subLabel, action, PWD] = setUp() - pause(1); + PWD = pwd; subLabel = '01'; opt = setOptions('dummy', subLabel); opt.verbosity = 0; - opt.dir.preproc = pwd; + opt.dir.preproc = tempName(); action = 'testStep'; + cd(opt.dir.preproc); + end diff --git a/tests/tests_unit/test_matToTsv.m b/tests/tests_unit/test_matToTsv.m index a5e4cf91d..238f6c2c7 100644 --- a/tests/tests_unit/test_matToTsv.m +++ b/tests/tests_unit/test_matToTsv.m @@ -1,48 +1,37 @@ function test_suite = test_matToTsv %#ok<*STOUT> - % - % (C) Copyright 2022 bidspm developers - try % assignment of 'localfunctions' is necessary in Matlab >= 2016 test_functions = localfunctions(); %#ok<*NASGU> catch % no problem; early Matlab versions can use initTestSuite fine end - initTestSuite; - end function test_onsetMatToTsv_basic() - % GIVEN - onsetsMatFile = fullfile(getTestDataDir(), 'mat_files', 'task-olfid_onsets.mat'); - % WHEN - onsetsTsvFile = onsetsMatToTsv(onsetsMatFile); - % THEN - assertEqual(exist(onsetsTsvFile, 'file'), 2); + tmpDir = tempName(); + copyfile(fullfile(getTestDataDir(), 'mat_files'), tmpDir); + if bids.internal.is_octave() + tmpDir = fullfile(tmpDir, 'mat_files'); + end - cleanUp(onsetsTsvFile); + onsetsMatFile = fullfile(tmpDir, 'task-olfid_onsets.mat'); + onsetsTsvFile = onsetsMatToTsv(onsetsMatFile); + + assertEqual(exist(onsetsTsvFile, 'file'), 2); end function test_regressorsMatToTsv_basic() + tmpDir = tempName(); + copyfile(fullfile(getTestDataDir(), 'mat_files'), tmpDir); + if bids.internal.is_octave() + tmpDir = fullfile(tmpDir, 'mat_files'); + end - % GIVEN - regressorsMatFile = fullfile(getTestDataDir(), 'mat_files', ... - 'task-olfid_desc-confounds_regressors.mat'); - % WHEN - regressorsTsvFile = regressorsMatToTsv(regressorsMatFile); - % THEN - assertEqual(exist(regressorsTsvFile, 'file'), 2); - - cleanUp(regressorsTsvFile); - -end - -function setUp() + regressorsMatFile = fullfile(tmpDir, 'task-olfid_desc-confounds_regressors.mat'); -end + regressorsTsvFile = regressorsMatToTsv(regressorsMatFile); -function cleanUp(file) - delete(file); + assertEqual(exist(regressorsTsvFile, 'file'), 2); end diff --git a/tests/tests_unit/test_renamePng.m b/tests/tests_unit/test_renamePng.m index 1786d5743..56662312f 100644 --- a/tests/tests_unit/test_renamePng.m +++ b/tests/tests_unit/test_renamePng.m @@ -10,15 +10,10 @@ function test_renamePng_basic() - outputDir = fullfile(pwd, 'tmp'); + outputDir = tempName(); - if isdir(outputDir) - rmdir(outputDir, 's'); - end - - mkdir(outputDir); - system('touch tmp/sub-foo_designmatrix_001.png'); - system('touch tmp/sub-foo_designmatrix_002.png'); + touch(fullfile(outputDir, 'sub-foo_designmatrix_001.png')); + touch(fullfile(outputDir, 'sub-foo_designmatrix_002.png')); files = dir(fullfile(outputDir, 'sub*_00*.png')); assertEqual(numel(files), 2); @@ -31,6 +26,4 @@ function test_renamePng_basic() files = dir(fullfile(outputDir, 'sub*_designmatrix.png')); assertEqual(numel(files), 1); - rmdir(outputDir, 's'); - end diff --git a/tests/tests_unit/test_returnVolumeList.m b/tests/tests_unit/test_returnVolumeList.m index 2806b1e5e..559eee6b2 100644 --- a/tests/tests_unit/test_returnVolumeList.m +++ b/tests/tests_unit/test_returnVolumeList.m @@ -7,9 +7,7 @@ test_functions = localfunctions(); %#ok<*NASGU> catch % no problem; early Matlab versions can use initTestSuite fine end - initTestSuite; - end function test_returnVolumeList_basic() diff --git a/tests/tests_unit/test_volumeSplicing.m b/tests/tests_unit/test_volumeSplicing.m index aaa234d61..74a3e4849 100644 --- a/tests/tests_unit/test_volumeSplicing.m +++ b/tests/tests_unit/test_volumeSplicing.m @@ -1,6 +1,5 @@ -% (C) Copyright 2022 bidspm developers - function test_suite = test_volumeSplicing %#ok<*STOUT> + % (C) Copyright 2022 bidspm developers try % assignment of 'localfunctions' is necessary in Matlab >= 2016 test_functions = localfunctions(); %#ok<*NASGU> catch % no problem; early Matlab versions can use initTestSuite fine diff --git a/tests/tests_unit/test_warnings.m b/tests/tests_unit/test_warnings.m index fec5d9a73..e3b4cf974 100644 --- a/tests/tests_unit/test_warnings.m +++ b/tests/tests_unit/test_warnings.m @@ -7,9 +7,7 @@ test_functions = localfunctions(); %#ok<*NASGU> catch % no problem; early Matlab versions can use initTestSuite fine end - initTestSuite; - end function test_noSPMmat() diff --git a/tests/tests_utils/test_loadAndCheckOptions.m b/tests/tests_utils/test_loadAndCheckOptions.m index c0c43d450..e719f9530 100644 --- a/tests/tests_utils/test_loadAndCheckOptions.m +++ b/tests/tests_utils/test_loadAndCheckOptions.m @@ -1,6 +1,5 @@ -% (C) Copyright 2020 bidspm developers - function test_suite = test_loadAndCheckOptions %#ok<*STOUT> + % (C) Copyright 2020 bidspm developers try % assignment of 'localfunctions' is necessary in Matlab >= 2016 test_functions = localfunctions(); %#ok<*NASGU> catch % no problem; early Matlab versions can use initTestSuite fine @@ -10,7 +9,7 @@ function test_loadAndCheckOptions_basic() - setUp(); + PWD = setUp(); % create dummy json file jsonContent.taskName = 'vismotion'; @@ -25,13 +24,12 @@ function test_loadAndCheckOptions_basic() expectedOptions.verbosity = 0; assertEqual(opt, expectedOptions); - cleanUp(fullfile(pwd, 'cfg')); - + teardown(PWD); end function test_loadAndCheckOptions_structure() - setUp(); + PWD = setUp(); % create dummy json file opt = setTestCfg(); @@ -45,13 +43,12 @@ function test_loadAndCheckOptions_structure() assertEqual(opt, expectedOptions); - cleanUp(fullfile(pwd, 'cfg')); - + teardown(PWD); end function test_loadAndCheckOptions_from_file() - setUp(); + PWD = setUp(); % create dummy json file jsonContent.taskName = 'vismotion'; @@ -72,13 +69,12 @@ function test_loadAndCheckOptions_from_file() assertEqual(opt, expectedOptions); - cleanUp(fullfile(pwd, 'cfg')); - + teardown(PWD); end function test_loadAndCheckOptions_from_several_files() - setUp(); + PWD = setUp(); % create old dummy json file jsonContent.taskName = 'vismotion'; @@ -113,13 +109,12 @@ function test_loadAndCheckOptions_from_several_files() assertEqual(opt, expectedOptions); - cleanUp(fullfile(pwd, 'cfg')); - + teardown(PWD); end function test_loadAndCheckOptions_moae() - setUp(); + PWD = setUp(); jsonContent = setOptions('MoAE'); jsonContent.verbosity = 0; @@ -129,18 +124,22 @@ function test_loadAndCheckOptions_moae() opt = loadAndCheckOptions(optionJsonFile); - cleanUp(fullfile(pwd, 'cfg')); + teardown(PWD); end -function setUp +function PWD = setUp() + PWD = pwd; + tmpDir = tempName(); + cd(tmpDir); spm_mkdir cfg; - delete(fullfile(pwd, 'cfg', '*.json')); end -function opt = setTestCfg() +function teardown(pth) + cd(pth); +end +function opt = setTestCfg() opt.verbosity = 0; opt.dryRun = true; - end diff --git a/tests/utils/getLayout.m b/tests/utils/getLayout.m index 1266e8050..fb307fa7c 100644 --- a/tests/utils/getLayout.m +++ b/tests/utils/getLayout.m @@ -7,7 +7,10 @@ try load(fullfile(opt.dir.preproc, 'layout.mat'), 'BIDS'); catch - BIDS = bids.layout(opt.dir.preproc, 'use_schema', false, 'verbose', opt.verbosity > 0, ... + fprintf('\n\n\t\tINDEXING: %s \n\n', opt.dir.preproc); + BIDS = bids.layout(opt.dir.preproc, ... + 'use_schema', false, ... + 'verbose', opt.verbosity > 0, ... 'index_dependencies', false); BIDS.raw = bids.layout(opt.dir.raw); end diff --git a/tests/utils/setOptions.m b/tests/utils/setOptions.m index ee4b123a4..61c8b93de 100644 --- a/tests/utils/setOptions.m +++ b/tests/utils/setOptions.m @@ -19,6 +19,7 @@ addOptional(args, 'subLabel', default_subLabel, charOrCell); addParameter(args, 'useRaw', default_useRaw, @islogical); addParameter(args, 'pipelineType', default_pipelineType); + addParameter(args, 'useTempDir', false); parse(args, varargin{:}); @@ -135,9 +136,22 @@ opt = checkOptions(opt); - useRaw = args.Results.useRaw; - if useRaw + if args.Results.useRaw opt.dir.preproc = getTestDataDir('raw'); end + if args.Results.useTempDir + tmpDir = tempName(); + copyfile(getTestDataDir(), tmpDir); + if bids.internal.is_octave() + tmpDir = fullfile(tmpDir, 'data'); + end + dirsToUpdate = {'stats', 'derivatives', 'preproc', 'raw', 'input', 'jobs', 'output'}; + for i = 1:numel(dirsToUpdate) + opt.dir.(dirsToUpdate{i}) = strrep(opt.dir.(dirsToUpdate{i}), ... + getTestDataDir(), ... + tmpDir); + end + end + end diff --git a/tests/utils/touch.m b/tests/utils/touch.m new file mode 100644 index 000000000..d9b4c2c72 --- /dev/null +++ b/tests/utils/touch.m @@ -0,0 +1,15 @@ +function touch(filename) + % (C) Copyright 2023 bidspm developers + [pth, file, ext] = fileparts(filename); + if isempty(pth) + pth = pwd; + end + spm_mkdir(pth); + + filename = fullfile(pth, [file, ext]); + + fid = fopen(filename, 'w'); + fprintf(fid, 'this is a dummy file'); + fclose(fid); + +end