From aaa9b8dde7f606d1a3d89d9ee25773a897fd3968 Mon Sep 17 00:00:00 2001 From: Arthur Mensch Date: Fri, 27 May 2016 14:17:21 +0200 Subject: [PATCH 1/3] cleaned test function --- pypreprocess/subject_data.py | 2 +- pypreprocess/tests/test_subject_data.py | 28 +------------------------ 2 files changed, 2 insertions(+), 28 deletions(-) diff --git a/pypreprocess/subject_data.py b/pypreprocess/subject_data.py index e81ebdb6..62e073d4 100644 --- a/pypreprocess/subject_data.py +++ b/pypreprocess/subject_data.py @@ -217,7 +217,7 @@ def _sanitize_output_dirs(self): # make tmp output dir if self.scratch is None: self.scratch = self.output_dir - if not self.scratch is None: + else: self.tmp_output_dir = os.path.join(self.scratch, "tmp") self.tmp_output_dir = self._sanitize_output_dir(self.tmp_output_dir) diff --git a/pypreprocess/tests/test_subject_data.py b/pypreprocess/tests/test_subject_data.py index d63ae939..9515d997 100644 --- a/pypreprocess/tests/test_subject_data.py +++ b/pypreprocess/tests/test_subject_data.py @@ -71,16 +71,7 @@ def test_not_unique_func_filenames_exception_thrown(): except RuntimeError: pass - sd = _make_sd( - func_filenames=[["/tmp/titi/func/1.img", "/tmp/titi/func/2.img"], - ["/tmp/titi/func/1.img", "/tmp/titi/func/3.img"]], - output_dir="/tmp") - try: - sd.sanitize() - raise RuntimeError("Check failed!") - except RuntimeError: - pass - + # abspaths of func images should be different with a session sd = _make_sd( func_filenames=["/tmp/titi/func/1.img", ["/tmp/titi/func/1.img", "/tmp/titi/func/3.img"]], @@ -91,23 +82,6 @@ def test_not_unique_func_filenames_exception_thrown(): except RuntimeError: pass - sd = _make_sd( - func_filenames=[["/tmp/titi/func/1.img", "/tmp/titi/func/2.img"], - ["/tmp/titi/func/3.img", "/tmp/titi/func/4.img"]], - output_dir="/tmp") - sd.sanitize() - - # abspaths of func images should be different with a session - sd = _make_sd( - func_filenames=[["/tmp/titi/func/1.img", "/tmp/titi/func/1.img"], - ["/tmp/titi/func/3.img", "/tmp/titi/func/4.img"]], - output_dir="/tmp") - try: - sd.sanitize() - raise RuntimeError("Check failed!") - except RuntimeError: - pass - def test_issue_40(): sd = _make_sd( From 4ce2e90d98be8043a58605153c8d978a3a01f849 Mon Sep 17 00:00:00 2001 From: Arthur Mensch Date: Fri, 27 May 2016 14:36:16 +0200 Subject: [PATCH 2/3] Better error message --- pypreprocess/nipype_preproc_spm_utils.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/pypreprocess/nipype_preproc_spm_utils.py b/pypreprocess/nipype_preproc_spm_utils.py index f8a1e71d..9d69c89a 100644 --- a/pypreprocess/nipype_preproc_spm_utils.py +++ b/pypreprocess/nipype_preproc_spm_utils.py @@ -1519,12 +1519,17 @@ def do_subjects_preproc(subject_factory, session_ids=None, **preproc_params): # load .ini ? preproc_details = None if isinstance(subject_factory, basestring): - with open(subject_factory, "r") as fd: - preproc_details = fd.read() - fd.close() + try: + with open(subject_factory, "r") as fd: + preproc_details = fd.read() + fd.close() + except IOError: + raise IOError('Could not load %s, please make sure to run your ' + 'script within the same folder' + ' as the .ini file' % subject_factory) subject_factory, _preproc_params = _generate_preproc_pipeline( - subject_factory, dataset_dir=preproc_params.get( - "dataset_dir", None)) + subject_factory, dataset_dir=preproc_params.get( + "dataset_dir", None)) _preproc_params.update(preproc_params) preproc_params = _preproc_params From c8677ec06788e69dbcc5ec92c22d537cf0ce6873 Mon Sep 17 00:00:00 2001 From: Arthur Mensch Date: Fri, 27 May 2016 14:36:39 +0200 Subject: [PATCH 3/3] Revert "cleaned test function" This reverts commit aaa9b8dde7f606d1a3d89d9ee25773a897fd3968. --- pypreprocess/subject_data.py | 2 +- pypreprocess/tests/test_subject_data.py | 28 ++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/pypreprocess/subject_data.py b/pypreprocess/subject_data.py index 62e073d4..e81ebdb6 100644 --- a/pypreprocess/subject_data.py +++ b/pypreprocess/subject_data.py @@ -217,7 +217,7 @@ def _sanitize_output_dirs(self): # make tmp output dir if self.scratch is None: self.scratch = self.output_dir - else: + if not self.scratch is None: self.tmp_output_dir = os.path.join(self.scratch, "tmp") self.tmp_output_dir = self._sanitize_output_dir(self.tmp_output_dir) diff --git a/pypreprocess/tests/test_subject_data.py b/pypreprocess/tests/test_subject_data.py index 9515d997..d63ae939 100644 --- a/pypreprocess/tests/test_subject_data.py +++ b/pypreprocess/tests/test_subject_data.py @@ -71,7 +71,16 @@ def test_not_unique_func_filenames_exception_thrown(): except RuntimeError: pass - # abspaths of func images should be different with a session + sd = _make_sd( + func_filenames=[["/tmp/titi/func/1.img", "/tmp/titi/func/2.img"], + ["/tmp/titi/func/1.img", "/tmp/titi/func/3.img"]], + output_dir="/tmp") + try: + sd.sanitize() + raise RuntimeError("Check failed!") + except RuntimeError: + pass + sd = _make_sd( func_filenames=["/tmp/titi/func/1.img", ["/tmp/titi/func/1.img", "/tmp/titi/func/3.img"]], @@ -82,6 +91,23 @@ def test_not_unique_func_filenames_exception_thrown(): except RuntimeError: pass + sd = _make_sd( + func_filenames=[["/tmp/titi/func/1.img", "/tmp/titi/func/2.img"], + ["/tmp/titi/func/3.img", "/tmp/titi/func/4.img"]], + output_dir="/tmp") + sd.sanitize() + + # abspaths of func images should be different with a session + sd = _make_sd( + func_filenames=[["/tmp/titi/func/1.img", "/tmp/titi/func/1.img"], + ["/tmp/titi/func/3.img", "/tmp/titi/func/4.img"]], + output_dir="/tmp") + try: + sd.sanitize() + raise RuntimeError("Check failed!") + except RuntimeError: + pass + def test_issue_40(): sd = _make_sd(