Skip to content

Commit 928019d

Browse files
committed
Custom configuration allowed for testing
1 parent 211f93e commit 928019d

File tree

4 files changed

+54
-10
lines changed

4 files changed

+54
-10
lines changed

narps_open/data/task.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@
1212
class TaskInformation(dict, metaclass=SingletonMeta):
1313
""" This class allows to access information about the task performed in NARPS """
1414

15-
task_information_file = join(Configuration()['directories']['dataset'], 'task-MGT_bold.json')
16-
17-
def __init__(self):
15+
def __init__(self, task_file=''):
1816
super().__init__()
1917

2018
# Load information from the task-MGT_bold.json file
21-
with open(self.task_information_file, 'rb') as file:
19+
if task_file:
20+
task_information_file = task_file # For testing purpose only
21+
else:
22+
task_information_file = join(
23+
Configuration()['directories']['dataset'], 'task-MGT_bold.json')
24+
with open(task_information_file, 'rb') as file:
2225
self.update(load(file))
2326

2427
# Compute derived information
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[general]
2+
title = "Testing configuration for the NARPS open pipelines project, to be used inside the nipype/nipype:py38 docker container"
3+
config_type = "custom"
4+
5+
[directories]
6+
dataset = "/work/data/original/ds001734/"
7+
reproduced_results = "/work/run/reproduced/"
8+
narps_results = "/work/data/results/"
9+
test_data = "/work/tests/test_data/"
10+
test_runs = "/work/run/"
11+
12+
[runner]
13+
nb_procs = 8 # Maximum number of threads executed by the runner
14+
nb_trials = 3 # Maximum number of executions to have the pipeline executed completely
15+
16+
[pipelines]
17+
remove_unused_data = true # set to true to activate remove nodes of pipelines
18+
19+
[results]
20+
neurovault_naming = true # true if results files are saved using the neurovault naming, false if they use naming of narps
21+
22+
[testing]
23+
24+
[testing.pipelines]
25+
nb_subjects_per_group = 4 # Compute first level analyses by subgroups of N subjects, to avoid lacking of disk and memory
26+
correlation_thresholds = [0.30, 0.70, 0.78, 0.85, 0.93] # Correlation between reproduced hypotheses files and results, respectively for [20, 40, 60, 80, 108] subjects.

tests/conftest.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,24 @@
2424
from narps_open.data.results import ResultsCollection
2525
from narps_open.data.participants import get_participants_subset
2626

27-
# Init configuration, to ensure it is in testing mode
28-
Configuration(config_type='testing')
27+
def pytest_addoption(parser):
28+
""" Add a configuration option for narps_open to the pytest command line """
29+
parser.addoption('--narps_open_config',
30+
action='store', help='NARPS Open Pipelines configuration file')
31+
32+
@fixture(scope='session', autouse=True)
33+
def load_configuration(request):
34+
""" Automatically load narps_open configuration from the corresponding
35+
pytest command line argument.
36+
"""
37+
config_file = request.config.getoption('--narps_open_config')
38+
39+
if config_file:
40+
# Init configuration with custom file
41+
Configuration(config_type='custom').config_file = config_file
42+
else:
43+
# Ensure it is in testing mode
44+
Configuration(config_type='testing')
2945

3046
@fixture
3147
def temporary_data_dir():

tests/data/test_task.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@
1818
from narps_open.data import task
1919

2020
@fixture(scope='function', autouse=True)
21-
def mock_task_data(mocker):
22-
""" Patch the json.load method to mock task data """
23-
mocker.patch.object(
24-
task.TaskInformation, 'task_information_file',
21+
def load_test_task_data():
22+
""" Init the TaskInformation class with task data for testing """
23+
task.TaskInformation(
2524
join(Configuration()['directories']['test_data'], 'data', 'task', 'task-info.json')
2625
)
2726

0 commit comments

Comments
 (0)