Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MAINT] remove test pollution #1134

Merged
merged 11 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/run_tests_notebooks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/tests_windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions bidspm.m
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,8 @@ function uninitBidspm()
end
testFolder = fullfile(pwd, 'tests', subfolder);

generateLayoutMat();

returnCode = moxunit_runtests(testFolder, ...
'-verbose', '-recursive', '-randomize_order', ...
'-with_coverage', ...
Expand Down
12 changes: 5 additions & 7 deletions demos/face_repetition/test_face_rep.m
Original file line number Diff line number Diff line change
Expand Up @@ -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, '..', '..'));
Expand Down Expand Up @@ -69,8 +67,8 @@
'task', 'facerepetition', ...
'space', {'IXI549Space'}, ...
'ignore', ignore, ...
'options', opt, ...
'skip_validation', skip_validation);
'verbosity', VERBOSITY, ...
'options', opt);

%% stats

Expand Down Expand Up @@ -106,7 +104,7 @@
'preproc_dir', [preproc_dir '-preproc'], ...
'model_file', newModel, ...
'options', opt, ...
'skip_validation', skip_validation, ...
'verbosity', VERBOSITY, ...
'concatenate', true);

end
3 changes: 2 additions & 1 deletion src/IO/saveSpmScript.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)
%
Expand Down
4 changes: 2 additions & 2 deletions src/stats/subject_level/getConfoundsRegressorFilename.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/workflows/bidsQApreproc.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

[BIDS, opt] = setUpWorkflow(opt, 'preprocessing quality control');

visible = 'off';

Check warning on line 37 in src/workflows/bidsQApreproc.m

View check run for this annotation

Codecov / codecov/patch

src/workflows/bidsQApreproc.m#L37

Added line #L37 was not covered by tests
if opt.verbosity > 1
visible = 'on';
end
Expand Down
2 changes: 0 additions & 2 deletions tests/tests_batches/preproc/test_setBatchSTC.m
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@

function test_setBatchSubjectLevelContrasts_F_contrast()

% TODO: fixturize
createDummyData();

subLabel = '01';

opt = setOptions('vismotion', subLabel, 'pipelineType', 'stats');
Expand Down Expand Up @@ -46,9 +43,6 @@ function test_setBatchSubjectLevelContrasts_F_contrast()

function test_setBatchSubjectLevelContrasts_basic()

% TODO: fixturize
createDummyData();

subLabel = '01';

opt = setOptions('vismotion', subLabel, 'pipelineType', 'stats');
Expand Down Expand Up @@ -106,9 +100,6 @@ function test_setBatchSubjectLevelContrasts_basic()

function test_setBatchSubjectLevelContrasts_select_node()

% TODO: fixturize
createDummyData();

subLabel = '01';

opt = setOptions('vismotion', subLabel, 'pipelineType', 'stats');
Expand Down
18 changes: 12 additions & 6 deletions tests/tests_batches/stats/test_setBatchSubjectLevelGLMSpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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');

Expand Down Expand Up @@ -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');
Expand Down
9 changes: 0 additions & 9 deletions tests/tests_batches/stats/test_setBatchSubjectLevelResults.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@

function test_setBatchSubjectLevelResults_basic()

% TODO: fixturize
createDummyData();

% IF
contrast_name = 'VisMot';
[subLabel, opt, result] = setUp('vismotion', contrast_name);
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 2 additions & 3 deletions tests/tests_batches/test_saveMatlabBatch.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
30 changes: 5 additions & 25 deletions tests/tests_batches/test_setBachRename.m
Original file line number Diff line number Diff line change
@@ -1,52 +1,32 @@
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';
patternReplace(2).repl = 'segparam';

% 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
23 changes: 23 additions & 0 deletions tests/tests_batches/test_setBatchInverseNormalize.m
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 0 additions & 2 deletions tests/tests_bids/test_fileFilterForBold.m
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 0 additions & 2 deletions tests/tests_bids/test_getROIs.m
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading
Loading