Skip to content

Commit

Permalink
[TEST] test update [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
bclenet committed Jan 9, 2025
1 parent a7deb46 commit 042f763
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 18 deletions.
17 changes: 8 additions & 9 deletions narps_open/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,31 +140,30 @@ def start(self, level: PipelineRunnerLevel = PipelineRunnerLevel.ALL) -> None:
f'{self.team_id}, with {len(self.subjects)} subjects: {self.subjects}')
print(f'\tThe following levels will be run: {level}')

# Generate workflow list & check for missing outputs
# Generate workflow list & level list
workflows = []
output_checks = []
levels = []
if bool(level & PipelineRunnerLevel.PREPROCESSING):
workflows += self.get_workflows(self._pipeline.get_preprocessing())
output_checks += self.get_missing_outputs(PipelineRunnerLevel.PREPROCESSING)
levels.append(PipelineRunnerLevel.PREPROCESSING)
if bool(level & PipelineRunnerLevel.RUN):
workflows += self.get_workflows(self._pipeline.get_run_level_analysis())
output_checks += self.get_missing_outputs(PipelineRunnerLevel.RUN)
levels.append(PipelineRunnerLevel.RUN)
if bool(level & PipelineRunnerLevel.SUBJECT):
workflows += self.get_workflows(self._pipeline.get_subject_level_analysis())
output_checks += self.get_missing_outputs(PipelineRunnerLevel.SUBJECT)
levels.append(PipelineRunnerLevel.SUBJECT)
if bool(level & PipelineRunnerLevel.GROUP):
workflows += self.get_workflows(self._pipeline.get_group_level_analysis())
output_checks += self.get_missing_outputs(PipelineRunnerLevel.GROUP)
levels.append(PipelineRunnerLevel.GROUP)

# Launch workflows
for workflow, output_check in zip(workflows, output_checks):
for workflow, current_level in zip(workflows, levels):
nb_procs = Configuration()['runner']['nb_procs']
if nb_procs > 1:
workflow.run('MultiProc', plugin_args = {'n_procs': nb_procs})
output_check()
else:
workflow.run()
output_check()
self.get_missing_outputs(current_level)

def get_missing_outputs(self, level: PipelineRunnerLevel = PipelineRunnerLevel.ALL):
"""
Expand Down
51 changes: 42 additions & 9 deletions tests/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,20 +271,13 @@ def test_start_nok():
with raises(AttributeError):
runner.start()

# 2b - test starting a pipeline with wrong workflow type
# 3 - test starting a pipeline with wrong workflow type
runner = PipelineRunner('2T6S')
runner._pipeline = MockupWrongPipeline2() # hack the runner by setting a test Pipeline

with raises(AttributeError):
runner.start()

# 2b - test starting a pipeline with wrong options (fist_level_only + group_level_only)
runner = PipelineRunner('2T6S')
runner._pipeline = MockupPipeline() # hack the runner by setting a test Pipeline

with raises(AttributeError):
runner.start(True, True)

@staticmethod
@mark.unit_test
def test_start_ok():
Expand Down Expand Up @@ -358,6 +351,37 @@ def test_start_ok():
assert file.readline() == 'MockupPipeline : '+workflow+' node_1\n'
assert file.readline() == 'MockupPipeline : '+workflow+' node_2\n'

@staticmethod
@mark.unit_test
def test_get_workflows():
""" Test the get_workflows method """
runner = PipelineRunner('2T6S')
workflow_1 = Workflow(name = 'workflow_1')
workflow_2 = Workflow(name = 'workflow_2')

# Error when passing something that is not a nipype.Workflow
with raises(AttributeError):
runner.get_workflows(183)

# Error when passing something that is not a list of nipype.Workflow
with raises(AttributeError):
runner.get_workflows([workflow_1, 183])

# Check output when passing a nipype.Workflow
test = runner.get_workflows(workflow_1)
assert isinstance(test, list)
assert test == [workflow_1]

# Check output when passing a list of nipype.Workflow
test = runner.get_workflows([workflow_1, workflow_2])
assert isinstance(test, list)
assert test == [workflow_1, workflow_2]

# Check output when passing None
test = runner.get_workflows(None)
assert isinstance(test, list)
assert test == []

@staticmethod
@mark.unit_test
def test_get_missing_outputs():
Expand Down Expand Up @@ -393,10 +417,19 @@ def test_get_missing_outputs():
Path(runner.pipeline.get_subject_level_outputs()[1]).touch()

# 1e - Check again for missing files
missing_files = runner.get_missing_first_level_outputs()
missing_files = runner.get_missing_outputs(PipelineRunnerLevel.FIRST)
assert len(missing_files) == 1
assert 'run_output.md' in missing_files[0]

missing_files = runner.get_missing_outputs(PipelineRunnerLevel.RUN)
assert len(missing_files) == 1
assert 'run_output.md' in missing_files[0]

missing_files = runner.get_missing_outputs(PipelineRunnerLevel.GROUP)
assert len(missing_files) == 2
assert 'group_1_output_a.md' in missing_files[0]
assert 'group_1_output_b.md' in missing_files[1]

# 2a - Instantiate a pipeline
runner = PipelineRunner('2T6S')
runner._pipeline = MockupPipeline() # hack the runner by setting a test Pipeline
Expand Down

0 comments on commit 042f763

Please sign in to comment.