Skip to content

Commit e758974

Browse files
add flag for running matlab tests
1 parent 799920b commit e758974

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

tests/IVIMmodels/unit_tests/algorithms.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
],
1818
"ASD_MemorialSloanKettering_QAMPER_IVIM": {
1919
"requieres_matlab": true,
20-
"fail_first_time": true
2120
},
2221
"IAR_LU_biexp": {
2322
"fail_first_time": true

tests/IVIMmodels/unit_tests/test_ivim_fit.py

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,22 @@
66
import time
77
from src.wrappers.OsipiBase import OsipiBase
88
#run using python -m pytest from the root folder
9-
import matlab.engine
109

11-
eng=matlab.engine.start_matlab()
10+
11+
eng = None
12+
13+
def pytest_addoption(parser):
14+
parser.addoption(
15+
"--with-matlab", action="store_true", default=False, help="Run MATLAB-dependent tests"
16+
)
17+
18+
@pytest.hookimpl
19+
def pytest_configure(config):
20+
global eng
21+
if config.getoption("--with-matlab"):
22+
import matlab.engine
23+
eng = matlab.engine.start_matlab()
24+
1225

1326
def signal_helper(signal):
1427
signal = np.asarray(signal)
@@ -61,7 +74,10 @@ def data_ivim_fit_saved():
6174
skiptime = True
6275
first = False # this will only work for 1 algorithm... If two algorithms use fail_first_time, the second will not see it is the first time.
6376
if algorithm_dict.get("requieres_matlab", {}) == True:
64-
kwargs={**kwargs,'eng': eng}
77+
if eng is None:
78+
continue
79+
else:
80+
kwargs={**kwargs,'eng': eng}
6581
yield name, bvals, data, algorithm, xfail, kwargs, tolerances, skiptime
6682

6783
@pytest.mark.parametrize("name, bvals, data, algorithm, xfail, kwargs, tolerances, skiptime", data_ivim_fit_saved())
@@ -100,7 +116,7 @@ def to_list_if_needed(value):
100116
assert elapsed_time < 0.5, f"Algorithm {name} took {elapsed_time} seconds, which is longer than 2 second to fit per voxel" #less than 0.5 seconds per voxel
101117

102118

103-
def algorithms():
119+
def algorithmlist():
104120
# Find the algorithms from algorithms.json
105121
file = pathlib.Path(__file__)
106122
algorithm_path = file.with_name('algorithms.json')
@@ -111,10 +127,13 @@ def algorithms():
111127
algorithm_dict = algorithm_information.get(algorithm, {})
112128
args={}
113129
if algorithm_dict.get("requieres_matlab", {}) == True:
114-
args['eng'] = eng
130+
if eng is None:
131+
continue
132+
else:
133+
kwargs = {**kwargs, 'eng': eng}
115134
yield algorithm, args
116135

117-
@pytest.mark.parametrize("algorithm, args", algorithms())
136+
@pytest.mark.parametrize("algorithm, args", algorithmlist())
118137
def test_default_bounds_and_initial_guesses(algorithm, args):
119138
fit = OsipiBase(algorithm=algorithm,**args)
120139
#assert fit.bounds is not None, f"For {algorithm}, there is no default fit boundary"
@@ -159,7 +178,10 @@ def bound_input():
159178
kwargs = algorithm_dict.get("options", {})
160179
tolerances = algorithm_dict.get("tolerances", {})
161180
if algorithm_dict.get("requieres_matlab", {}) == True:
162-
kwargs={**kwargs,'eng': eng}
181+
if eng is None:
182+
continue
183+
else:
184+
kwargs = {**kwargs, 'eng': eng}
163185
yield name, bvals, data, algorithm, xfail, kwargs, tolerances
164186

165187

0 commit comments

Comments
 (0)