|
14 | 14 | DICOM_DIR = 'http://datasets-tests.datalad.org/dicoms/dcm2niix-tests'
|
15 | 15 |
|
16 | 16 |
|
17 |
| -def fetch_data(datadir, dicoms): |
18 |
| - """Fetches some test DICOMs using datalad""" |
19 |
| - api.install(path=datadir, source=DICOM_DIR) |
20 |
| - data = os.path.join(datadir, dicoms) |
21 |
| - api.get(path=data) |
22 |
| - return data |
| 17 | +@pytest.fixture |
| 18 | +def fetch_data(): |
| 19 | + def _fetch_data(datadir, dicoms): |
| 20 | + try: |
| 21 | + """Fetches some test DICOMs using datalad""" |
| 22 | + api.install(path=datadir, source=DICOM_DIR) |
| 23 | + data = os.path.join(datadir, dicoms) |
| 24 | + api.get(path=data) |
| 25 | + except IncompleteResultsError as exc: |
| 26 | + pytest.skip("Failed to fetch test data: %s" % str(exc)) |
| 27 | + return data |
| 28 | + return _fetch_data |
23 | 29 |
|
24 | 30 | @pytest.mark.skipif(no_datalad, reason="Datalad required")
|
25 | 31 | @pytest.mark.skipif(no_dcm2niix, reason="Dcm2niix required")
|
26 |
| -def test_dcm2niix_dwi(tmpdir): |
| 32 | +def test_dcm2niix_dti(fetch_data, tmpdir): |
27 | 33 | tmpdir.chdir()
|
28 | 34 | datadir = tmpdir.mkdir('data').strpath
|
29 |
| - try: |
30 |
| - dicoms = fetch_data(datadir, 'Siemens_Sag_DTI_20160825_145811') |
31 |
| - except IncompleteResultsError as exc: |
32 |
| - pytest.skip("Failed to fetch test data: %s" % str(exc)) |
| 35 | + dicoms = fetch_data(datadir, 'Siemens_Sag_DTI_20160825_145811') |
33 | 36 |
|
34 |
| - def assert_dwi(eg): |
| 37 | + def assert_dti(res): |
35 | 38 | "Some assertions we will make"
|
36 |
| - assert eg.outputs.converted_files |
37 |
| - assert eg.outputs.bvals |
38 |
| - assert eg.outputs.bvecs |
39 |
| - outputs = [y for x,y in eg.outputs.get().items()] |
40 |
| - if eg.inputs.get('bids_format'): |
| 39 | + assert res.outputs.converted_files |
| 40 | + assert res.outputs.bvals |
| 41 | + assert res.outputs.bvecs |
| 42 | + outputs = [y for x,y in res.outputs.get().items()] |
| 43 | + if res.inputs.get('bids_format'): |
41 | 44 | # ensure all outputs are of equal lengths
|
42 | 45 | assert len(set(map(len, outputs))) == 1
|
43 | 46 | else:
|
44 |
| - assert not eg.outputs.bids |
| 47 | + assert not res.outputs.bids |
45 | 48 |
|
46 | 49 | dcm = Dcm2niix()
|
47 | 50 | dcm.inputs.source_dir = dicoms
|
48 | 51 | dcm.inputs.out_filename = '%u%z'
|
49 |
| - assert_dwi(dcm.run()) |
| 52 | + assert_dti(dcm.run()) |
50 | 53 |
|
51 | 54 | # now run specifying output directory and removing BIDS option
|
52 | 55 | outdir = tmpdir.mkdir('conversion').strpath
|
53 | 56 | dcm.inputs.output_dir = outdir
|
54 | 57 | dcm.inputs.bids_format = False
|
55 |
| - assert_dwi(dcm.run()) |
| 58 | + assert_dti(dcm.run()) |
0 commit comments