Skip to content

Commit 5c20c6b

Browse files
authored
conftest.py testing (#83)
* [TEST] init a test for conftest.py * [BUG] inside unit_tests workflow * [TEST] testing the conftest module * [CI] 48h workflow timeouts for pipeline tests * [TEST] completing the test_conftest
1 parent 5d9fe37 commit 5c20c6b

File tree

6 files changed

+334
-11
lines changed

6 files changed

+334
-11
lines changed

.github/workflows/pipeline_tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ jobs:
5151
pytest:
5252
needs: identify-tests
5353
runs-on: self-hosted
54+
timeout-minutes: 2880 # 48h
5455
steps:
5556
- name: Checkout PR branch
5657
uses: actions/checkout@v3

.github/workflows/test_changes.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ jobs:
4242
pytest:
4343
needs: identify-tests
4444
runs-on: self-hosted
45+
timeout-minutes: 2880 # 48h
4546
steps:
4647
- name: Checkout PR branch
4748
uses: actions/checkout@v3

narps_open/data/results/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def get_uid(self):
5656

5757
def get_file_urls(self):
5858
""" Return a dict containing the download url for each file of the collection.
59-
* dict key is the file base name (with no extension)
59+
* dict key is the file base name (with extension)
6060
* dict value is the download url for the file on Neurovault
6161
"""
6262

@@ -69,7 +69,7 @@ def get_file_urls(self):
6969
file_urls = {}
7070
for result in json['results']:
7171
# Get data for a file in the collection
72-
file_urls[result['name']] = result['file']
72+
file_urls[result['name']+'.nii.gz'] = result['file']
7373

7474
return file_urls
7575

@@ -84,7 +84,7 @@ def download(self):
8484
for file_name, file_url in self.files.items():
8585
urlretrieve(
8686
file_url,
87-
join(self.directory, file_name+'.nii.gz'),
87+
join(self.directory, file_name),
8888
show_download_progress
8989
)
9090

tests/conftest.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,20 @@ def test_pipeline_execution(
5858
# Get missing subjects
5959
missing_subjects = set()
6060
for file in runner.get_missing_first_level_outputs():
61-
missing_subjects.add(get_subject_id(file))
61+
subject_id = get_subject_id(file)
62+
if subject_id is not None:
63+
missing_subjects.add(subject_id)
6264

6365
# Leave if no missing subjects
6466
if not missing_subjects:
6567
break
6668

6769
# Start pipeline
6870
runner.subjects = missing_subjects
69-
runner.start(True, False)
71+
try: # This avoids errors in the workflow to make the test fail
72+
runner.start(True, False)
73+
except(RuntimeError) as err:
74+
print('RuntimeError: ', err)
7075

7176
# Check missing files for the last time
7277
missing_files = runner.get_missing_first_level_outputs()
@@ -80,15 +85,15 @@ def test_pipeline_execution(
8085

8186
# Indices and keys to the unthresholded maps
8287
indices = list(range(1, 18, 2))
83-
keys = [f'hypo{i}_unthresh.nii.gz' for i in range(1, 10)]
8488

8589
# Retrieve the paths to the reproduced files
8690
reproduced_files = runner.pipeline.get_hypotheses_outputs()
8791
reproduced_files = [reproduced_files[i] for i in indices]
8892

8993
# Retrieve the paths to the results files
9094
collection = ResultsCollection(team_id)
91-
results_files = [join(collection.directory, collection.files[k]) for k in keys]
95+
results_files = [join(collection.directory, f) for f in collection.files.keys()]
96+
results_files = [results_files[i] for i in indices]
9297

9398
# Compute the correlation coefficients
9499
return [
@@ -142,10 +147,10 @@ def test_pipeline_evaluation(team_id: str):
142147

143148
for subjects in [20, 40, 60, 80, 108]:
144149
# Execute pipeline
145-
results = helpers.test_pipeline_execution(team_id, subjects)
150+
results = test_pipeline_execution(team_id, subjects)
146151

147152
# Compute correlation with results
148-
passed = helpers.test_correlation_results(results, subjects)
153+
passed = test_correlation_results(results, subjects)
149154

150155
# Write values in a file
151156
with open(file_name, 'a', encoding = 'utf-8') as file:

tests/data/test_results.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ def test_create():
4848
assert collection.uid == '4881'
4949
assert 'results/orig/4881_2T6S' in collection.directory
5050
test_str = 'http://neurovault.org/media/images/4881/hypo1_thresholded_revised.nii.gz'
51-
assert collection.files['hypo1_thresh'] == test_str
51+
assert collection.files['hypo1_thresh.nii.gz'] == test_str
5252

5353
collection = ResultsCollection('43FJ')
5454
assert collection.team_id == '43FJ'
5555
assert collection.uid == '4824'
5656
assert 'results/orig/4824_43FJ' in collection.directory
5757
test_str = 'http://neurovault.org/media/images/4824/'
5858
test_str += 'Zstat_Thresholded_Negative_Effect_of_Loss_Equal_Indifference.nii.gz'
59-
assert collection.files['hypo5_thresh'] == test_str
59+
assert collection.files['hypo5_thresh.nii.gz'] == test_str
6060

6161
@staticmethod
6262
@mark.unit_test

0 commit comments

Comments
 (0)