Skip to content

Commit

Permalink
Use mock.patch.object() as we have reference to object
Browse files Browse the repository at this point in the history
  • Loading branch information
samtygier-stfc committed Dec 4, 2023
1 parent 4504509 commit d623014
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions mantidimaging/gui/windows/spectrum_viewer/test/model_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def test_save_csv(self):
self.model.set_normalise_stack(None)

mock_stream, mock_path = self._make_mock_path_stream()
with mock.patch("mantidimaging.gui.windows.spectrum_viewer.SpectrumViewerWindowModel.save_roi_coords"):
with mock.patch.object(self.model, "save_roi_coords"):
self.model.save_csv(mock_path, False)

mock_path.open.assert_called_once_with("w")
Expand All @@ -194,7 +194,7 @@ def test_save_rits_dat(self):
self.model.set_normalise_stack(norm)

mock_stream, mock_path = self._make_mock_path_stream()
with mock.patch("mantidimaging.gui.windows.spectrum_viewer.SpectrumViewerWindowModel.save_roi_coords"):
with mock.patch.object(self.model, "save_roi_coords"):
self.model.save_rits(mock_path, True, ErrorMode.STANDARD_DEVIATION)

mock_path.open.assert_called_once_with("w")
Expand All @@ -212,7 +212,7 @@ def test_save_rits_roi_dat(self):
self.model.set_normalise_stack(norm)

mock_stream, mock_path = self._make_mock_path_stream()
with mock.patch("mantidimaging.gui.windows.spectrum_viewer.SpectrumViewerWindowModel.save_roi_coords"):
with mock.patch.object(self.model, "save_roi_coords"):
self.model.save_rits(mock_path, True, ErrorMode.STANDARD_DEVIATION)

mock_path.open.assert_called_once_with("w")
Expand Down Expand Up @@ -249,7 +249,7 @@ def test_invalid_error_mode_rits(self):
self.model.set_normalise_stack(norm)

mock_stream, mock_path = self._make_mock_path_stream()
with mock.patch("mantidimaging.gui.windows.spectrum_viewer.SpectrumViewerWindowModel.save_roi_coords"):
with mock.patch.object(self.model, "save_roi_coords"):
self.assertRaises(ValueError, self.model.save_rits, mock_path, True, None)
mock_path.open.assert_not_called()

Expand All @@ -261,7 +261,7 @@ def test_save_rits_no_norm_err(self):
stack.log_file = mock_inst_log

mock_stream, mock_path = self._make_mock_path_stream()
with mock.patch("mantidimaging.gui.windows.spectrum_viewer.SpectrumViewerWindowModel.save_roi_coords"):
with mock.patch.object(self.model, "save_roi_coords"):
self.assertRaises(ValueError, self.model.save_rits, mock_path, False, ErrorMode.STANDARD_DEVIATION)
mock_path.open.assert_not_called()

Expand All @@ -273,7 +273,7 @@ def test_save_rits_no_tof_err(self):
self.model.set_normalise_stack(norm)

mock_stream, mock_path = self._make_mock_path_stream()
with mock.patch("mantidimaging.gui.windows.spectrum_viewer.SpectrumViewerWindowModel.save_roi_coords"):
with mock.patch.object(self.model, "save_roi_coords"):
self.assertRaises(ValueError, self.model.save_rits, mock_path, True, ErrorMode.STANDARD_DEVIATION)
mock_path.open.assert_not_called()

Expand Down Expand Up @@ -302,7 +302,7 @@ def test_save_csv_norm(self):
self.model.set_normalise_stack(open_stack)

mock_stream, mock_path = self._make_mock_path_stream()
with mock.patch("mantidimaging.gui.windows.spectrum_viewer.SpectrumViewerWindowModel.save_roi_coords"):
with mock.patch.object(self.model, "save_roi_coords"):
self.model.save_csv(mock_path, True)

mock_path.open.assert_called_once_with("w")
Expand Down

0 comments on commit d623014

Please sign in to comment.