@@ -81,6 +81,24 @@ def pytest_addoption(parser):
8181 type = str ,
8282 help = "Drop this algorithm from the list"
8383 )
84+ parser .addoption (
85+ "--withmatlab" ,
86+ action = "store_true" ,
87+ default = False ,
88+ help = "Run MATLAB-dependent tests"
89+ )
90+
91+
92+ @pytest .fixture (scope = "session" )
93+ def eng (request ):
94+ """Start and return a MATLAB engine session if --withmatlab is set."""
95+ if not request .config .getoption ("--withmatlab" ):
96+ return None
97+ import matlab .engine
98+ print ("Starting MATLAB engine..." )
99+ eng = matlab .engine .start_matlab ()
100+ print ("MATLAB engine started." )
101+ return eng
84102
85103
86104@pytest .fixture (scope = "session" )
@@ -149,25 +167,20 @@ def use_prior(request):
149167def pytest_generate_tests (metafunc ):
150168 if "SNR" in metafunc .fixturenames :
151169 metafunc .parametrize ("SNR" , metafunc .config .getoption ("SNR" ))
152- if "ivim_algorithm" in metafunc .fixturenames :
153- algorithms = algorithm_list (metafunc .config .getoption ("algorithmFile" ), metafunc .config .getoption ("selectAlgorithm" ), metafunc .config .getoption ("dropAlgorithm" ))
154- metafunc .parametrize ("ivim_algorithm" , algorithms )
155170 if "ivim_data" in metafunc .fixturenames :
156171 data = data_list (metafunc .config .getoption ("dataFile" ))
157172 metafunc .parametrize ("ivim_data" , data )
173+ if "data_ivim_fit_saved" in metafunc .fixturenames :
174+ args = data_ivim_fit_saved (metafunc .config .getoption ("dataFile" ),metafunc .config .getoption ("algorithmFile" ))
175+ metafunc .parametrize ("data_ivim_fit_saved" , args )
176+ if "algorithmlist" in metafunc .fixturenames :
177+ args = algorithmlist (metafunc .config .getoption ("algorithmFile" ))
178+ metafunc .parametrize ("algorithmlist" , args )
179+ if "bound_input" in metafunc .fixturenames :
180+ args = bound_input (metafunc .config .getoption ("dataFile" ),metafunc .config .getoption ("algorithmFile" ))
181+ metafunc .parametrize ("bound_input" , args )
158182
159183
160- def algorithm_list (filename , selected , dropped ):
161- current_folder = pathlib .Path .cwd ()
162- algorithm_path = current_folder / filename
163- with algorithm_path .open () as f :
164- algorithm_information = json .load (f )
165- algorithms = set (algorithm_information ["algorithms" ])
166- algorithms = algorithms - set (dropped )
167- if len (selected ) > 0 and selected [0 ]:
168- algorithms = algorithms & set (selected )
169- return list (algorithms )
170-
171184def data_list (filename ):
172185 current_folder = pathlib .Path .cwd ()
173186 data_path = current_folder / filename
@@ -178,3 +191,69 @@ def data_list(filename):
178191 bvals = bvals ['bvalues' ]
179192 for name , data in all_data .items ():
180193 yield name , bvals , data
194+
195+
196+ def data_ivim_fit_saved (datafile , algorithmFile ):
197+ # Find the algorithms from algorithms.json
198+ current_folder = pathlib .Path .cwd ()
199+ algorithm_path = current_folder / algorithmFile
200+ with algorithm_path .open () as f :
201+ algorithm_information = json .load (f )
202+ # Load generic test data generated from the included phantom: phantoms/MR_XCAT_qMRI
203+ generic = current_folder / datafile
204+ with generic .open () as f :
205+ all_data = json .load (f )
206+ algorithms = algorithm_information ["algorithms" ]
207+ bvals = all_data .pop ('config' )
208+ bvals = bvals ['bvalues' ]
209+ for algorithm in algorithms :
210+ first = True
211+ for name , data in all_data .items ():
212+ algorithm_dict = algorithm_information .get (algorithm , {})
213+ xfail = {"xfail" : name in algorithm_dict .get ("xfail_names" , {}),
214+ "strict" : algorithm_dict .get ("xfail_names" , {}).get (name , True )}
215+ kwargs = algorithm_dict .get ("options" , {})
216+ tolerances = algorithm_dict .get ("tolerances" , {})
217+ skiptime = False
218+ if first :
219+ if algorithm_dict .get ("fail_first_time" , False ):
220+ skiptime = True
221+ first = False
222+ requires_matlab = algorithm_dict .get ("requires_matlab" , False )
223+ yield name , bvals , data , algorithm , xfail , kwargs , tolerances , skiptime , requires_matlab
224+
225+ def algorithmlist (algorithmFile ):
226+ # Find the algorithms from algorithms.json
227+ current_folder = pathlib .Path .cwd ()
228+ algorithm_path = current_folder / algorithmFile
229+ with algorithm_path .open () as f :
230+ algorithm_information = json .load (f )
231+
232+ algorithms = algorithm_information ["algorithms" ]
233+ for algorithm in algorithms :
234+ algorithm_dict = algorithm_information .get (algorithm , {})
235+ requires_matlab = algorithm_dict .get ("requires_matlab" , False )
236+ yield algorithm , requires_matlab
237+
238+ def bound_input (datafile ,algorithmFile ):
239+ # Find the algorithms from algorithms.json
240+ current_folder = pathlib .Path .cwd ()
241+ algorithm_path = current_folder / algorithmFile
242+ with algorithm_path .open () as f :
243+ algorithm_information = json .load (f )
244+ # Load generic test data generated from the included phantom: phantoms/MR_XCAT_qMRI
245+ generic = current_folder / datafile
246+ with generic .open () as f :
247+ all_data = json .load (f )
248+ algorithms = algorithm_information ["algorithms" ]
249+ bvals = all_data .pop ('config' )
250+ bvals = bvals ['bvalues' ]
251+ for name , data in all_data .items ():
252+ for algorithm in algorithms :
253+ algorithm_dict = algorithm_information .get (algorithm , {})
254+ xfail = {"xfail" : name in algorithm_dict .get ("xfail_names" , {}),
255+ "strict" : algorithm_dict .get ("xfail_names" , {}).get (name , True )}
256+ kwargs = algorithm_dict .get ("options" , {})
257+ tolerances = algorithm_dict .get ("tolerances" , {})
258+ requires_matlab = algorithm_dict .get ("requires_matlab" , False )
259+ yield name , bvals , data , algorithm , xfail , kwargs , tolerances , requires_matlab
0 commit comments