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

Function test_RangeManager_8

pyxrf/gui_module/tests/test_useful_widgets.py:566–633  ·  view source on GitHub ↗

Entering selection boundaries via keyboard

(qtbot, full_range, selection, value_type)

Source from the content-addressed store, hash-verified

564])
565# fmt: on
566def test_RangeManager_8(qtbot, full_range, selection, value_type):
567 """Entering selection boundaries via keyboard"""
568
569 slider_steps = 1000
570 selection_to_range_min = 0.01
571
572 rman = RangeManager(slider_steps=slider_steps, selection_to_range_min=selection_to_range_min)
573 qtbot.addWidget(rman)
574 rman.show()
575
576 def _verify_sliders(slider_low, slider_high, sel, rng):
577 step = (rng[1] - rng[0]) / slider_steps
578 # 'low' value
579 pos_expected = slider_steps - round((sel[0] - rng[0]) / step)
580 assert slider_low.value() == pos_expected, "Lower boundary slider value (position) is incorrect"
581 # 'high' value
582 pos_expected = round((sel[1] - rng[0]) / step)
583 assert slider_high.value() == pos_expected, "Higher boundary slider value (position) is incorrect"
584
585 rman.set_range(full_range[0], full_range[1])
586 rman.reset() # Select the full range
587
588 # This variable will hold the parameters that were passed with the signal
589 returned_sig_parameters = None
590
591 def _check_signal_params(low, high, name):
592 # Instead of verification of parameters, this function copies the parameters
593 # into a variable `returned_sig_parameters`. If the verification is performed
594 # inside the function (as intended), then no nice error message is printed.
595 nonlocal returned_sig_parameters
596 returned_sig_parameters = (low, high)
597 return True
598
599 # Enter lower boundary
600 with qtbot.waitSignal(rman.selection_changed, check_params_cb=_check_signal_params):
601 enter_text_via_keyboard(qtbot, rman.le_min_value, f"{selection[0]:.10g}", finish=True)
602 npt.assert_array_almost_equal(returned_sig_parameters, (selection[0], full_range[1]))
603 _verify_sliders(rman.sld_min_value, rman.sld_max_value, (selection[0], full_range[1]), full_range)
604
605 # Enter upper boundary
606 with qtbot.waitSignal(rman.selection_changed, check_params_cb=_check_signal_params):
607 enter_text_via_keyboard(qtbot, rman.le_max_value, f"{selection[1]:.10g}", finish=True)
608 npt.assert_array_almost_equal(returned_sig_parameters, (selection[0], selection[1]))
609 _verify_sliders(rman.sld_min_value, rman.sld_max_value, (selection[0], selection[1]), full_range)
610
611 # Enter out-of-range lower boundary. Shouldn't generate the signal.
612 with qtbot.assertNotEmitted(rman.selection_changed):
613 enter_text_via_keyboard(qtbot, rman.le_min_value, f"{selection[1] + 1:.10g}", finish=True)
614 npt.assert_array_almost_equal(rman.get_selection(), (selection[0], selection[1]))
615 _verify_sliders(rman.sld_min_value, rman.sld_max_value, (selection[0], selection[1]), full_range)
616
617 # Enter some random string. Shouldn't generate the signal.
618 with qtbot.assertNotEmitted(rman.selection_changed):
619 enter_text_via_keyboard(qtbot, rman.le_min_value, "random string", finish=True)
620 npt.assert_array_almost_equal(rman.get_selection(), (selection[0], selection[1]))
621 _verify_sliders(rman.sld_min_value, rman.sld_max_value, (selection[0], selection[1]), full_range)
622
623 # Enter out-of-range upper boundary. Shouldn't generate the signal.

Callers

nothing calls this directly

Calls 7

set_rangeMethod · 0.95
resetMethod · 0.95
get_selectionMethod · 0.95
RangeManagerClass · 0.90
enter_text_via_keyboardFunction · 0.85
_verify_slidersFunction · 0.85
showMethod · 0.80

Tested by

no test coverage detected