From 389d6e432c6e9c7cb7f4b300986a975742c844f6 Mon Sep 17 00:00:00 2001 From: John K Date: Tue, 22 Sep 2020 09:54:43 -0700 Subject: [PATCH 1/3] catch no subject error early --- AFQ/api.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/AFQ/api.py b/AFQ/api.py index 1fe183e41..22e2b5338 100644 --- a/AFQ/api.py +++ b/AFQ/api.py @@ -388,6 +388,9 @@ def __init__(self, json.dump(pipeline_description, outfile) self.subjects = bids_layout.get(return_type='id', target='subject') + if not len(self.subjects): + raise ValueError("`bids_path` contains no subjects") + sessions = bids_layout.get(return_type='id', target='session') if len(sessions): self.sessions = sessions From 56b6528a3311036fa33e90bc545ce479368448d3 Mon Sep 17 00:00:00 2001 From: John K Date: Tue, 22 Sep 2020 10:14:12 -0700 Subject: [PATCH 2/3] add better message; add test --- AFQ/api.py | 5 ++++- AFQ/tests/test_api.py | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/AFQ/api.py b/AFQ/api.py index 22e2b5338..76a22265a 100644 --- a/AFQ/api.py +++ b/AFQ/api.py @@ -389,7 +389,10 @@ def __init__(self, self.subjects = bids_layout.get(return_type='id', target='subject') if not len(self.subjects): - raise ValueError("`bids_path` contains no subjects") + raise ValueError( + "`bids_path` contains no subjects in derivatives folders." + + " This could be caused by derivatives folders not following" + + " the BIDS format.") sessions = bids_layout.get(return_type='id', target='session') if len(sessions): diff --git a/AFQ/tests/test_api.py b/AFQ/tests/test_api.py index 953821231..03294a095 100644 --- a/AFQ/tests/test_api.py +++ b/AFQ/tests/test_api.py @@ -180,6 +180,23 @@ def test_AFQ_custom_tract(): @pytest.mark.nightly2 +def test_AFQ_no_derivs(): + """ + Test the initialization of the AFQ object + """ + bids_path = create_dummy_bids_path(1, 1) + os.remove(op.join( + bids_path, "derivatives", "dmriprep", "dataset_description.json")) + with pytest.raises( + ValueError, + match = "`bids_path` contains no subjects in derivatives folders." + + " This could be caused by derivatives folders not following" + + " the BIDS format."): + my_afq = api.AFQ(bids_path, + dmriprep="synthetic") + + +@pytest.mark.nightly3 def test_AFQ_init(): """ Test the initialization of the AFQ object From 40964b909770e0dec6cffac6df49465779e4f642 Mon Sep 17 00:00:00 2001 From: John K Date: Tue, 22 Sep 2020 10:19:04 -0700 Subject: [PATCH 3/3] pep8 --- AFQ/tests/test_api.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/AFQ/tests/test_api.py b/AFQ/tests/test_api.py index 03294a095..b5a54d18d 100644 --- a/AFQ/tests/test_api.py +++ b/AFQ/tests/test_api.py @@ -189,9 +189,9 @@ def test_AFQ_no_derivs(): bids_path, "derivatives", "dmriprep", "dataset_description.json")) with pytest.raises( ValueError, - match = "`bids_path` contains no subjects in derivatives folders." - + " This could be caused by derivatives folders not following" - + " the BIDS format."): + match="`bids_path` contains no subjects in derivatives folders." + + " This could be caused by derivatives folders not" + + " following the BIDS format."): my_afq = api.AFQ(bids_path, dmriprep="synthetic")