From f31c2d08679153107e68b9a6768b1dcaf101e20a Mon Sep 17 00:00:00 2001 From: mathiasg Date: Tue, 1 Oct 2019 11:31:31 -0400 Subject: [PATCH] tst: use pytest fixture --- nipype/interfaces/tests/test_extra_dcm2nii.py | 43 ++++++++++--------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/nipype/interfaces/tests/test_extra_dcm2nii.py b/nipype/interfaces/tests/test_extra_dcm2nii.py index 083b8fcca1..969256ae76 100644 --- a/nipype/interfaces/tests/test_extra_dcm2nii.py +++ b/nipype/interfaces/tests/test_extra_dcm2nii.py @@ -14,42 +14,45 @@ DICOM_DIR = 'http://datasets-tests.datalad.org/dicoms/dcm2niix-tests' -def fetch_data(datadir, dicoms): - """Fetches some test DICOMs using datalad""" - api.install(path=datadir, source=DICOM_DIR) - data = os.path.join(datadir, dicoms) - api.get(path=data) - return data +@pytest.fixture +def fetch_data(): + def _fetch_data(datadir, dicoms): + try: + """Fetches some test DICOMs using datalad""" + api.install(path=datadir, source=DICOM_DIR) + data = os.path.join(datadir, dicoms) + api.get(path=data) + except IncompleteResultsError as exc: + pytest.skip("Failed to fetch test data: %s" % str(exc)) + return data + return _fetch_data @pytest.mark.skipif(no_datalad, reason="Datalad required") @pytest.mark.skipif(no_dcm2niix, reason="Dcm2niix required") -def test_dcm2niix_dwi(tmpdir): +def test_dcm2niix_dti(fetch_data, tmpdir): tmpdir.chdir() datadir = tmpdir.mkdir('data').strpath - try: - dicoms = fetch_data(datadir, 'Siemens_Sag_DTI_20160825_145811') - except IncompleteResultsError as exc: - pytest.skip("Failed to fetch test data: %s" % str(exc)) + dicoms = fetch_data(datadir, 'Siemens_Sag_DTI_20160825_145811') - def assert_dwi(eg): + def assert_dti(res): "Some assertions we will make" - assert eg.outputs.converted_files - assert eg.outputs.bvals - assert eg.outputs.bvecs - outputs = [y for x,y in eg.outputs.get().items()] - if eg.inputs.get('bids_format'): + assert res.outputs.converted_files + assert res.outputs.bvals + assert res.outputs.bvecs + outputs = [y for x,y in res.outputs.get().items()] + if res.inputs.get('bids_format'): # ensure all outputs are of equal lengths assert len(set(map(len, outputs))) == 1 else: - assert not eg.outputs.bids + assert not res.outputs.bids dcm = Dcm2niix() dcm.inputs.source_dir = dicoms dcm.inputs.out_filename = '%u%z' - assert_dwi(dcm.run()) + assert_dti(dcm.run()) # now run specifying output directory and removing BIDS option outdir = tmpdir.mkdir('conversion').strpath dcm.inputs.output_dir = outdir dcm.inputs.bids_format = False - assert_dwi(dcm.run()) + assert_dti(dcm.run())