Skip to content

Commit d9c9061

Browse files
committed
tst: move testing utilities
1 parent 81d744c commit d9c9061

File tree

2 files changed

+31
-30
lines changed

2 files changed

+31
-30
lines changed

tests/test_regression.py

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
"""Testing conversion with conversion saved on datalad"""
2-
from tempfile import mkdtemp
3-
import os
42
import os.path as op
53
import json
64
from glob import glob
@@ -13,37 +11,11 @@
1311
except ImportError:
1412
have_datalad = False
1513

16-
from heudiconv.cli.run import main as runner
1714
import heudiconv
15+
from heudiconv.cli.run import main as runner
16+
from .utils import fetch_data, gen_heudiconv_args
1817

1918

20-
def gen_heudiconv_args(datadir, outdir, subject, heuristic_file, xargs=None):
21-
heuristic = op.realpath(op.join(
22-
op.dirname(heudiconv.__file__),
23-
'..',
24-
'heuristics',
25-
heuristic_file))
26-
27-
args = ["-d", op.join(datadir, 'sourcedata/{subject}/*/*/*.tgz'),
28-
"-c", "dcm2niix",
29-
"-o", outdir,
30-
"-s", subject,
31-
"-f", heuristic,
32-
"--bids",
33-
]
34-
if xargs:
35-
args += xargs
36-
37-
return args
38-
39-
def fetch_data(tmpdir, subject):
40-
"""Fetches some test dicoms"""
41-
targetdir = os.path.join(tmpdir, 'QA')
42-
api.install(path=targetdir,
43-
source='///dbic/QA')
44-
api.get('{}/sourcedata/{}'.format(targetdir, subject))
45-
return targetdir
46-
4719
@pytest.mark.parametrize('subject', ['sub-sid000143'])
4820
@pytest.mark.parametrize('heuristic', ['dbic_bids.py'])
4921
@pytest.mark.skipif(not have_datalad, reason="no datalad")

tests/utils.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,35 @@
11
import hashlib
2+
import os.path as op
23

34

45
def md5sum(filename):
56
with open(filename, 'rb') as f:
67
return hashlib.md5(f.read()).hexdigest()
8+
9+
def gen_heudiconv_args(datadir, outdir, subject, heuristic_file, xargs=None):
10+
heuristic = op.realpath(op.join(
11+
op.dirname(heudiconv.__file__),
12+
'..',
13+
'heuristics',
14+
heuristic_file))
15+
16+
args = ["-d", op.join(datadir, 'sourcedata/{subject}/*/*/*.tgz'),
17+
"-c", "dcm2niix",
18+
"-o", outdir,
19+
"-s", subject,
20+
"-f", heuristic,
21+
"--bids",
22+
]
23+
if xargs:
24+
args += xargs
25+
26+
return args
27+
28+
29+
def fetch_data(tmpdir, subject):
30+
"""Fetches some test dicoms using datalad"""
31+
targetdir = os.path.join(tmpdir, 'QA')
32+
api.install(path=targetdir,
33+
source='///dbic/QA')
34+
api.get('{}/sourcedata/{}'.format(targetdir, subject))
35+
return targetdir

0 commit comments

Comments
 (0)