|
43 | 43 | KeyInfoForForce,
|
44 | 44 | BIDSFile,
|
45 | 45 | )
|
| 46 | +from heudiconv.cli.run import main as runner |
46 | 47 |
|
47 | 48 | from .utils import (
|
| 49 | + fetch_data, |
| 50 | + gen_heudiconv_args, |
48 | 51 | TESTS_DATA_PATH,
|
49 | 52 | )
|
50 | 53 |
|
51 | 54 | import pytest
|
52 | 55 |
|
| 56 | +have_datalad = True |
| 57 | +try: |
| 58 | + from datalad.support.exceptions import IncompleteResultsError |
| 59 | +except ImportError: |
| 60 | + have_datalad = False |
| 61 | + |
| 62 | + |
53 | 63 | def gen_rand_label(label_size, label_seed, seed_stdout=True):
|
54 | 64 | seed(label_seed)
|
55 | 65 | rand_char = ''.join(choice(string.ascii_letters) for _ in range(label_size-1))
|
@@ -1116,3 +1126,32 @@ def test_BIDSFile():
|
1116 | 1126 | # -for an existing entity, you can overwrite it with "set":
|
1117 | 1127 | my_bids_file.set('echo', '2')
|
1118 | 1128 | assert my_bids_file['echo'] == '2'
|
| 1129 | + |
| 1130 | + |
| 1131 | +@pytest.mark.skipif(not have_datalad, reason="no datalad") |
| 1132 | +def test_ME_mag_phase_conversion(tmpdir, subID='MEGRE', heuristic='bids_ME.py'): |
| 1133 | + """ Unit test for the case of multi-echo GRE data with |
| 1134 | + magnitude and phase. |
| 1135 | + The different echoes should be labeled automatically. |
| 1136 | + """ |
| 1137 | + tmpdir.chdir() |
| 1138 | + tmppath = tmpdir.strpath |
| 1139 | + try: |
| 1140 | + datadir = fetch_data(tmppath, f"dicoms/velasco/{subID}") |
| 1141 | + except IncompleteResultsError as exc: |
| 1142 | + pytest.skip("Failed to fetch test data: %s" % str(exc)) |
| 1143 | + |
| 1144 | + outdir = tmpdir.mkdir('out').strpath |
| 1145 | + args = gen_heudiconv_args(datadir, outdir, subID, heuristic) |
| 1146 | + runner(args) # run conversion |
| 1147 | + |
| 1148 | + # Check that the expected files have been extracted. |
| 1149 | + # This also checks that the "echo" entity comes before "part": |
| 1150 | + for part in ['mag', 'phase']: |
| 1151 | + for e in range(1,4): |
| 1152 | + for ext in ['nii.gz', 'json']: |
| 1153 | + assert op.exists( |
| 1154 | + op.join(outdir, 'sub-%s', 'anat', 'sub-%s_echo-%s_part-%s_MEGRE.%s') |
| 1155 | + % (subID, subID, e, part, ext) |
| 1156 | + ) |
| 1157 | + |
0 commit comments