Skip to content

Commit b8f3a08

Browse files
committed
ENH(TST): tests for loading heuristics
1 parent 7a2160d commit b8f3a08

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

heudiconv/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ def load_heuristic(heuristic):
303303
mod = import_module('heudiconv.heuristics.%s' % heuristic)
304304
mod.filename = mod.__file__.rstrip('co') # remove c or o from pyc/pyo
305305
except Exception as exc:
306-
raise RuntimeError(
306+
raise ImportError(
307307
"Failed to import heuristic %s: %s"
308308
% (heuristic, exc)
309309
)

tests/test_utils.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import os
2+
import os.path as op
23
from heudiconv.utils import (
34
get_known_heuristics_with_descriptions,
4-
get_heuristic_description
5+
get_heuristic_description,
6+
load_heuristic
57
)
68

9+
import pytest
10+
from .utils import HEURISTICS_PATH
11+
712

813
def test_get_known_heuristics_with_descriptions():
914
d = get_known_heuristics_with_descriptions()
@@ -21,4 +26,18 @@ def test_get_heuristic_description():
2126
assert '_ses-' in desc
2227
assert '_run-' in desc
2328
# and mention ReproNim ;)
24-
assert 'ReproNim' in desc
29+
assert 'ReproNim' in desc
30+
31+
32+
def test_load_heuristic():
33+
by_name = load_heuristic('reproin')
34+
from_file = load_heuristic(op.join(HEURISTICS_PATH, 'reproin.py'))
35+
36+
assert by_name
37+
assert by_name.filename == from_file.filename
38+
39+
with pytest.raises(ImportError):
40+
load_heuristic('unknownsomething')
41+
42+
with pytest.raises(ImportError):
43+
load_heuristic(op.join(HEURISTICS_PATH, 'unknownsomething.py'))

0 commit comments

Comments
 (0)