Exemple #1
0
    def test_remove_removes_named_workspace(self, mock_create_model):
        names = ["peaks1", 'peaks2', 'peaks3']
        presenter = PeaksViewerCollectionPresenter(MagicMock())
        for name in names:
            presenter.append_peaksworkspace(name)

        presenter.remove_peaksworkspace(names[1])

        self.assertEqual([names[0], names[2]], presenter.workspace_names())
Exemple #2
0
    def test_append_constructs_PeaksViewerPresenter_for_call(self, mock_create_model):
        # mock 2 models with the correct names and assume  create_peaksviewermodel makes them
        names = ["peaks1", 'peaks2']
        presenter = PeaksViewerCollectionPresenter(MagicMock())

        for name in names:
            presenter.append_peaksworkspace(name)

        self.assertEqual(names, presenter.workspace_names())
Exemple #3
0
    def test_hides_view_when_last_named_workspace_removed(
            self, mock_create_model):
        names = ["peaks1"]
        presenter = PeaksViewerCollectionPresenter(MagicMock())
        presenter.append_peaksworkspace(names[0])

        presenter.remove_peaksworkspace(names[0])

        presenter._actions_view.set_peaksworkspace.assert_called_with([])
        presenter._view.hide.assert_called()
Exemple #4
0
    def test_append_uses_unused_fg_color(self, mock_create_model):
        names = ["peaks1", 'peaks2']
        # setup with 1 workspace
        presenter = PeaksViewerCollectionPresenter(MagicMock())
        presenter.append_peaksworkspace(names[0])

        mock_create_model.assert_called_once_with(
            names[0], PeaksViewerCollectionPresenter.FG_COLORS[0],
            PeaksViewerCollectionPresenter.DEFAULT_BG_COLOR)
        mock_create_model.reset_mock()
        presenter.append_peaksworkspace(names[1])
        mock_create_model.assert_called_once_with(
            names[1], PeaksViewerCollectionPresenter.FG_COLORS[1],
            PeaksViewerCollectionPresenter.DEFAULT_BG_COLOR)
    def test_append_constructs_PeaksViewerPresenter(self,
                                                    mock_single_presenter):
        peaks_workspace = PeaksViewerModel(create_mock_peaks_workspace(), 'r',
                                           'b')
        mock_collection_view = MagicMock()
        mock_peaks_view = MagicMock()
        mock_collection_view.append_peaksviewer.return_value = mock_peaks_view

        presenter = PeaksViewerCollectionPresenter(mock_collection_view)
        presenter.append_peaksworkspace(peaks_workspace)

        mock_single_presenter.assert_has_calls(
            [call(peaks_workspace, mock_peaks_view)])
        self.assertEqual(1, presenter.view.append_peaksviewer.call_count)
Exemple #6
0
    def test_notify_called_for_each_subpresenter(self, mock_create_model):
        presenter = PeaksViewerCollectionPresenter(MagicMock())

        with patch("mantidqt.widgets.sliceviewer.peaksviewer.presenter.PeaksViewerPresenter"
                   ) as presenter_mock:
            presenter_mock.side_effect = [MagicMock(), MagicMock()]
            child_presenters = [presenter.append_peaksworkspace(f'peaks_{i}') for i in range(2)]
            presenter.notify(PeaksViewerPresenter.Event.OverlayPeaks)
            for child in child_presenters:
                child.notify.assert_called_once_with(PeaksViewerPresenter.Event.OverlayPeaks)
    def _create_collection_presenter(self, models, single_presenter_mock):
        view = MagicMock()
        # make each call to to mock_presenter return a new mock object with
        # the appropriate return_value for the model
        side_effects = []
        for model in models:
            mock = MagicMock()
            mock.model.return_value = model
            side_effects.append(mock)
        single_presenter_mock.side_effect = side_effects
        presenter = PeaksViewerCollectionPresenter(view)
        child_presenters = []
        for peaks_ws in models:
            child_presenters.append(presenter.append_peaksworkspace(peaks_ws))

        return presenter, child_presenters