-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix issue with replacing data in reduction table (#105)
move the statement causing the crash (updating the GUI plots) from worker thread to main thread
- Loading branch information
Showing
6 changed files
with
99 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
85 changes: 85 additions & 0 deletions
85
test/unit/RefRed/reduction_table_handling/test_update_reduction_table.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
from RefRed.main import MainGui | ||
|
||
# third party packages | ||
import pytest | ||
from qtpy.QtCore import Qt | ||
import unittest.mock as mock | ||
|
||
wait = 200 | ||
|
||
|
||
class Event(object): | ||
val = None | ||
|
||
def __init__(self, val=None): | ||
self.val = val | ||
|
||
def key(self): | ||
return self.val | ||
|
||
|
||
class MockLocateListRun(object): | ||
"""Mock return value for LocateListRun""" | ||
|
||
list_run = [] | ||
list_nexus_found = ['/SNS/REF_L/IPTS-26776/nexus/REF_L_184975.nxs.h5'] | ||
list_run_found = [184975] | ||
list_run_not_found = [] | ||
|
||
|
||
@pytest.mark.parametrize("is_display_checked", [True, False]) | ||
@mock.patch( | ||
"RefRed.calculations.check_list_run_compatibility_thread.CheckListRunCompatibilityThread.updating_reductionTable_metadata" # noqa E501 | ||
) | ||
@mock.patch("RefRed.calculations.check_list_run_compatibility_thread.CheckListRunCompatibilityThread.loading_lr_data") | ||
@mock.patch( | ||
"RefRed.calculations.check_list_run_compatibility_thread.CheckListRunCompatibilityThread.update_lconfigdataset" | ||
) | ||
@mock.patch("RefRed.calculations.check_list_run_compatibility_thread.AddListNexus") | ||
@mock.patch("RefRed.main.ReductionTableCheckBox") | ||
@mock.patch("RefRed.main.DisplayPlots") | ||
@mock.patch("RefRed.reduction_table_handling.update_reduction_table.LocateListRun") | ||
def test_update_reduction_table_thread( | ||
mock_locate_list_run, | ||
mock_display_plots, | ||
mock_reduction_table_checkbox, | ||
mock_add_list_nexus, | ||
mock_update_lconfigdataset, | ||
mock_loading_lr_data, | ||
mock_updating_reductionTable_metadata, | ||
is_display_checked, | ||
qtbot, | ||
): | ||
"""Test of the communication between the main thread and CheckListRunCompatibilityThread | ||
Note: This only tests the signalling between the main thread and the thread spawned by | ||
CheckListRunCompatibilityThread. The actual logic updating run data and plots is mocked. | ||
""" | ||
mock_locate_list_run.return_value = MockLocateListRun() | ||
mock_add_list_nexus.return_value = mock.Mock(ws=True) | ||
|
||
window_main = MainGui() | ||
qtbot.addWidget(window_main) | ||
# set the display checkbox to the desired value | ||
window_main.ui.reductionTable.cellWidget(0, 0).setChecked(is_display_checked) | ||
# set a run number in the reduction table | ||
window_main.ui.reductionTable.setCurrentCell(0, 1) | ||
window_main.ui.reductionTable.currentItem().setText("184975") | ||
|
||
# press Enter in run number cell to trigger update_reduction_table | ||
window_main.ui.reductionTable.keyPressEvent(Event(Qt.Key_Return)) | ||
qtbot.wait(wait) | ||
|
||
# check mocked functions in the spawned thread | ||
mock_update_lconfigdataset.assert_called_once() | ||
mock_loading_lr_data.assert_called_once() | ||
mock_updating_reductionTable_metadata.assert_called_once() | ||
|
||
# check that display plots is only called if the checkbox is checked | ||
if is_display_checked: | ||
mock_display_plots.assert_called_once() | ||
else: | ||
mock_display_plots.assert_not_called() | ||
|
||
# check that the reduction table was re-enabled after the thread returned | ||
assert window_main.ui.reductionTable.isEnabled() |
86281cd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GitLab pipeline for refred-dev has been submitted for this commit: "https://code.ornl.gov/sns-hfir-scse/deployments/conda-legacy-deploy/-/pipelines/486992"