示例#1
0
    def test_color_returns_string_identifier_given_to_model(self):
        fg_color, bg_color = 'b', '0.5'
        model = PeaksViewerModel(create_autospec(PeaksWorkspace), fg_color,
                                 bg_color)

        self.assertEqual(fg_color, model.fg_color)
        self.assertEqual(bg_color, model.bg_color)
示例#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
示例#3
0
    def test_peaks_workspace_add_peak(self):
        peaks_workspace = create_autospec(PeaksWorkspace)
        model = PeaksViewerModel(peaks_workspace, 'b', '1.0')

        model.add_peak([1, 1, 1], SpecialCoordinateSystem.QLab)
        peaks_workspace.addPeak.assert_called_with([1, 1, 1], SpecialCoordinateSystem.QLab)
        model.add_peak([2, 2, 2], SpecialCoordinateSystem.QSample)
        peaks_workspace.addPeak.assert_called_with([2, 2, 2], SpecialCoordinateSystem.QSample)
        model.add_peak([3, 3, 3], SpecialCoordinateSystem.HKL)
        peaks_workspace.addPeak.assert_called_with([3, 3, 3], SpecialCoordinateSystem.HKL)
示例#4
0
def create_peaks_viewer_model(centers, fg_color, name=None):
    peaks = [create_mock_peak(center) for center in centers]

    def get_peak(index):
        return peaks[index]

    model = PeaksViewerModel(create_autospec(PeaksWorkspace), fg_color, 'unused')
    if name is not None:
        model.ws.name.return_value = name
    model.ws.__iter__.return_value = peaks
    model.ws.getPeak.side_effect = get_peak
    return model
示例#5
0
def create_peaks_viewer_model(centers, fg_color, name=None):
    peaks = [create_mock_peak(center) for center in centers]

    def get_peak(index):
        return peaks[index]

    def column(name: str):
        if name in ('QLab', 'QSample'):
            return centers

    def remove_peak(peak_number: int):
        return peak_number

    model = PeaksViewerModel(create_autospec(PeaksWorkspace), fg_color, 'unused')
    if name is not None:
        model.ws.name.return_value = name
    model.ws.__iter__.return_value = peaks
    model.ws.getPeak.side_effect = get_peak
    model.ws.column.side_effect = column
    model.ws.removePeak.side_effect = remove_peak

    return model
示例#6
0
    def test_peaks_workspace_returns_same_workspace_given_to_model(self):
        peaks_workspace = create_autospec(PeaksWorkspace)
        model = PeaksViewerModel(peaks_workspace, 'b', '1.0')

        self.assertEqual(peaks_workspace, model.peaks_workspace)