Operations: Fix Crop Coordinates ROI not updating when switching between stacks#3145
Operations: Fix Crop Coordinates ROI not updating when switching between stacks#3145RasmiaKulan wants to merge 4 commits into
Conversation
a1d7609 to
8f13664
Compare
JackEAllen
left a comment
There was a problem hiding this comment.
Thank you for adding a fix. Functionally this works well and resolves the issue 🥳
I do have a small question about the test I'd like to get your opinion on, but otherwise happy with the change.
We can explore improving the extendability of updating fields on stack change for specific operations such is the case with this fix separately as part of #3152
| first_stack = mock.Mock() | ||
| first_stack.data = np.ones((2, 201, 201)) | ||
|
|
||
| second_stack = mock.Mock() | ||
| second_stack.data = np.ones((2, 143, 140)) |
There was a problem hiding this comment.
Are the stacks used in this test if we are mocking get_bounding_box?
I think that when the init_roi_field runs, it does not inspect stack.data, it just uses the mocked return values via the side_effect so you may be abel to remove them so long as you keep the distinct stack assignment and init calls by having two:
self.presenter.stack = mock.Mock()
self.presenter.init_roi_field(mock_roi_field)where assigning one stack object to the presenter.stack and calling init_roi_field performed twice may be enough to emulate a stack change.
…ilter is selected
| stack = mock.Mock( | ||
| name="test_stack", | ||
| shape=(2, 201, 201), | ||
| num_images=2, | ||
| num_sinograms=201, | ||
| ) | ||
| with mock.patch("mantidimaging.gui.windows.operations.presenter.BlockQtSignals"): | ||
| self.presenter.set_stack(stack) | ||
|
|
There was a problem hiding this comment.
The main assertion here looks good, but do we need the mock attributes here?
They are set, but don't seem to be asserted anywhere after being passed to the mock unless i've missed something.
As do_update_previews is not mocked, I wonder if this could silently succeed or fail for unrelated reasons. i'd be tempted to add it ( @mock.patch('mantidimaging.gui.windows.operations.presenter.FiltersWindowPresenter.do_update_previews')) as an additional patch and we could then simplify to:
stack = mock.Mock(name="test_stack")
self.presenter.set_stack(stack)There was a problem hiding this comment.
@JackEAllen I still needed to keep:
with mock.patch("mantidimaging.gui.windows.operations.presenter.BlockQtSignals")because self.view in the test is a MagicMock rather than a real Qt QObject. Without the patch, BlockQtSignals runs its real assertion:
assert isinstance(obj, QObject)which causes the test to fail before reaching the behaviour under test.
I also still needed to specify num_images on the stack mock because set_stack() accesses self.max_preview_image_idx, which evaluates:
self.stack.num_images - 1If num_images is left as the default auto-generated Mock, this results in:
TypeError: unsupported operand type(s) for -: 'Mock' and 'int'Since do_update_previews is now mocked, the additional attributes like shape and num_sinograms are no longer required, so the test can still be simplified to only the minimal attributes actually used by set_stack().
Issue Closes #3115
Description
set_stacksto refresh the ROI field using the current stack if the currently selected filter is Crop Coordinates, and the ROI field exists.roi_field_called_with_auto_bounding_box_on_different_stacksDeveloper Testing
python -m pytest -vsroi_field_called_with_auto_bounding_box_on_different_stackspasses locally. Tested using the debugger as well to check if the variables were returning expected results.Acceptance Criteria and Reviewer Testing
python -m pytest -vsROI within FoV steps:
Auto-crop is re-activated when switching between stacks when multiple datasets are loaded:
Documentation and Additional Notes