File tree Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -303,7 +303,7 @@ def load_heuristic(heuristic):
303
303
mod = import_module ('heudiconv.heuristics.%s' % heuristic )
304
304
mod .filename = mod .__file__ .rstrip ('co' ) # remove c or o from pyc/pyo
305
305
except Exception as exc :
306
- raise RuntimeError (
306
+ raise ImportError (
307
307
"Failed to import heuristic %s: %s"
308
308
% (heuristic , exc )
309
309
)
Original file line number Diff line number Diff line change 1
1
import os
2
+ import os .path as op
2
3
from heudiconv .utils import (
3
4
get_known_heuristics_with_descriptions ,
4
- get_heuristic_description
5
+ get_heuristic_description ,
6
+ load_heuristic
5
7
)
6
8
9
+ import pytest
10
+ from .utils import HEURISTICS_PATH
11
+
7
12
8
13
def test_get_known_heuristics_with_descriptions ():
9
14
d = get_known_heuristics_with_descriptions ()
@@ -21,4 +26,18 @@ def test_get_heuristic_description():
21
26
assert '_ses-' in desc
22
27
assert '_run-' in desc
23
28
# 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' ))
You can’t perform that action at this time.
0 commit comments