def test_presenter_subscribes_to_view_updates(self, _):
        mock_view = MagicMock()

        presenter = PeaksViewerPresenter(create_peaks_viewer_model([], 'r'),
                                         mock_view)

        mock_view.subscribe.assert_called_once_with(presenter)
Example #2
0
    def test_sort_by_value_not_string(self):
        npeaks = 5
        peaks_ws = WorkspaceCreationHelper.createPeaksWorkspace(npeaks)
        view = PeaksViewerView(None, None)
        model = PeaksViewerModel(peaks_ws, fg_color='r', bg_color='w')
        presenter = PeaksViewerPresenter(model, view)
        table_view = view.table_view
        table_model = table_view.model()

        # Very difficult to simulate mouse click to sort - trust Qt to do that
        # We are more interested that the sort is based on value no a string comparison
        # check a few columns
        for column_index in (7, 16):  # tof & qlab
            table_model.sort(column_index, Qt.DescendingOrder)

            self.assertEqual(npeaks, view.table_view.rowCount())
            # assert sort has happened
            col_values = [
                table_model.index(i, column_index).data(
                    PeaksWorkspaceDataPresenter.DATA_SORT_ROLE)
                for i in range(npeaks)
            ]
            self.assertTrue(
                all(col_values[i + 1] < col_values[i]
                    for i in range(npeaks - 1)),
                msg="TOF values have not been sorted into descending order")

        view.close()
        del presenter
 def test_add_delete_peaks(self, mock_peaks_list_presenter):
     name = 'ws1'
     mock_model = create_mock_model(name)
     self.mock_view.frame = 'Frame'
     presenter = PeaksViewerPresenter(mock_model, self.mock_view)
     presenter.add_peak([1, 2, 3])
     mock_model.add_peak.assert_called_once_with([1, 2, 3], 'Frame')
     presenter.delete_peak([1, 2, 3])
     mock_model.delete_peak.assert_called_once_with([1, 2, 3], 'Frame')
Example #4
0
    def test_single_peak_selection(self, mock_peaks_list_presenter):
        mock_view = MagicMock()
        name = 'ws1'
        mock_model = create_mock_model(name)
        mock_view.selected_index = 0
        presenter = PeaksViewerPresenter(mock_model, mock_view)

        presenter.notify(PeaksViewerPresenter.Event.PeakSelected)

        mock_model.zoom_to.assert_called_once_with(0)
    def test_view_populated_on_presenter_construction(self, mock_peaks_list_presenter):
        name = "ws1"
        fg_color = "r"
        test_model = create_peaks_viewer_model([(1, 2, 3)], fg_color=fg_color, name=name)

        PeaksViewerPresenter(test_model, self.mock_view)

        self.mock_view.set_title.assert_called_once_with(name)
        self.mock_view.set_peak_color.assert_called_once_with(fg_color)
        # peaks list presenter construction
        mock_peaks_list_presenter.assert_called_once_with(ANY, self.mock_view.table_view)
        self.mock_view.table_view.enable_sorting.assert_called_once()
    def test_single_peak_selection(self, mock_peaks_list_presenter):
        name = 'ws1'
        mock_model = create_mock_model(name)
        viewlimits = (-1, 1), (-2, 2)
        mock_model.viewlimits.return_value = viewlimits
        self.mock_view.selected_index = 0
        presenter = PeaksViewerPresenter(mock_model, self.mock_view)

        presenter.notify(PeaksViewerPresenter.Event.PeakSelected)

        mock_model.viewlimits.assert_called_once_with(0)
        self.mock_view.set_axes_limits.assert_called_once_with(*viewlimits, auto_transform=False)
Example #7
0
    def test_single_peak_selection_if_peaks_not_drawn(
            self, mock_peaks_list_presenter):
        # peaks not drawn if one fo viewing axes non-Q
        name = 'ws1'
        mock_model = create_mock_model(name)
        mock_model.has_representations_drawn.return_value = False
        self.mock_view.selected_index = 0
        presenter = PeaksViewerPresenter(mock_model, self.mock_view)

        presenter.notify(PeaksViewerPresenter.Event.PeakSelected)

        mock_model.viewlimits.assert_not_called()
        self.mock_view.set_axes_limits.assert_not_called()
Example #8
0
    def test_clear_removes_painted_peaks(self, mock_peaks_list_presenter):
        centers = ((1, 2, 3), (4, 5, 3.01))
        slice_info = create_slice_info(centers, slice_value=3, slice_width=5)
        test_model = create_peaks_viewer_model(centers, fg_color="r")
        painter = MagicMock()
        test_model.draw_peaks(slice_info, painter)
        mock_view = MagicMock()
        mock_view.painter = painter
        presenter = PeaksViewerPresenter(test_model, mock_view)

        presenter.notify(PeaksViewerPresenter.Event.ClearPeaks)

        self.assertEqual(2, mock_view.painter.remove.call_count)
    def test_clear_removes_painted_peaks(self, mock_peaks_list_presenter):
        centers = ((1, 2, 3), (4, 5, 3.01))
        slice_info = create_slice_info(centers, slice_value=3, slice_width=5)
        test_model = create_peaks_viewer_model(centers, fg_color="r")
        painter, axes = MagicMock(), MagicMock()
        axes.get_xlim.return_value = (-1, 1)
        painter.axes = axes
        test_model.draw_peaks(slice_info, painter, SpecialCoordinateSystem.QSample)
        self.mock_view.painter = painter
        presenter = PeaksViewerPresenter(test_model, self.mock_view)

        presenter.notify(PeaksViewerPresenter.Event.ClearPeaks)

        self.assertEqual(2, self.mock_view.painter.remove.call_count)
    def test_slice_point_changed_clears_old_peaks_and_overlays_visible(
            self, mock_peaks_list_presenter):
        centers = ((1, 2, 3), (4, 5, 3.01))
        slice_info = create_slice_info(centers, slice_value=3, slice_width=5)
        test_model = create_peaks_viewer_model(centers, fg_color="r")
        # draw some peaks first so we can test clearing them
        painter, axes = MagicMock(), MagicMock()
        axes.get_xlim.return_value = (-1, 1)
        painter.axes = axes

        test_model.draw_peaks(slice_info, painter, SpecialCoordinateSystem.QSample)
        # clear draw calls
        painter.cross.reset_mock()
        self.mock_view.painter = painter
        self.mock_view.sliceinfo = create_slice_info(centers, slice_value=3, slice_width=5)
        presenter = PeaksViewerPresenter(test_model, self.mock_view)

        presenter.notify(PeaksViewerPresenter.Event.SlicePointChanged)

        self.assertEqual(2, self.mock_view.painter.remove.call_count)
        self.assertEqual(2, self.mock_view.painter.cross.call_count)
Example #11
0
    def test_slice_point_changed_clears_old_peaks_and_overlays_visible(
            self, mock_peaks_list_presenter):
        centers = ((1, 2, 3), (4, 5, 3.01))
        slice_info = create_slice_info(centers, slice_value=3, slice_width=5)
        test_model = create_peaks_viewer_model(centers, fg_color="r")
        # draw some peaks first so we can test clearing them
        painter = MagicMock()
        test_model.draw_peaks(slice_info, painter)
        # clear draw calls
        painter.cross.reset_mock()
        mock_view = MagicMock()
        mock_view.painter = painter
        mock_view.sliceinfo = create_slice_info(centers,
                                                slice_value=3,
                                                slice_width=5)
        presenter = PeaksViewerPresenter(test_model, mock_view)

        presenter.notify(PeaksViewerPresenter.Event.SlicePointChanged)

        self.assertEqual(2, mock_view.painter.remove.call_count)
        self.assertEqual(2, mock_view.painter.cross.call_count)