Skip to content
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ demos/spm*/raw
demos/spm*/source

# test folder and dummy data
tests/cfg/*.json
tests/sub-01/*
tests/group/*
tests/models/*.json
Expand Down
4 changes: 3 additions & 1 deletion src/utils/loadAndCheckOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
% - add test for when the input is a structure.

if nargin < 1 || isempty(optionJsonFile)
optionJsonFile = spm_select('FPList', pwd, '^options_task-.*.json$');
optionJsonFile = spm_select('FPList', ...
fullfile(pwd, 'cfg'), ...
'^options_task-.*.json$');
end

if isstruct(optionJsonFile)
Expand Down
4 changes: 3 additions & 1 deletion src/utils/saveOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ function saveOptions(opt)
% :type opt: structure
%

filename = fullfile(pwd, ['options', ...
optionDir = fullfile(pwd, 'cfg');
[~,~,~] = mkdir(optionDir);
filename = fullfile(optionDir, ['options', ...
'_task-', opt.taskName, ...
'_date-' datestr(now, 'yyyymmddHHMM'), ...
'.json']);
Expand Down
36 changes: 21 additions & 15 deletions tests/test_loadAndCheckOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@

function test_loadAndCheckOptionsBasic()

delete('*.json');
mkdir cfg;
delete(fullfile(pwd, 'cfg', '*.json'));

% create dummy json file
jsonContent.taskName = 'vismotion';
filename = 'options_task-vismotion.json';
filename = fullfile(pwd, 'cfg', 'options_task-vismotion.json');
spm_jsonwrite(filename, jsonContent);

% makes sure that it is picked up by default
Expand All @@ -27,6 +28,9 @@ function test_loadAndCheckOptionsBasic()

function test_loadAndCheckOptionsStructure()

mkdir cfg;
delete(fullfile(pwd, 'cfg', '*.json'));

% create dummy json file
opt.taskName = 'vismotion';

Expand All @@ -42,19 +46,20 @@ function test_loadAndCheckOptionsStructure()

function test_loadAndCheckOptionsFromFile()

delete('*.json');
mkdir cfg;
delete(fullfile(pwd, 'cfg', '*.json'));

% create dummy json file
jsonContent.taskName = 'vismotion';
jsonContent.space = 'individual';
jsonContent.groups = {''};
jsonContent.subjects = {[]};

filename = 'options_task-vismotion_space-T1w.json';
filename = fullfile(pwd, 'cfg', 'options_task-vismotion_space-T1w.json');
spm_jsonwrite(filename, jsonContent);

% makes sure that it is read correctly from
opt = loadAndCheckOptions('options_task-vismotion_space-T1w.json');
opt = loadAndCheckOptions(filename);

expectedOptions = defaultOptions();
expectedOptions.taskName = 'vismotion';
Expand All @@ -68,30 +73,31 @@ function test_loadAndCheckOptionsFromFile()

function test_loadAndCheckOptionsFromSeveralFiles()

delete('*.json');
mkdir cfg;
delete(fullfile(pwd, 'cfg', '*.json'));

% create old dummy json file
jsonContent.taskName = 'vismotion';
filename = fullfile(pwd, ['options', ...
'_task-', jsonContent.taskName, ...
'_date-151501011111', ...
'.json']);
filename = fullfile(pwd, 'cfg', ['options', ...
'_task-', jsonContent.taskName, ...
'_date-151501011111', ...
'.json']);
spm_jsonwrite(filename, jsonContent);

% create dummy json file with no date
jsonContent.taskName = 'vismotion';
jsonContent.space = 'individual';
filename = 'options_task-vismotion_space-T1w.json';
filename = fullfile(pwd, 'cfg', 'options_task-vismotion_space-T1w.json');
spm_jsonwrite(filename, jsonContent);

% most recent option file that should be read from
jsonContent.taskName = 'vismotion';
jsonContent.space = 'individual';
jsonContent.funcVoxelDims = [1 1 1];
filename = fullfile(pwd, ['options', ...
'_task-', jsonContent.taskName, ...
'_date-' datestr(now, 'yyyymmddHHMM'), ...
'.json']);
filename = fullfile(pwd, 'cfg', ['options', ...
'_task-', jsonContent.taskName, ...
'_date-' datestr(now, 'yyyymmddHHMM'), ...
'.json']);
spm_jsonwrite(filename, jsonContent);

% makes sure that the right json is read
Expand Down