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

Function test_RangeManager_3

pyxrf/gui_module/tests/test_useful_widgets.py:318–368  ·  view source on GitHub ↗

Test `set_selection()` method

(qtbot, full_range, selection, value_type)

Source from the content-addressed store, hash-verified

316])
317# fmt: on
318def test_RangeManager_3(qtbot, full_range, selection, value_type):
319 """Test `set_selection()` method"""
320
321 slider_steps = 1000
322 selection_to_range_min = 0.01
323
324 rman = RangeManager(slider_steps=slider_steps, selection_to_range_min=selection_to_range_min)
325 qtbot.addWidget(rman)
326 rman.show()
327
328 rman.set_value_type(value_type)
329 rman.set_range(full_range[0], full_range[1])
330
331 def _clip_selection(sel, rng, selection_to_range_min):
332 """
333 Clip the selection values to compute the expected selection.
334 Reproduces the clipping performed by the RangeManager.
335 """
336 sel = [max(min(_, rng[1]), rng[0]) for _ in sel]
337 if value_type == "float":
338 min_diff = (rng[1] - rng[0]) * selection_to_range_min
339 else:
340 min_diff = 1
341 if sel[1] - sel[0] < min_diff:
342 sel[1] = sel[0] + min_diff
343 if sel[1] > rng[1]:
344 sel = [rng[1] - min_diff, rng[1]]
345 return sel
346
347 sel = _clip_selection(selection, full_range, selection_to_range_min)
348
349 result_expected = True
350 if tuple(sel) == tuple(full_range):
351 result_expected = False
352
353 result = rman.set_selection(value_low=selection[0], value_high=selection[1])
354 assert result == result_expected, f"Incorrect return value {result} by `set_selection()` method"
355
356 npt.assert_array_almost_equal(rman.get_selection(), sel, err_msg="Selection is set incorrectly")
357 # Verify that selection is displayed correctly
358 assert rman.le_min_value.text() == f"{sel[0]:.10g}", "Lower boundary is displayed incorrectly"
359 assert rman.le_max_value.text() == f"{sel[1]:.10g}", "Upper boundary is displayed incorrectly"
360
361 # Check positions of the sliders
362 step = (full_range[1] - full_range[0]) / slider_steps
363 assert rman.sld_min_value.value() == slider_steps - round(
364 (sel[0] - full_range[0]) / step
365 ), "Slider position (min. value) is incorrect"
366 assert rman.sld_max_value.value() == round(
367 (sel[1] - full_range[0]) / step
368 ), "Slider position (max. value) is incorrect"
369
370
371# fmt: off

Callers

nothing calls this directly

Calls 7

set_value_typeMethod · 0.95
set_rangeMethod · 0.95
set_selectionMethod · 0.95
get_selectionMethod · 0.95
RangeManagerClass · 0.90
_clip_selectionFunction · 0.85
showMethod · 0.80

Tested by

no test coverage detected