예제 #1
0
    def test_get_name(self):
        ws = MockWorkspace()
        expected_name = "TEST_WORKSPACE"
        ws.name = Mock(return_value=expected_name)
        model = TableWorkspaceDisplayModel(ws)

        self.assertEqual(expected_name, model.get_name())
    def test_get_name(self):
        ws = MockWorkspace()
        expected_name = "TEST_WORKSPACE"
        ws.name = Mock(return_value=expected_name)
        model = TableWorkspaceDisplayModel(ws)

        self.assertEqual(expected_name, model.get_name())
예제 #3
0
    def test_no_raise_with_supported_workspace(self):
        from mantid.simpleapi import CreateEmptyTableWorkspace
        ws = MockWorkspace()
        expected_name = "TEST_WORKSPACE"
        ws.name = Mock(return_value=expected_name)

        # no need to assert anything - if the constructor raises the test will fail
        TableWorkspaceDisplayModel(ws)

        ws = CreateEmptyTableWorkspace()
        TableWorkspaceDisplayModel(ws)
    def test_no_raise_with_supported_workspace(self):
        from mantid.simpleapi import CreateEmptyTableWorkspace
        ws = MockWorkspace()
        expected_name = "TEST_WORKSPACE"
        ws.name = Mock(return_value=expected_name)

        # no need to assert anything - if the constructor raises the test will fail
        TableWorkspaceDisplayModel(ws)

        ws = CreateEmptyTableWorkspace()
        TableWorkspaceDisplayModel(ws)
    def test_not_common_bins_horizontal_tooltip_role(self):
        mock_section = 0
        mock_return_values = [0, 1, 2, 3, 4, 5, 6]
        is_histogram_data = False

        ws = MockWorkspace(read_return=mock_return_values, isHistogramData=is_histogram_data)
        ws.isCommonBins = Mock(return_value=False)
        model_type = MatrixWorkspaceTableViewModelType.y
        model = MatrixWorkspaceTableViewModel(ws, model_type)
        output = model.headerData(mock_section, Qt.Horizontal, Qt.ToolTipRole)

        self.assertEqual(MatrixWorkspaceTableViewModel.HORIZONTAL_BINS_VARY_TOOLTIP_STRING.format(mock_section), output)
    def test_not_common_bins_horizontal_tooltip_role(self):
        mock_section = 0
        mock_return_values = [0, 1, 2, 3, 4, 5, 6]
        is_histogram_data = False

        ws = MockWorkspace(read_return=mock_return_values,
                           isHistogramData=is_histogram_data)
        ws.isCommonBins = Mock(return_value=False)
        model_type = MatrixWorkspaceTableViewModelType.y
        model = MatrixWorkspaceTableViewModel(ws, model_type)
        output = model.headerData(mock_section, Qt.Horizontal, Qt.ToolTipRole)

        self.assertEqual(
            MatrixWorkspaceTableViewModel.HORIZONTAL_BINS_VARY_TOOLTIP_STRING.
            format(mock_section), output)
 def test_row_and_column_count(self):
     ws = MockWorkspace()
     model_type = MatrixWorkspaceTableViewModelType.x
     MatrixWorkspaceTableViewModel(ws, model_type)
     # these are called when the TableViewModel is initialised
     ws.getNumberHistograms.assert_called_once_with()
     ws.blocksize.assert_called_once_with()
 def _check_correct_data_is_displayed(self, model_type, column, mock_data,
                                      row):
     ws = MockWorkspace(read_return=mock_data)
     model = MatrixWorkspaceTableViewModel(ws, model_type)
     index = MockQModelIndex(row, column)
     output = model.data(index, Qt.DisplayRole)
     model.relevant_data.assert_called_once_with(row)
     self.assertEqual(str(mock_data[column]), output)
 def test_headerData_horizontal_header_display_role_for_X_values(self):
     ws = MockWorkspace()
     model_type = MatrixWorkspaceTableViewModelType.x
     model = MatrixWorkspaceTableViewModel(ws, model_type)
     mock_section = 0
     output = model.headerData(mock_section, Qt.Horizontal, Qt.DisplayRole)
     expected_output = MatrixWorkspaceTableViewModel.HORIZONTAL_HEADER_DISPLAY_STRING_FOR_X_VALUES.format(
         mock_section)
     self.assertEqual(expected_output, output)
 def test_headerData_not_display_or_tooltip(self):
     if not qtpy.PYQT5:
         self.skipTest(
             "QVariant cannot be instantiated in QT4, and the test fails with an error."
         )
     ws = MockWorkspace()
     model_type = MatrixWorkspaceTableViewModelType.x
     model = MatrixWorkspaceTableViewModel(ws, model_type)
     output = model.headerData(0, Qt.Vertical, Qt.BackgroundRole)
     self.assertTrue(isinstance(output, QtCore.QVariant))
 def test_correct_relevant_data(self):
     ws = MockWorkspace()
     model = MatrixWorkspaceTableViewModel(
         ws, MatrixWorkspaceTableViewModelType.x)
     msg = "The function is not set correctly! The wrong data will be read."
     self.assertEqual(ws.readX, model.relevant_data, msg=msg)
     model = MatrixWorkspaceTableViewModel(
         ws, MatrixWorkspaceTableViewModelType.y)
     self.assertEqual(ws.readY, model.relevant_data, msg=msg)
     model = MatrixWorkspaceTableViewModel(
         ws, MatrixWorkspaceTableViewModelType.e)
     self.assertEqual(ws.readE, model.relevant_data, msg=msg)
    def test_correct_model_type(self):
        ws = MockWorkspace()
        model = MatrixWorkspaceTableViewModel(
            ws, MatrixWorkspaceTableViewModelType.x)
        self.assertEqual(model.type, MatrixWorkspaceTableViewModelType.x)

        model = MatrixWorkspaceTableViewModel(
            ws, MatrixWorkspaceTableViewModelType.y)
        self.assertEqual(model.type, MatrixWorkspaceTableViewModelType.y)

        model = MatrixWorkspaceTableViewModel(
            ws, MatrixWorkspaceTableViewModelType.e)
        self.assertEqual(model.type, MatrixWorkspaceTableViewModelType.e)
    def test_headerData_vertical_header_tooltip_role(self):
        ws = MockWorkspace()
        model_type = MatrixWorkspaceTableViewModelType.x
        model = MatrixWorkspaceTableViewModel(ws, model_type)
        mock_section = 0
        output = model.headerData(mock_section, Qt.Vertical, Qt.ToolTipRole)

        ws.getSpectrum.assert_called_once_with(mock_section)
        ws.mock_spectrum.getSpectrumNo.assert_called_once_with()

        expected_output = MatrixWorkspaceTableViewModel.VERTICAL_HEADER_TOOLTIP_STRING.format(
            mock_section, MockSpectrum.TEST_SPECTRUM_NO)
        self.assertEqual(expected_output, output)
    def test_action_copy_bin_values(self, mock_copy, mock_show_mouse_toast):
        ws = MockWorkspace()
        view = MockMatrixWorkspaceDisplayView()
        presenter = MatrixWorkspaceDisplay(ws, view=view)
        mock_table = MockQTableView()

        # two columns are selected at different positions
        mock_indexes = [MockQModelIndex(0, 0), MockQModelIndex(0, 3)]
        mock_table.mock_selection_model.selectedColumns = Mock(return_value=mock_indexes)
        # change the mock ws to have 3 histograms
        ws.getNumberHistograms = Mock(return_value=3)

        mock_read = Mock(return_value=[83, 11, 33, 70])
        presenter._get_ws_read_from_type = Mock(return_value=mock_read)
        expected_string = "83\t70\n83\t70\n83\t70"

        presenter.action_copy_bin_values(mock_table)

        mock_table.selectionModel.assert_called_once_with()
        mock_table.mock_selection_model.hasSelection.assert_called_once_with()
        mock_copy.assert_called_once_with(expected_string)
        mock_show_mouse_toast.assert_called_once_with(MatrixWorkspaceDisplay.COPY_SUCCESSFUL_MESSAGE)
    def test_headerData_vertical_header_display_role(self):
        ws = MockWorkspace()
        model_type = MatrixWorkspaceTableViewModelType.x
        model = MatrixWorkspaceTableViewModel(ws, model_type)
        mock_section = 0
        output = model.headerData(mock_section, Qt.Vertical, Qt.DisplayRole)

        ws.getAxis.assert_called_once_with(AXIS_INDEX_FOR_VERTICAL)
        ws.mock_axis.label.assert_called_once_with(mock_section)

        expected_output = MatrixWorkspaceTableViewModel.VERTICAL_HEADER_DISPLAY_STRING.format(
            mock_section, MockMantidAxis.TEST_LABEL)

        self.assertEqual(expected_output, output)
    def test_action_copy_bin_values(self, mock_copy, mock_show_mouse_toast):
        ws = MockWorkspace()
        view = MockMatrixWorkspaceDisplayView()
        presenter = MatrixWorkspaceDisplay(ws, view=view)
        mock_table = MockQTableView()

        # two columns are selected at different positions
        mock_indexes = [MockQModelIndex(0, 0), MockQModelIndex(0, 3)]
        mock_table.mock_selection_model.selectedColumns = Mock(
            return_value=mock_indexes)
        # change the mock ws to have 3 histograms
        ws.getNumberHistograms = Mock(return_value=3)

        mock_read = Mock(return_value=[83, 11, 33, 70])
        presenter._get_ws_read_from_type = Mock(return_value=mock_read)
        expected_string = "83\t70\n83\t70\n83\t70"

        presenter.action_copy_bin_values(mock_table)

        mock_table.selectionModel.assert_called_once_with()
        mock_table.mock_selection_model.hasSelection.assert_called_once_with()
        mock_copy.assert_called_once_with(expected_string)
        mock_show_mouse_toast.assert_called_once_with(
            MatrixWorkspaceDisplay.COPY_SUCCESSFUL_MESSAGE)
    def test_action_copy_cell_no_selection(self, mock_copy,
                                           mock_show_mouse_toast):
        ws = MockWorkspace()
        view = MockMatrixWorkspaceDisplayView()
        presenter = MatrixWorkspaceDisplay(ws, view=view)
        mock_table = MockQTableView()
        mock_table.mock_selection_model.hasSelection = Mock(return_value=False)

        presenter.action_copy_cells(mock_table)

        mock_table.selectionModel.assert_called_once_with()
        mock_table.mock_selection_model.hasSelection.assert_called_once_with()
        mock_show_mouse_toast.assert_called_once_with(
            MatrixWorkspaceDisplay.NO_SELECTION_MESSAGE)

        self.assertNotCalled(mock_copy)
    def common_setup_action_plot(self, table_has_selection=True):
        mock_ws = MockWorkspace()
        mock_view = MockMatrixWorkspaceDisplayView()
        mock_plotter = Mock()
        presenter = MatrixWorkspaceDisplay(mock_ws,
                                           plot=mock_plotter,
                                           view=mock_view)

        # monkey-patch the spectrum plot label to count the number of calls
        presenter.model.get_spectrum_plot_label = Mock()
        presenter.model.get_bin_plot_label = Mock()

        mock_table = MockQTableView()
        # configure the mock return values
        mock_table.mock_selection_model.hasSelection = Mock(
            return_value=table_has_selection)
        return mock_plotter, mock_table, mock_view, presenter
    def test_action_copy_cell(self, mock_copy, mock_show_mouse_toast):
        ws = MockWorkspace()
        view = MockMatrixWorkspaceDisplayView()
        presenter = MatrixWorkspaceDisplay(ws, view=view)
        mock_table = MockQTableView()

        # two columns are selected at different positions
        mock_index = MockQModelIndex(None, None)
        mock_table.mock_selection_model.currentIndex = Mock(
            return_value=mock_index)

        presenter.action_copy_cells(mock_table)

        mock_table.selectionModel.assert_called_once_with()
        self.assertEqual(1, mock_copy.call_count)
        self.assertEqual(9, mock_index.sibling.call_count)
        mock_show_mouse_toast.assert_called_once_with(
            MatrixWorkspaceDisplay.COPY_SUCCESSFUL_MESSAGE)
    def test_action_copy_spectrum_values_no_selection(self, mock_copy,
                                                      mock_show_mouse_toast):
        ws = MockWorkspace()
        view = MockMatrixWorkspaceDisplayView()
        presenter = MatrixWorkspaceDisplay(ws, view=view)

        mock_table = MockQTableView()
        mock_table.mock_selection_model.hasSelection = Mock(return_value=False)
        mock_table.mock_selection_model.selectedRows = Mock()

        presenter.action_copy_spectrum_values(mock_table)

        mock_table.selectionModel.assert_called_once_with()
        mock_table.mock_selection_model.hasSelection.assert_called_once_with()
        # the action should never look for rows if there is no selection
        self.assertNotCalled(mock_table.mock_selection_model.selectedRows)
        self.assertNotCalled(mock_copy)
        mock_show_mouse_toast.assert_called_once_with(
            MatrixWorkspaceDisplay.NO_SELECTION_MESSAGE)
    def _run_test_headerData_horizontal_header_display_role(
            self, is_histogram_data, mock_return_values, mock_section,
            expected_bin_centre):
        ws = MockWorkspace(read_return=mock_return_values,
                           isHistogramData=is_histogram_data)
        model_type = MatrixWorkspaceTableViewModelType.y
        model = MatrixWorkspaceTableViewModel(ws, model_type)
        output = model.headerData(mock_section, Qt.Horizontal, Qt.DisplayRole)

        ws.isHistogramData.assert_called_once_with()
        ws.readX.assert_called_once_with(0)
        ws.getAxis.assert_called_once_with(AXIS_INDEX_FOR_HORIZONTAL)
        ws.mock_axis.getUnit.assert_called_once_with()
        ws.mock_axis.mock_unit.symbol.assert_called_once_with()
        ws.mock_axis.mock_unit.mock_symbol.utf8.assert_called_once_with()
        expected_output = MatrixWorkspaceTableViewModel \
            .HORIZONTAL_HEADER_DISPLAY_STRING \
            .format(mock_section, expected_bin_centre, MockMantidSymbol.TEST_UTF8)
        self.assertEqual(expected_output, output)
    def test_action_copy_spectrum_values(self, mock_copy,
                                         mock_show_mouse_toast):
        ws = MockWorkspace()
        view = MockMatrixWorkspaceDisplayView()
        presenter = MatrixWorkspaceDisplay(ws, view=view)

        mock_table = MockQTableView()

        # two rows are selected in different positions
        mock_indexes = [MockQModelIndex(0, 1), MockQModelIndex(3, 1)]
        mock_table.mock_selection_model.selectedRows = Mock(
            return_value=mock_indexes)

        mock_read = Mock(return_value=[43, 99])
        presenter._get_ws_read_from_type = Mock(return_value=mock_read)
        expected_string = "43\t99\n43\t99"

        presenter.action_copy_spectrum_values(mock_table)

        mock_table.selectionModel.assert_called_once_with()
        mock_table.mock_selection_model.hasSelection.assert_called_once_with()
        mock_copy.assert_called_once_with(expected_string)
        mock_show_mouse_toast.assert_called_once_with(
            MatrixWorkspaceDisplay.COPY_SUCCESSFUL_MESSAGE)
예제 #23
0
 def wrapper(self):
     ws = MockWorkspace()
     model = TableWorkspaceDisplayModel(ws)
     return func(self, model)
 def test_setup_table(self):
     ws = MockWorkspace()
     view = MockMatrixWorkspaceDisplayView()
     MatrixWorkspaceDisplay(ws, view=view)
     self.assertEqual(3, view.set_context_menu_actions.call_count)
     self.assertEqual(1, view.set_model.call_count)
 def test_correct_cell_colors(self):
     ws = MockWorkspace()
     model = MatrixWorkspaceTableViewModel(
         ws, MatrixWorkspaceTableViewModelType.x)
     self.assertEqual((240, 240, 240, 255), model.masked_color.getRgb())
     self.assertEqual((255, 253, 209, 255), model.monitor_color.getRgb())
 def test_invalid_model_type(self):
     ws = MockWorkspace()
     with self.assertRaises(AssertionError):
         MatrixWorkspaceTableViewModel(ws, "My Model Type")