MCPcopy Create free account
hub / github.com/NSLS2/PyXRF / test_RangeManager_1

Function test_RangeManager_1

pyxrf/gui_module/tests/test_useful_widgets.py:209–253  ·  view source on GitHub ↗

RangeManager: test the function for setting and changing value type

(qtbot)

Source from the content-addressed store, hash-verified

207
208
209def test_RangeManager_1(qtbot):
210 """
211 RangeManager: test the function for setting and changing value type
212 """
213 rman = RangeManager()
214 qtbot.addWidget(rman)
215 rman.show()
216
217 def _compare_tuples(*, returned, expected, v_type):
218 assert len(returned) == len(expected), "Returned selection has wrong number of elements"
219 for v in returned:
220 assert isinstance(v, v_type), f"Returned value has wrong type: {type(v)})"
221 npt.assert_array_almost_equal(
222 returned, expected, err_msg="Returned and original selection are not identical"
223 )
224
225 # The value type is 'float' by default
226 f_range = (25.123, 89.892)
227 f_selection = (32.65, 47.2)
228 rman.set_range(f_range[0], f_range[1])
229 rman.set_selection(value_low=f_selection[0], value_high=f_selection[1])
230
231 # Read the selection back
232 _compare_tuples(returned=rman.get_selection(), expected=f_selection, v_type=float)
233 _compare_tuples(returned=rman.get_range(), expected=f_range, v_type=float)
234
235 # Switch value type to "int". Selection is expected to change because due to rouning.
236 # The selection is also expected to change because the new selection is supposed to
237 # cover the same fraction of the total range, but the numbers were selected so
238 # this does not affect the result.
239 selection_changed = rman.set_value_type("int")
240 assert selection_changed, "Selection was not changed (expected to change)"
241
242 i_range = tuple(round(_) for _ in f_range)
243 i_selection = tuple(round(_) for _ in f_selection)
244
245 _compare_tuples(returned=rman.get_selection(), expected=i_selection, v_type=int)
246 _compare_tuples(returned=rman.get_range(), expected=i_range, v_type=int)
247
248 # Switch value type back to "float"
249 selection_changed = rman.set_value_type("float")
250 assert not selection_changed, "Selection changed (not expected to change)"
251
252 _compare_tuples(returned=rman.get_selection(), expected=i_selection, v_type=float)
253 _compare_tuples(returned=rman.get_range(), expected=i_range, v_type=float)
254
255
256# fmt: off

Callers

nothing calls this directly

Calls 8

set_rangeMethod · 0.95
set_selectionMethod · 0.95
get_selectionMethod · 0.95
get_rangeMethod · 0.95
set_value_typeMethod · 0.95
RangeManagerClass · 0.90
_compare_tuplesFunction · 0.85
showMethod · 0.80

Tested by

no test coverage detected