Esempio n. 1
0
 def test_is_editable_column(self):
     ws = MockWorkspace()
     model = TableWorkspaceDisplayModel(ws)
     ws.isColumnReadOnly = StrictMock(return_value=False)
     self.assertTrue(model.is_editable_column(0))
     ws.isColumnReadOnly = StrictMock(return_value=True)
     self.assertFalse(model.is_editable_column(0))
    def test_initialise_marked_columns_multiple_y_before_yerr(self):
        ws = MockWorkspace()
        # add 5 columns as that is how many the default mock WS has
        mock_column_types = [
            TableWorkspaceColumnTypeMapping.X,
            TableWorkspaceColumnTypeMapping.Y,
            TableWorkspaceColumnTypeMapping.YERR,
            TableWorkspaceColumnTypeMapping.Y,
            TableWorkspaceColumnTypeMapping.Y,
            TableWorkspaceColumnTypeMapping.YERR,
            TableWorkspaceColumnTypeMapping.YERR,
            TableWorkspaceColumnTypeMapping.X
        ]
        ws.columnCount = StrictMock(return_value=len(mock_column_types))

        ws.getPlotType = lambda i: mock_column_types[i]
        model = TableWorkspaceDisplayModel(ws)

        self.assertEqual(2, len(model.marked_columns.as_x))
        self.assertEqual(3, len(model.marked_columns.as_y))
        # no YErr is added because the Y column hasn't been added yet,
        # and there isn't anything to associate the error with
        self.assertEqual(3, len(model.marked_columns.as_y_err))

        self.assertEqual(1, model.marked_columns.as_y_err[0].related_y_column)
        # the YErr associates with the FIRST Y column that doesn't have a Y Err
        self.assertEqual(3, model.marked_columns.as_y_err[1].related_y_column)
        self.assertEqual(4, model.marked_columns.as_y_err[2].related_y_column)
Esempio n. 3
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())
Esempio n. 5
0
    def test_initialise_marked_columns_one_of_each_type(self):
        num_of_repeated_columns = 10
        ws = MockWorkspace()
        # multiply by 3 to have 1 of each type
        ws.columnCount = StrictMock(return_value=num_of_repeated_columns * 3)
        # make 10 columns of each type
        mock_column_types = [
            TableWorkspaceColumnTypeMapping.X,
            TableWorkspaceColumnTypeMapping.Y,
            TableWorkspaceColumnTypeMapping.YERR
        ] * num_of_repeated_columns
        ws.getPlotType = lambda i: mock_column_types[i]
        ws.getLinkedYCol = lambda i: i - 1
        model = TableWorkspaceDisplayModel(ws)

        self.assertEqual(num_of_repeated_columns,
                         len(model.marked_columns.as_x))
        self.assertEqual(num_of_repeated_columns,
                         len(model.marked_columns.as_y))
        self.assertEqual(num_of_repeated_columns,
                         len(model.marked_columns.as_y_err))

        for i, col in enumerate(range(2, 30, 3)):
            self.assertEqual(col - 1,
                             model.marked_columns.as_y_err[i].related_y_column)
Esempio n. 6
0
    def test_initialise_marked_columns_multiple_y_before_yerr(self):
        ws = MockWorkspace()
        # add 5 columns as that is how many the default mock WS has
        mock_column_types = [
            TableWorkspaceColumnTypeMapping.X,
            TableWorkspaceColumnTypeMapping.Y,
            TableWorkspaceColumnTypeMapping.YERR,
            TableWorkspaceColumnTypeMapping.Y,
            TableWorkspaceColumnTypeMapping.Y,
            TableWorkspaceColumnTypeMapping.YERR,
            TableWorkspaceColumnTypeMapping.YERR,
            TableWorkspaceColumnTypeMapping.X
        ]
        ws.columnCount = StrictMock(return_value=len(mock_column_types))

        ws.getPlotType = lambda i: mock_column_types[i]
        ws.getLinkedYCol = StrictMock(side_effect=[1, 3, 4])
        model = TableWorkspaceDisplayModel(ws)

        self.assertEqual(2, len(model.marked_columns.as_x))
        self.assertEqual(3, len(model.marked_columns.as_y))
        self.assertEqual(3, len(model.marked_columns.as_y_err))

        self.assertEqual(1, model.marked_columns.as_y_err[0].related_y_column)
        self.assertEqual(3, model.marked_columns.as_y_err[1].related_y_column)
        self.assertEqual(4, model.marked_columns.as_y_err[2].related_y_column)
    def test_no_raise_with_supported_workspace(self):
        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
        MatrixWorkspaceDisplayModel(ws)

        ws = CreateSampleWorkspace(NumBanks=1, BankPixelWidth=4, NumEvents=10)
        MatrixWorkspaceDisplayModel(ws)
    def test_no_raise_with_supported_workspace(self):
        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
        MatrixWorkspaceDisplayModel(ws)

        ws = CreateSampleWorkspace(NumBanks=1, BankPixelWidth=4, NumEvents=10)
        MatrixWorkspaceDisplayModel(ws)
    def test_get_item_model(self):
        ws = MockWorkspace()
        expected_name = "TEST_WORKSPACE"
        ws.name = Mock(return_value=expected_name)
        model = MatrixWorkspaceDisplayModel(ws)

        x_model, y_model, e_model = model.get_item_model()

        self.assertEqual(x_model.type, MatrixWorkspaceTableViewModelType.x)
        self.assertEqual(y_model.type, MatrixWorkspaceTableViewModelType.y)
        self.assertEqual(e_model.type, MatrixWorkspaceTableViewModelType.e)
Esempio n. 10
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_get_item_model(self):
        ws = MockWorkspace()
        expected_name = "TEST_WORKSPACE"
        ws.name = Mock(return_value=expected_name)
        model = MatrixWorkspaceDisplayModel(ws)

        x_model, y_model, e_model = model.get_item_model()

        self.assertEqual(x_model.type, MatrixWorkspaceTableViewModelType.x)
        self.assertEqual(y_model.type, MatrixWorkspaceTableViewModelType.y)
        self.assertEqual(e_model.type, MatrixWorkspaceTableViewModelType.e)
    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 _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_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 test_initialise_marked_columns_one_of_each_type(self):
        num_of_repeated_columns = 10
        ws = MockWorkspace()
        # multiply by 3 to have 1 of each type
        ws.columnCount = StrictMock(return_value=num_of_repeated_columns * 3)
        # make 10 columns of each type
        mock_column_types = [TableWorkspaceColumnTypeMapping.X, TableWorkspaceColumnTypeMapping.Y,
                             TableWorkspaceColumnTypeMapping.YERR] * num_of_repeated_columns
        ws.getPlotType = lambda i: mock_column_types[i]
        model = TableWorkspaceDisplayModel(ws)

        self.assertEqual(num_of_repeated_columns, len(model.marked_columns.as_x))
        self.assertEqual(num_of_repeated_columns, len(model.marked_columns.as_y))
        self.assertEqual(num_of_repeated_columns, len(model.marked_columns.as_y_err))

        for i, col in enumerate(range(2, 30, 3)):
            self.assertEqual(col - 1, model.marked_columns.as_y_err[i].related_y_column)
Esempio n. 18
0
 def test_setup_table(self):
     ws = MockWorkspace()
     view = MockMatrixWorkspaceDisplayView()
     container = Mock(spec=StatusBarView)
     container.status_bar = Mock(spec=QStatusBar)
     MatrixWorkspaceDisplay(ws, view=view, container=container)
     self.assertEqual(4, view.set_context_menu_actions.call_count)
     self.assertEqual(1, view.set_model.call_count)
Esempio n. 19
0
 def wrapper(self, *args):
     ws = MockWorkspace()
     view = MockMatrixWorkspaceDisplayView()
     mock_observer = Mock()
     container = Mock(spec=StatusBarView)
     container.status_bar = Mock(spec=QStatusBar)
     presenter = MatrixWorkspaceDisplay(ws, view=view, ads_observer=mock_observer, container=container)
     return func(self, ws, view, presenter, *args)
 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)
Esempio n. 22
0
 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_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_initialise_marked_columns_yerr_before_y_doesnt_mark_yerr(self):
        """
        Test if there are column marking such as [X, Y, YERR, X, YERR, Y]
                                                                   ^ this YErr
        won't be associated with any Y column, as there isn't one at the time of adding the YErr column
        :return:
        """
        ws = MockWorkspace()
        # add 5 columns as that is how many the default mock WS has
        mock_column_types = [TableWorkspaceColumnTypeMapping.X, TableWorkspaceColumnTypeMapping.YERR,
                             TableWorkspaceColumnTypeMapping.Y, TableWorkspaceColumnTypeMapping.X,
                             TableWorkspaceColumnTypeMapping.Y]
        ws.getPlotType = lambda i: mock_column_types[i]
        model = TableWorkspaceDisplayModel(ws)

        self.assertEqual(2, len(model.marked_columns.as_x))
        self.assertEqual(2, len(model.marked_columns.as_y))
        # no YErr is added because the Y column hasn't been added yet,
        # and there isn't anything to associate the error with
        self.assertEqual(0, len(model.marked_columns.as_y_err))
Esempio n. 25
0
    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.SPECTRUM_NO)
        self.assertEqual(expected_output, output)
    def test_initialise_marked_columns_multiple_y_before_yerr(self):
        ws = MockWorkspace()
        # add 5 columns as that is how many the default mock WS has
        mock_column_types = [TableWorkspaceColumnTypeMapping.X, TableWorkspaceColumnTypeMapping.Y,
                             TableWorkspaceColumnTypeMapping.YERR, TableWorkspaceColumnTypeMapping.Y,
                             TableWorkspaceColumnTypeMapping.Y, TableWorkspaceColumnTypeMapping.YERR,
                             TableWorkspaceColumnTypeMapping.YERR, TableWorkspaceColumnTypeMapping.X]
        ws.columnCount = StrictMock(return_value=len(mock_column_types))

        ws.getPlotType = lambda i: mock_column_types[i]
        model = TableWorkspaceDisplayModel(ws)

        self.assertEqual(2, len(model.marked_columns.as_x))
        self.assertEqual(3, len(model.marked_columns.as_y))
        # no YErr is added because the Y column hasn't been added yet,
        # and there isn't anything to associate the error with
        self.assertEqual(3, len(model.marked_columns.as_y_err))

        self.assertEqual(1, model.marked_columns.as_y_err[0].related_y_column)
        # the YErr associates with the FIRST Y column that doesn't have a Y Err
        self.assertEqual(3, model.marked_columns.as_y_err[1].related_y_column)
        self.assertEqual(4, model.marked_columns.as_y_err[2].related_y_column)
Esempio n. 27
0
def setup_common_for_test_data():
    """
    Common configuration of variables and mocking for testing
    MatrixWorkspaceDisplayTableViewModel's data and headerData functions
    """
    # Create some mock data for the mock workspace
    row = 2
    column = 2
    # make a workspace with 0s
    mock_data = [0] * 10
    # set one of them to be not 0
    mock_data[column] = 999
    model_type = MatrixWorkspaceTableViewModelType.x
    # pass onto the MockWorkspace so that it returns it when read from the TableViewModel
    ws = MockWorkspace(read_return=mock_data)
    ws.hasMaskedBins = Mock(return_value=True)
    ws.maskedBinsIndices = Mock(return_value=[column])
    model = MatrixWorkspaceTableViewModel(ws, model_type)
    # The model retrieves the spectrumInfo object, and our MockWorkspace has already given it
    # the MockSpectrumInfo, so all that needs to be done here is to set up the correct method Mocks
    model.ws_spectrum_info.hasDetectors = Mock(return_value=True)
    index = MockQModelIndex(row, column)
    return ws, model, row, index
def setup_common_for_test_data():
    """
    Common configuration of variables and mocking for testing
    MatrixWorkspaceDisplayTableViewModel's data and headerData functions
    """
    # Create some mock data for the mock workspace
    row = 2
    column = 2
    # make a workspace with 0s
    mock_data = [0] * 10
    # set one of them to be not 0
    mock_data[column] = 999
    model_type = MatrixWorkspaceTableViewModelType.x
    # pass onto the MockWorkspace so that it returns it when read from the TableViewModel
    ws = MockWorkspace(read_return=mock_data)
    ws.hasMaskedBins = Mock(return_value=True)
    ws.maskedBinsIndices = Mock(return_value=[column])
    model = MatrixWorkspaceTableViewModel(ws, model_type)
    # The model retrieves the spectrumInfo object, and our MockWorkspace has already given it
    # the MockSpectrumInfo, so all that needs to be done here is to set up the correct method Mocks
    model.ws_spectrum_info.hasDetectors = Mock(return_value=True)
    index = MockQModelIndex(row, column)
    return ws, model, row, index
Esempio n. 29
0
    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_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_initialise_marked_columns_yerr_before_y_doesnt_mark_yerr(self):
        """
        Test if there are column marking such as [X, Y, YERR, X, YERR, Y]
                                                                   ^ this YErr
        won't be associated with any Y column, as there isn't one at the time of adding the YErr column
        :return:
        """
        ws = MockWorkspace()
        # add 5 columns as that is how many the default mock WS has
        mock_column_types = [
            TableWorkspaceColumnTypeMapping.X,
            TableWorkspaceColumnTypeMapping.YERR,
            TableWorkspaceColumnTypeMapping.Y,
            TableWorkspaceColumnTypeMapping.X,
            TableWorkspaceColumnTypeMapping.Y
        ]
        ws.getPlotType = lambda i: mock_column_types[i]
        model = TableWorkspaceDisplayModel(ws)

        self.assertEqual(2, len(model.marked_columns.as_x))
        self.assertEqual(2, len(model.marked_columns.as_y))
        # no YErr is added because the Y column hasn't been added yet,
        # and there isn't anything to associate the error with
        self.assertEqual(0, len(model.marked_columns.as_y_err))
 def wrapper(self, *args):
     ws = MockWorkspace()
     ws.setPlotType = Mock()
     view = Mock(spec=TableWorkspaceDisplayView)
     container = Mock(spec=StatusBarView)
     container.status_bar = Mock(spec=QStatusBar)
     if add_selection_model:
         mock_selection_model = MockQSelectionModel(has_selection=True)
         mock_selection_model.selectedRows = Mock(return_value=[
             MockQModelIndex(1, 1),
             MockQModelIndex(2, 2),
             MockQModelIndex(3, 3)
         ])
         mock_selection_model.selectedColumns = Mock(return_value=[
             MockQModelIndex(1, 1),
             MockQModelIndex(2, 2),
             MockQModelIndex(3, 3)
         ])
         view.mock_selection_model = mock_selection_model
         view.selectionModel.return_value = mock_selection_model
     twd = TableWorkspaceDisplay(ws, view=view, container=container)
     if add_plot:
         twd.plot = MockPlotLib()
     return func(self, ws, view, twd, *args)
Esempio n. 32
0
    def common_setup_action_plot(self, table_has_selection=True):
        mock_ws = MockWorkspace()
        mock_view = MockMatrixWorkspaceDisplayView()
        mock_plotter = Mock()
        container = Mock(spec=StatusBarView)
        container.status_bar = Mock(spec=QStatusBar)
        presenter = MatrixWorkspaceDisplay(mock_ws, plot=mock_plotter, view=mock_view, container=container)

        # 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 _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)
Esempio n. 34
0
    def test_headerData_vertical_header_display_for_numeric_axis_with_point_data(
            self):
        dummy_unit = 'unit'
        ws = MockWorkspace()
        mock_axis = Mock()
        mock_axis.isNumeric.return_value = True
        expected_value = 0.
        mock_axis.label = MagicMock(side_effect=[str(expected_value)])
        mock_axis.getUnit().symbol().utf8.return_value = dummy_unit
        ws.getAxis.return_value = mock_axis

        model_type = MatrixWorkspaceTableViewModelType.y
        model = MatrixWorkspaceTableViewModel(ws, model_type)
        mock_section = 0
        output = model.headerData(mock_section, Qt.Vertical, Qt.DisplayRole)

        expected_output = MatrixWorkspaceTableViewModel.VERTICAL_HEADER_DISPLAY_STRING_FOR_NUMERIC_AXIS.format(
            mock_section, expected_value, dummy_unit)
        self.assertEqual(expected_output, output)
Esempio n. 35
0
    def test_headerData_vertical_header_tooltip_for_numeric_axis_with_binned_data(
            self):
        dummy_unit = 'unit'
        ws = MockWorkspace()
        mock_axis = Mock()
        mock_axis.isNumeric.return_value = True
        ws.getNumberHistograms.return_value = 1
        mock_axis.length.return_value = 2
        mock_axis.label = MagicMock(side_effect=["0.5"])
        mock_axis.getUnit().symbol().utf8.return_value = dummy_unit
        ws.getAxis.return_value = mock_axis

        model_type = MatrixWorkspaceTableViewModelType.y
        model = MatrixWorkspaceTableViewModel(ws, model_type)
        mock_section = 0
        output = model.headerData(mock_section, Qt.Vertical, Qt.ToolTipRole)

        expected_output = MatrixWorkspaceTableViewModel.VERTICAL_HEADER_TOOLTIP_STRING_FOR_NUMERIC_AXIS.format(
            mock_section, 0.5, dummy_unit)
        self.assertEqual(expected_output, output)
Esempio n. 36
0
    def test_histogram_data_has_one_extra_x_column(self):
        """
        Test that an extra column is added if the workspace is HistogramData. This is the column that
        contains the right boundary for the last bin.
        """
        mock_data = [1, 2, 3, 4, 5, 6, 7]
        data_len = len(mock_data)
        ws = MockWorkspace(read_return=mock_data, isHistogramData=True)

        model_type = MatrixWorkspaceTableViewModelType.x
        model = MatrixWorkspaceTableViewModel(ws, model_type)

        self.assertEqual(data_len + 1, model.columnCount())

        # test that it is not added to Y and E
        model_type = MatrixWorkspaceTableViewModelType.y
        model = MatrixWorkspaceTableViewModel(ws, model_type)

        self.assertEqual(data_len, model.columnCount())

        model_type = MatrixWorkspaceTableViewModelType.e
        model = MatrixWorkspaceTableViewModel(ws, model_type)

        self.assertEqual(data_len, model.columnCount())
 def test_supports(self):
     ws = MockWorkspace()
     # the test will fail if the support check fails - an exception is raised
     TableWorkspaceDisplay.supports(ws)
Esempio n. 38
0
 def test_invalid_model_type(self):
     ws = MockWorkspace()
     with self.assertRaises(AssertionError):
         MatrixWorkspaceTableViewModel(ws, "My Model Type")
Esempio n. 39
0
 def wrapper(self):
     ws = MockWorkspace()
     model = TableWorkspaceDisplayModel(ws)
     return func(self, model)