Skip to content

Commit 0c49945

Browse files
authored
Merge pull request #167 from Remi-Gau/remi-reorganize_test_template_folders
[INFRA] reorganize test and template folders
2 parents 900dcec + 143d3cf commit 0c49945

12 files changed

+45
-80
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ before_script:
3939
# Add to src functions to path
4040
- octave $OCTFLAGS --eval "addpath(genpath(fullfile(pwd, 'src'))); savepath ();"
4141
# Change current directory
42-
- cd manualTests
42+
- cd tests/manualTests
4343

4444
jobs:
4545
include:

manualTests/miss_hit.cfg

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/convertSourceToRaw.m

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,13 @@ function convertSourceToRaw(cfg)
2323
rawDir = fullfile(cfg.dir.output, 'raw');
2424

2525
% add dummy README and CHANGE file
26-
copyfile(fullfile( ...
27-
fileparts(mfilename('fullpath')), '..', 'manualTests', 'dummyData', ...
28-
'README'), ...
26+
templateFolder = fullfile(fileparts(mfilename('fullpath')), '..', 'templates');
27+
28+
copyfile(fullfile(templateFolder, 'README'), ...
2929
sourceDir);
30-
copyfile(fullfile( ...
31-
fileparts(mfilename('fullpath')), '..', 'manualTests', 'dummyData', ...
32-
'CHANGES'), ...
30+
copyfile(fullfile(templateFolder, 'CHANGES'), ...
3331
sourceDir);
34-
copyfile(fullfile( ...
35-
fileparts(mfilename('fullpath')), '..', 'manualTests', 'dummyData', ...
36-
'.bidsignore'), ...
32+
copyfile(fullfile(templateFolder, '.bidsignore'), ...
3733
sourceDir);
3834

3935
copyfile(sourceDir, rawDir);

src/templates/test_templateTest.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ function test_templateTestBasic()
2323
% expectedOuput = X;
2424

2525
% assertEqual(actualOupout, expectedOuput)
26+
% assertTrue( );
27+
% assertFalse( );
2628

2729
%% clean up (delete temporary files that were created)
2830

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

tests/README.md

Lines changed: 28 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,43 @@
66
- Install [MOcov for matlab and octave](https://github.com/MOcov/MOcov) to get
77
the code coverage
88

9-
- Make sure you are in the `tests` directory.
9+
- Make sure the following folders and sub-folders are in the Octave / MATLAB
10+
path:
1011

11-
- Run `moxunit_runtests` or `moxunit_runtests -verbose` to run the tests.
12+
- `src`
13+
- `lib`
14+
- `tests/utils`
15+
16+
- Run `moxunit_runtests tests` or `moxunit_runtests tests -verbose` to run the
17+
tests.
1218

1319
This should tell you which tests pass or fail.
1420

15-
## code coverage
21+
## Adding more tests
22+
23+
You can use the function template to write more tests.
24+
25+
It is in the [`src/templates` folder](../src/templates)
26+
27+
## Manual tests
28+
29+
This is the folder where we keep tests that can not be run in continuous
30+
integration even as simple "smoke tests".
31+
32+
<!-- ## code coverage
33+
34+
A lot of what follows does not really work locally because of needing to add the right
35+
folders to the path to get an accurate coverage.
1636
1737
The following command would give more info and will give you HTML output in a
1838
`coverage_html` folder showing you which lines of code is or is not checked by
1939
your test suite.
2040
2141
```matlab
22-
success = moxunit_runtests(pwd, ... % the path where the tests are
42+
success = moxunit_runtests('tests', ... % the path where the tests are
2343
'-verbose', ...
2444
'-with_coverage', ...
25-
'-cover', fullfile(pwd, '..'), ... % the path of the code whose coverage we want to estimate
45+
'-cover', fullfile(pwd, 'src'), ... % the path of the code whose coverage we want to estimate
2646
'-cover_xml_file','coverage.xml', ...
2747
'-cover_html_dir','coverage_html');
2848
```
@@ -38,9 +58,9 @@ some tests.
3858
3959
```matlab
4060
coverage = mocov( ...
41-
'-expression', 'moxunit_runtests()', ...
61+
'-expression', "moxunit_runtests('test')", ...
4262
'-verbose', ...
43-
'-cover', fullfile(pwd, '..'), ...
63+
'-cover', fullfile(pwd, 'src'), ...
4464
'-cover_exclude', '*jsonread.m', ...
4565
'-cover_exclude', '*json*code.m', ...
4666
'-cover_exclude', '*Contents.m', ...
@@ -54,50 +74,4 @@ coverage = mocov( ...
5474
'-cover_exclude', '*test_*', ...
5575
'-cover_xml_file','coverage.xml', ...
5676
'-cover_html_dir','coverage_html')
57-
```
58-
59-
## Adding more tests
60-
61-
You can use the following function template to write more tests.
62-
63-
```matlab
64-
function test_suite = test_functionToTest()
65-
% This top function is necessary for mox unit to run tests.
66-
% DO NOT CHANGE IT except to adapt the name of the function.
67-
try % assignment of 'localfunctions' is necessary in Matlab >= 2016
68-
test_functions = localfunctions(); %#ok<*NASGU>
69-
catch % no problem; early Matlab versions can use initTestSuite fine
70-
end
71-
initTestSuite;
72-
end
73-
74-
function test_functionToTestBasic()
75-
76-
%% set up
77-
78-
79-
%% data to test against
80-
81-
82-
%% test
83-
% assertTrue( );
84-
% assertFalse( );
85-
% assertEqual( );
86-
87-
end
88-
89-
function test_functionToTestUseCase1()
90-
91-
%% set up
92-
93-
94-
%% data to test against
95-
96-
97-
%% test
98-
% assertTrue( );
99-
% assertFalse( );
100-
% assertEqual( );
101-
102-
end
103-
```
77+
``` -->

manualTests/test_makeRawDataset.m renamed to tests/manualTests/test_makeRawDataset.m

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,21 +213,23 @@ function test_makeRawDataset()
213213
createJson(cfg, extraInfo);
214214

215215
%% add dummy data
216+
templateFolder = fullfile(fileparts(mfilename('fullpath')), '..', '..', 'templates');
217+
216218
subjectDir = fullfile(cfg.dir.output, 'source', 'sub-001', 'ses-001');
217219
funcDir = fullfile(subjectDir, 'func');
218220

219221
boldFilename = 'sub-001_ses-001_task-testtask_run-001_bold.nii.gz';
220222

221223
copyfile( ...
222-
fullfile('dummyData', 'dummyData.nii.gz'), ...
224+
fullfile(templateFolder, 'dummyData.nii.gz'), ...
223225
fullfile(funcDir, boldFilename));
224226

225227
boldFilename = ['sub-001_ses-001_task-rest', ...
226228
'_acq-newTYpe_ce-test_dir-yPos_rec-fastRecon', ...
227229
'_run-001_echo-1_bold.nii.gz'];
228230

229231
copyfile( ...
230-
fullfile('dummyData', 'dummyData.nii.gz'), ...
232+
fullfile(templateFolder, 'dummyData.nii.gz'), ...
231233
fullfile(funcDir, boldFilename));
232234

233235
eegDir = fullfile(subjectDir, 'eeg');
@@ -241,19 +243,19 @@ function test_makeRawDataset()
241243
behFilename = 'sub-001_ses-001_task-easyTargetPractice_run-001_beh.tsv';
242244

243245
copyfile( ...
244-
fullfile('dummyData', 'dummyData.nii.gz'), ...
246+
fullfile(templateFolder, 'dummyData.nii.gz'), ...
245247
fullfile(eegDir, eegFilename));
246248

247249
copyfile( ...
248-
fullfile('dummyData', 'dummyData.nii.gz'), ...
250+
fullfile(templateFolder, 'dummyData.nii.gz'), ...
249251
fullfile(megDir, megFilename));
250252

251253
copyfile( ...
252-
fullfile('dummyData', 'dummyData.nii.gz'), ...
254+
fullfile(templateFolder, 'dummyData.nii.gz'), ...
253255
fullfile(ieegDir, ieegFilename));
254256

255257
copyfile( ...
256-
fullfile('dummyData', 'dummyData.nii.gz'), ...
258+
fullfile(templateFolder, 'dummyData.nii.gz'), ...
257259
fullfile(behDir, behFilename));
258260

259261
%% actually do the conversion of the source data thus created

tests/test_readAndFilterLogfile.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ function test_readAndFilterLogfileFromFile()
7676

7777
%% set up
7878

79-
inputFile = fullfile(fileparts(mfilename('fullpath')), 'dummyData', ...
79+
inputFile = fullfile(fileparts(mfilename('fullpath')), 'testData', ...
8080
'sub-blind01_ses-01_task-vislocalizer_events.tsv');
8181

8282
% filter file

0 commit comments

Comments
 (0)