Skip to content

Commit

Permalink
Merge pull request #3059 from mgxd/tst/xfail
Browse files Browse the repository at this point in the history
TEST: Skip dcm2niix test if data fails to download
  • Loading branch information
effigies authored Oct 2, 2019
2 parents 0fa28d5 + f31c2d0 commit 6e80cea
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions nipype/interfaces/tests/test_extra_dcm2nii.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())

0 comments on commit 6e80cea

Please sign in to comment.