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

Function test_DialogLoadMask_2

pyxrf/gui_module/tests/test_wd_load_data.py:60–114  ·  view source on GitHub ↗

DialogLoadMask - ROI selection group. In this test, the ROI selection is modified using keyboard clicks. Checked features: initalization, enabling/disabling ROI selection group, editing the ROI entries, synchronization of entered and stored values, showing/hiding the displayed value

(qtbot)

Source from the content-addressed store, hash-verified

58
59
60def test_DialogLoadMask_2(qtbot):
61 """
62 DialogLoadMask - ROI selection group.
63 In this test, the ROI selection is modified using keyboard clicks.
64 Checked features: initalization, enabling/disabling ROI selection group, editing the ROI entries,
65 synchronization of entered and stored values, showing/hiding the displayed values as
66 the group is enabled/disabled.
67 """
68 dlg = DialogLoadMask()
69 qtbot.addWidget(dlg)
70 dlg.show()
71
72 def _check_roi_widgets(expected_values):
73 l_edit_widgets = (dlg.le_roi_start_row, dlg.le_roi_start_col, dlg.le_roi_end_row, dlg.le_roi_end_col)
74 for n, v in enumerate(expected_values):
75 if n < 2: # First 2 entries (are incremented when displayed)
76 v += 1
77 s = f"{v}" if v > 0 else ""
78 assert l_edit_widgets[n].text() == s, "Line Edit text does not match the expected text"
79
80 # Set image size
81 n_rows, n_columns = 25, 37
82 dlg.set_image_size(n_rows=n_rows, n_columns=n_columns)
83
84 assert not dlg.gb_roi.isChecked(), "ROI selection group must be active"
85 _check_roi_widgets([0, 0, n_rows, n_columns])
86 dlg.gb_roi.setChecked(True) # There seems to be no way to change the state of the group box by clicking
87 assert dlg.gb_roi.isChecked(), "Failed to activate ROI group"
88 _check_roi_widgets([0, 0, n_rows, n_columns])
89
90 # Use keyboard to enter values in each box
91 def _enter_value(edit_box, value):
92 qtbot.mouseDClick(edit_box, Qt.LeftButton)
93 qtbot.keyClicks(edit_box, f"{value}")
94 qtbot.keyClick(edit_box, Qt.Key_Enter)
95
96 # Enter a new ROI using keyboard
97 sel = (11, 8, 23, 19)
98 _enter_value(dlg.le_roi_start_row, sel[0] + 1)
99 _enter_value(dlg.le_roi_start_col, sel[1] + 1)
100 _enter_value(dlg.le_roi_end_row, sel[2])
101 _enter_value(dlg.le_roi_end_col, sel[3])
102 _check_roi_widgets(sel)
103 # Now check if the values were set correctly
104 assert dlg.get_roi() == sel, "ROI was incorrectly set"
105
106 # Disable and then enable the ROI group again, the entered values should remain
107 dlg.gb_roi.setChecked(False)
108 assert dlg.get_roi_active() is False, "ROI group must be inactive"
109 _check_roi_widgets(sel) # Values must be hidden now
110 assert dlg.get_roi() == sel, "Unexpected ROI selection values"
111 dlg.gb_roi.setChecked(True)
112 assert dlg.get_roi_active() is True, "ROI group must be active"
113 _check_roi_widgets(sel) # Values must be displayed
114 assert dlg.get_roi() == sel, "Unexpected ROI selection values"
115
116
117@pytest.mark.parametrize("use_keys_and_mouse", [False, True])

Callers

nothing calls this directly

Calls 7

set_image_sizeMethod · 0.95
get_roiMethod · 0.95
get_roi_activeMethod · 0.95
DialogLoadMaskClass · 0.85
_check_roi_widgetsFunction · 0.85
_enter_valueFunction · 0.85
showMethod · 0.80

Tested by

no test coverage detected