19
19
)
20
20
from ibex_bluesky_core .plans .reflectometry ._autoalign import (
21
21
_check_parameter ,
22
+ _optimise_axis_over_range ,
22
23
)
23
24
24
25
@@ -104,10 +105,6 @@ def plan(mock) -> Generator[Msg, None, None]:
104
105
105
106
mock = MagicMock ()
106
107
107
- def _mock_optimise_axis_over_range (* args , ** kwargs ):
108
- yield from bps .null ()
109
- return None , True
110
-
111
108
with (
112
109
patch ("ibex_bluesky_core.devices.reflectometry.get_pv_prefix" , return_value = prefix ),
113
110
patch ("ibex_bluesky_core.plans.reflectometry._autoalign.scan" , return_value = _fake_scan ()),
@@ -120,10 +117,6 @@ def _mock_optimise_axis_over_range(*args, **kwargs):
120
117
"ibex_bluesky_core.plans.reflectometry._autoalign._check_parameter" ,
121
118
side_effect = ["Test!" , None ],
122
119
),
123
- patch (
124
- "ibex_bluesky_core.plans.reflectometry._autoalign._optimise_axis_over_range" ,
125
- new = _mock_optimise_axis_over_range ,
126
- ),
127
120
):
128
121
param = ReflParameter (prefix = prefix , name = "S1VG" , changing_timeout_s = 60 )
129
122
@@ -143,10 +136,10 @@ def _mock_optimise_axis_over_range(*args, **kwargs):
143
136
144
137
145
138
@pytest .mark .parametrize (
146
- "param_value, problem_str" ,
139
+ ( "param_value" , " problem_str") ,
147
140
[
148
- (- 5 , "Optimised value found to be to be outside, to the right , of scan range" ),
149
- (5 , "Optimised value found to be to be outside, to the left , of scan range" ),
141
+ (- 5 , "Optimised value found to be to be outside, to the left , of scan range" ),
142
+ (5 , "Optimised value found to be to be outside, to the right , of scan range" ),
150
143
(0 , None ),
151
144
],
152
145
)
@@ -155,11 +148,9 @@ def test_alignment_param_value_outside_of_scan_range_returns_problem(param_value
155
148
with (
156
149
patch ("lmfit.model.ModelResult" ) as mr ,
157
150
):
158
- mr .values = {"x0" : param_value }
159
-
160
151
assert (
161
152
_check_parameter (
162
- alignment_param_value = 0.0 ,
153
+ alignment_param_value = param_value ,
163
154
result = mr ,
164
155
init_mot_pos = 0.0 ,
165
156
rel_scan_range = 1.0 ,
@@ -182,31 +173,26 @@ def my_check(model: ModelResult, param_val: float) -> str | None:
182
173
with patch ("lmfit.model.ModelResult" ) as mr :
183
174
mr .values = {"x0" : 0.0 }
184
175
185
- if problem :
186
- with pytest .raises (ValueError ):
187
- _check_parameter (
188
- alignment_param_value = 0.0 ,
189
- result = mr ,
190
- init_mot_pos = 0.0 ,
191
- rel_scan_range = 1.0 ,
192
- is_good_fit = my_check ,
193
- )
194
-
195
- else : # Check that does not raise
196
- _check_parameter (
197
- alignment_param_value = 0.0 ,
198
- result = mr ,
199
- init_mot_pos = 0.0 ,
200
- rel_scan_range = 1.0 ,
201
- is_good_fit = my_check ,
202
- )
176
+ assert ("problem" if problem else None ) == _check_parameter (
177
+ alignment_param_value = 0.0 ,
178
+ result = mr ,
179
+ init_mot_pos = 0.0 ,
180
+ rel_scan_range = 1.0 ,
181
+ is_good_fit = my_check ,
182
+ )
203
183
204
184
205
- def test_that_if_no_problem_found_then_motor_is_moved_and_rezeroed (RE , prefix , simpledae ):
185
+ def test_that_if_no_problem_found_then_motor_is_moved (RE , prefix , simpledae ):
206
186
"""Test that if no problems are found with the optimised
207
- value then move the motor to it and redefine this as 0
187
+ value then move the motor to it
208
188
"""
209
- sp = 5.0
189
+
190
+ icc = MagicMock (spec = ISISCallbacks )
191
+ icc .live_fit .fit_result .params ["" ] = 0.0
192
+
193
+ def mock_scan (* a , ** k ):
194
+ yield from bps .null ()
195
+ return icc
210
196
211
197
with (
212
198
patch ("ibex_bluesky_core.devices.reflectometry.get_pv_prefix" , return_value = prefix ),
@@ -223,19 +209,24 @@ def test_that_if_no_problem_found_then_motor_is_moved_and_rezeroed(RE, prefix, s
223
209
return_value = _plan_return_0 (),
224
210
),
225
211
patch (
226
- "ibex_bluesky_core.plans.reflectometry._autoalign._optimise_axis_over_range " ,
227
- return_value = sp ,
212
+ "ibex_bluesky_core.plans.reflectometry._autoalign.scan " ,
213
+ new = mock_scan ,
228
214
),
229
215
):
230
216
param = ReflParameter (prefix = prefix , name = "S1VG" , changing_timeout_s = 60 )
231
217
232
218
RE (
233
- optimise_axis_against_intensity (
219
+ _optimise_axis_over_range (
234
220
simpledae ,
235
221
alignment_param = param ,
236
- rel_scan_ranges = [ 0.0 ] ,
222
+ rel_scan_range = 0.0 ,
237
223
fit_method = SlitScan ().fit (),
238
224
fit_param = "" ,
225
+ num_points = 10 ,
226
+ periods = True ,
227
+ save_run = True ,
228
+ is_good_fit = lambda * a , ** k : None ,
229
+ problem_found_plan = bps .null ,
239
230
)
240
231
)
241
232
@@ -247,11 +238,13 @@ def test_that_if_problem_found_and_type_1_then_re_scan(RE, prefix, simpledae, mo
247
238
"""Test that if a problem is found, and the user types 1, then rescan.
248
239
Then if they type 2, moves to value.
249
240
"""
241
+ call_count = 0
250
242
251
243
def counter (str : str ):
252
- counter .call_count += 1 # type: ignore
244
+ nonlocal call_count
245
+ call_count += 1 # type: ignore
253
246
254
- if counter . call_count == 1 : # type: ignore
247
+ if call_count == 1 : # type: ignore
255
248
return "1"
256
249
else :
257
250
return "2"
@@ -271,13 +264,8 @@ def counter(str: str):
271
264
"ibex_bluesky_core.plans.reflectometry._autoalign.bps.rd" ,
272
265
return_value = _plan_return_0 (),
273
266
),
274
- patch (
275
- "ibex_bluesky_core.plans.reflectometry._autoalign._optimise_axis_over_range" ,
276
- return_value = 0 ,
277
- ),
278
267
):
279
268
param = ReflParameter (prefix = prefix , name = "S1VG" , changing_timeout_s = 60 )
280
- counter .call_count = 0 # type: ignore
281
269
282
270
monkeypatch .setattr ("builtins.input" , counter )
283
271
RE (
@@ -297,13 +285,15 @@ def test_that_if_problem_found_and_type_random_then_re_ask(RE, prefix, simpledae
297
285
"""Test that if a problem is found, and the user types gibberish, then ask again.
298
286
Then if they type 1, it rescans. If they type 2, it moves to value.
299
287
"""
288
+ call_count = 0
300
289
301
290
def counter (str : str ):
302
- counter .call_count += 1 # type: ignore
291
+ nonlocal call_count
292
+ call_count += 1
303
293
304
- if counter . call_count == 1 : # type: ignore
294
+ if call_count == 1 : # type: ignore
305
295
return "platypus"
306
- elif counter . call_count == 2 : # type: ignore
296
+ elif call_count == 2 : # type: ignore
307
297
return "1"
308
298
else :
309
299
return "2"
@@ -323,20 +313,15 @@ def counter(str: str):
323
313
"ibex_bluesky_core.plans.reflectometry._autoalign.bps.rd" ,
324
314
return_value = _plan_return_0 (),
325
315
),
326
- patch (
327
- "ibex_bluesky_core.plans.reflectometry._autoalign._optimise_axis_over_range" ,
328
- return_value = 0 ,
329
- ),
330
316
):
331
317
param = ReflParameter (prefix = prefix , name = "S1VG" , changing_timeout_s = 60 )
332
- counter .call_count = 0 # type: ignore
333
318
334
319
monkeypatch .setattr ("builtins.input" , counter )
335
320
RE (
336
321
optimise_axis_against_intensity (
337
322
simpledae ,
338
323
alignment_param = param ,
339
- rel_scan_ranges = [0 .0 ],
324
+ rel_scan_ranges = [10 .0 ],
340
325
fit_method = SlitScan ().fit (),
341
326
fit_param = "" ,
342
327
)
0 commit comments