def test_data_tooltip_role_masked_bin(self):
        if not qtpy.PYQT5:
            self.skipTest("QVariant cannot be instantiated in QT4, and the test fails with an error.")

        ws, model, row, index = setup_common_for_test_data()

        model.ws_spectrum_info.isMasked = Mock(return_value=False)
        model.ws_spectrum_info.isMonitor = Mock(return_value=False)
        ws.hasMaskedBins = Mock(return_value=True)
        ws.maskedBinsIndices = Mock(return_value=[index.column()])

        output = model.data(index, Qt.ToolTipRole)

        model.ws_spectrum_info.hasDetectors.assert_has_calls([call.do_work(row), call.do_work(row)])
        model.ws_spectrum_info.isMasked.assert_called_once_with(row)
        model.ws_spectrum_info.isMonitor.assert_called_once_with(row)

        self.assertEqual(MatrixWorkspaceTableViewModel.MASKED_BIN_STRING, output)

        # Doing the same thing a second time should hit the cache, so no additional calls will have been made
        output = model.data(index, Qt.ToolTipRole)
        self.assertEqual(4, model.ws_spectrum_info.hasDetectors.call_count)
        self.assertEqual(2, model.ws_spectrum_info.isMasked.call_count)
        self.assertEqual(2, model.ws_spectrum_info.isMonitor.call_count)
        # This was called only once because the monitor was cached
        ws.hasMaskedBins.assert_called_once_with(row)
        ws.maskedBinsIndices.assert_called_once_with(row)

        self.assertEqual(MatrixWorkspaceTableViewModel.MASKED_BIN_STRING, output)
    def test_data_tooltip_role_masked_bin(self):
        if not qtpy.PYQT5:
            self.skipTest(
                "QVariant cannot be instantiated in QT4, and the test fails with an error."
            )

        ws, model, row, index = setup_common_for_test_data()

        model.ws_spectrum_info.isMasked = Mock(return_value=False)
        model.ws_spectrum_info.isMonitor = Mock(return_value=False)
        ws.hasMaskedBins = Mock(return_value=True)
        ws.maskedBinsIndices = Mock(return_value=[index.column()])

        output = model.data(index, Qt.ToolTipRole)

        model.ws_spectrum_info.hasDetectors.assert_has_calls(
            [call.do_work(row), call.do_work(row)])
        model.ws_spectrum_info.isMasked.assert_called_once_with(row)
        model.ws_spectrum_info.isMonitor.assert_called_once_with(row)

        self.assertEqual(MatrixWorkspaceTableViewModel.MASKED_BIN_STRING,
                         output)

        # Doing the same thing a second time should hit the cache, so no additional calls will have been made
        output = model.data(index, Qt.ToolTipRole)
        self.assertEqual(4, model.ws_spectrum_info.hasDetectors.call_count)
        self.assertEqual(2, model.ws_spectrum_info.isMasked.call_count)
        self.assertEqual(2, model.ws_spectrum_info.isMonitor.call_count)
        # This was called only once because the monitor was cached
        ws.hasMaskedBins.assert_called_once_with(row)
        ws.maskedBinsIndices.assert_called_once_with(row)

        self.assertEqual(MatrixWorkspaceTableViewModel.MASKED_BIN_STRING,
                         output)
    def test_data_tooltip_role_monitor_row(self):
        if not qtpy.PYQT5:
            self.skipTest("QVariant cannot be instantiated in QT4, and the test fails with an error.")
        ws, model, row, index = setup_common_for_test_data()

        # necessary otherwise it is returned that there is a masked bin, and we get the wrong output
        ws.hasMaskedBins = Mock(return_value=False)

        model.ws_spectrum_info.isMasked = Mock(return_value=False)
        model.ws_spectrum_info.isMonitor = Mock(return_value=True)

        output = model.data(index, Qt.ToolTipRole)

        model.ws_spectrum_info.hasDetectors.assert_has_calls([call.do_work(row), call.do_work(row)])
        model.ws_spectrum_info.isMasked.assert_called_once_with(row)
        model.ws_spectrum_info.isMonitor.assert_called_once_with(row)

        self.assertEqual(MatrixWorkspaceTableViewModel.MONITOR_ROW_STRING, output)

        # Doing the same thing a second time should hit the cache, so no additional calls will have been made
        output = model.data(index, Qt.ToolTipRole)
        model.ws_spectrum_info.hasDetectors.assert_has_calls([call.do_work(row), call.do_work(row)])
        self.assertEqual(2, model.ws_spectrum_info.isMasked.call_count)
        # This was called only once because the monitor was cached
        model.ws_spectrum_info.isMonitor.assert_called_once_with(row)

        self.assertEqual(MatrixWorkspaceTableViewModel.MONITOR_ROW_STRING, output)
    def test_data_tooltip_role_masked_row(self):
        if not qtpy.PYQT5:
            self.skipTest("QVariant cannot be instantiated in QT4, and the test fails with an error.")
        ws, model, row, index = setup_common_for_test_data()

        model.ws_spectrum_info.hasDetectors = Mock(return_value=True)
        model.ws_spectrum_info.isMasked = Mock(return_value=True)
        model.ws_spectrum_info.isMonitor = Mock(return_value=False)

        output = model.data(index, Qt.ToolTipRole)

        model.ws_spectrum_info.hasDetectors.assert_has_calls([call.do_work(row), call.do_work(row)])
        model.ws_spectrum_info.isMasked.assert_called_once_with(row)
        model.ws_spectrum_info.isMonitor.assert_called_once_with(row)

        self.assertEqual(MatrixWorkspaceTableViewModel.MASKED_ROW_STRING, output)

        output = model.data(index, Qt.ToolTipRole)

        # The row was masked so it should have been cached
        model.ws_spectrum_info.isMasked.assert_called_once_with(row)

        # However it is checked if it is a monitor again
        self.assertEqual(3, model.ws_spectrum_info.hasDetectors.call_count)
        self.assertEqual(2, model.ws_spectrum_info.isMonitor.call_count)

        self.assertEqual(MatrixWorkspaceTableViewModel.MASKED_ROW_STRING, output)
    def test_data_background_role_monitor_row(self):
        ws, model, row, index = setup_common_for_test_data()

        model.ws_spectrum_info.isMasked = Mock(return_value=False)
        model.ws_spectrum_info.isMonitor = Mock(return_value=True)

        output = model.data(index, Qt.BackgroundRole)

        model.ws_spectrum_info.hasDetectors.assert_called_with(row)
        model.ws_spectrum_info.isMasked.assert_called_once_with(row)
        model.ws_spectrum_info.isMonitor.assert_called_once_with(row)

        index.row.assert_called_once_with()
        self.assertFalse(index.column.called)

        self.assertEqual(model.monitor_color, output)

        # Just do it a second time -> This time it's cached and should be read off the cache.
        # If it is not read off the cache the assert_called_once below will fail,
        # as the functions would be called a 2nd time
        output = model.data(index, Qt.BackgroundRole)

        model.ws_spectrum_info.hasDetectors.assert_called_with(row)
        # assert that it has been called twice with the same parameters
        model.ws_spectrum_info.isMasked.assert_has_calls([call.do_work(row), call.do_work(row)])
        # only called once, as the 2nd time should have hit the cached monitor
        model.ws_spectrum_info.isMonitor.assert_called_once_with(row)
        self.assertEqual(model.monitor_color, output)

        # assert that the row was called twice with no parameters
        self.assertEqual(2, index.row.call_count)
        self.assertFalse(index.column.called)
    def test_data_tooltip_role_monitor_row(self):
        if not qtpy.PYQT5:
            self.skipTest(
                "QVariant cannot be instantiated in QT4, and the test fails with an error."
            )
        ws, model, row, index = setup_common_for_test_data()

        # necessary otherwise it is returned that there is a masked bin, and we get the wrong output
        ws.hasMaskedBins = Mock(return_value=False)

        model.ws_spectrum_info.isMasked = Mock(return_value=False)
        model.ws_spectrum_info.isMonitor = Mock(return_value=True)

        output = model.data(index, Qt.ToolTipRole)

        model.ws_spectrum_info.hasDetectors.assert_has_calls(
            [call.do_work(row), call.do_work(row)])
        model.ws_spectrum_info.isMasked.assert_called_once_with(row)
        model.ws_spectrum_info.isMonitor.assert_called_once_with(row)

        self.assertEqual(MatrixWorkspaceTableViewModel.MONITOR_ROW_STRING,
                         output)

        # Doing the same thing a second time should hit the cache, so no additional calls will have been made
        output = model.data(index, Qt.ToolTipRole)
        model.ws_spectrum_info.hasDetectors.assert_has_calls(
            [call.do_work(row), call.do_work(row)])
        self.assertEqual(2, model.ws_spectrum_info.isMasked.call_count)
        # This was called only once because the monitor was cached
        model.ws_spectrum_info.isMonitor.assert_called_once_with(row)

        self.assertEqual(MatrixWorkspaceTableViewModel.MONITOR_ROW_STRING,
                         output)
    def test_data_tooltip_role_masked_monitor_row(self):
        if not qtpy.PYQT5:
            self.skipTest(
                "QVariant cannot be instantiated in QT4, and the test fails with an error."
            )
        ws, model, row, index = setup_common_for_test_data()

        model.ws_spectrum_info.isMasked = Mock(return_value=True)
        model.ws_spectrum_info.isMonitor = Mock(return_value=True)

        output = model.data(index, Qt.ToolTipRole)

        model.ws_spectrum_info.hasDetectors.assert_has_calls(
            [call.do_work(row), call.do_work(row)])
        model.ws_spectrum_info.isMasked.assert_called_once_with(row)
        model.ws_spectrum_info.isMonitor.assert_called_once_with(row)

        self.assertEqual(
            MatrixWorkspaceTableViewModel.MASKED_MONITOR_ROW_STRING, output)

        # Doing the same thing a second time should hit the cache, so no additional calls will have been made
        output = model.data(index, Qt.ToolTipRole)
        model.ws_spectrum_info.hasDetectors.assert_has_calls(
            [call.do_work(row), call.do_work(row)])
        model.ws_spectrum_info.isMasked.assert_called_once_with(row)
        model.ws_spectrum_info.isMonitor.assert_called_once_with(row)

        self.assertEqual(
            MatrixWorkspaceTableViewModel.MASKED_MONITOR_ROW_STRING, output)
    def test_data_tooltip_role_masked_row(self):
        if not qtpy.PYQT5:
            self.skipTest(
                "QVariant cannot be instantiated in QT4, and the test fails with an error."
            )
        ws, model, row, index = setup_common_for_test_data()

        model.ws_spectrum_info.hasDetectors = Mock(return_value=True)
        model.ws_spectrum_info.isMasked = Mock(return_value=True)
        model.ws_spectrum_info.isMonitor = Mock(return_value=False)

        output = model.data(index, Qt.ToolTipRole)

        model.ws_spectrum_info.hasDetectors.assert_has_calls(
            [call.do_work(row), call.do_work(row)])
        model.ws_spectrum_info.isMasked.assert_called_once_with(row)
        model.ws_spectrum_info.isMonitor.assert_called_once_with(row)

        self.assertEqual(MatrixWorkspaceTableViewModel.MASKED_ROW_STRING,
                         output)

        output = model.data(index, Qt.ToolTipRole)

        # The row was masked so it should have been cached
        model.ws_spectrum_info.isMasked.assert_called_once_with(row)

        # However it is checked if it is a monitor again
        self.assertEqual(3, model.ws_spectrum_info.hasDetectors.call_count)
        self.assertEqual(2, model.ws_spectrum_info.isMonitor.call_count)

        self.assertEqual(MatrixWorkspaceTableViewModel.MASKED_ROW_STRING,
                         output)
    def test_data_background_role_monitor_row(self):
        ws, model, row, index = setup_common_for_test_data()

        model.ws_spectrum_info.isMasked = Mock(return_value=False)
        model.ws_spectrum_info.isMonitor = Mock(return_value=True)

        output = model.data(index, Qt.BackgroundRole)

        model.ws_spectrum_info.hasDetectors.assert_called_with(row)
        model.ws_spectrum_info.isMasked.assert_called_once_with(row)
        model.ws_spectrum_info.isMonitor.assert_called_once_with(row)

        index.row.assert_called_once_with()
        self.assertFalse(index.column.called)

        self.assertEqual(model.monitor_color, output)

        # Just do it a second time -> This time it's cached and should be read off the cache.
        # If it is not read off the cache the assert_called_once below will fail,
        # as the functions would be called a 2nd time
        output = model.data(index, Qt.BackgroundRole)

        model.ws_spectrum_info.hasDetectors.assert_called_with(row)
        # assert that it has been called twice with the same parameters
        model.ws_spectrum_info.isMasked.assert_has_calls(
            [call.do_work(row), call.do_work(row)])
        # only called once, as the 2nd time should have hit the cached monitor
        model.ws_spectrum_info.isMonitor.assert_called_once_with(row)
        self.assertEqual(model.monitor_color, output)

        # assert that the row was called twice with no parameters
        self.assertEqual(2, index.row.call_count)
        self.assertFalse(index.column.called)
    def test_data_tooltip_role_masked_monitor_row(self):
        if not qtpy.PYQT5:
            self.skipTest("QVariant cannot be instantiated in QT4, and the test fails with an error.")
        ws, model, row, index = setup_common_for_test_data()

        model.ws_spectrum_info.isMasked = Mock(return_value=True)
        model.ws_spectrum_info.isMonitor = Mock(return_value=True)

        output = model.data(index, Qt.ToolTipRole)

        model.ws_spectrum_info.hasDetectors.assert_has_calls([call.do_work(row), call.do_work(row)])
        model.ws_spectrum_info.isMasked.assert_called_once_with(row)
        model.ws_spectrum_info.isMonitor.assert_called_once_with(row)

        self.assertEqual(MatrixWorkspaceTableViewModel.MASKED_MONITOR_ROW_STRING, output)

        # Doing the same thing a second time should hit the cache, so no additional calls will have been made
        output = model.data(index, Qt.ToolTipRole)
        model.ws_spectrum_info.hasDetectors.assert_has_calls([call.do_work(row), call.do_work(row)])
        model.ws_spectrum_info.isMasked.assert_called_once_with(row)
        model.ws_spectrum_info.isMonitor.assert_called_once_with(row)

        self.assertEqual(MatrixWorkspaceTableViewModel.MASKED_MONITOR_ROW_STRING, output)
    def test_data_background_role_masked_bin(self):
        ws, model, row, index = setup_common_for_test_data()

        model.ws_spectrum_info.isMasked = Mock(return_value=False)
        model.ws_spectrum_info.isMonitor = Mock(return_value=False)

        output = model.data(index, Qt.BackgroundRole)

        model.ws_spectrum_info.hasDetectors.assert_called_with(row)
        model.ws_spectrum_info.isMasked.assert_called_once_with(row)
        model.ws_spectrum_info.isMonitor.assert_called_once_with(row)
        ws.hasMaskedBins.assert_called_once_with(row)
        ws.maskedBinsIndices.assert_called_once_with(row)

        index.row.assert_called_once_with()
        index.column.assert_called_once_with()

        self.assertEqual(model.masked_color, output)
        # Just do it a second time -> This time it's cached and should be read off the cache.
        # If it is not read off the cache the assert_called_once below will fail,
        # as the functions would be called a 2nd time
        output = model.data(index, Qt.BackgroundRole)

        # masked bins is checked last, so it will call all other functions a second time
        model.ws_spectrum_info.hasDetectors.assert_has_calls(
            [call.do_work(row), call.do_work(row)])
        model.ws_spectrum_info.isMasked.assert_has_calls(
            [call.do_work(row), call.do_work(row)])
        model.ws_spectrum_info.isMonitor.assert_has_calls(
            [call.do_work(row), call.do_work(row)])

        # these, however, should remain at 1 call, as the masked bin cache should have been hit
        ws.hasMaskedBins.assert_called_once_with(row)
        ws.maskedBinsIndices.assert_called_once_with(row)

        self.assertEqual(model.masked_color, output)

        self.assertEqual(2, index.row.call_count)
        self.assertEqual(2, index.column.call_count)
    def test_data_background_role_masked_bin(self):
        ws, model, row, index = setup_common_for_test_data()

        model.ws_spectrum_info.isMasked = Mock(return_value=False)
        model.ws_spectrum_info.isMonitor = Mock(return_value=False)

        output = model.data(index, Qt.BackgroundRole)

        model.ws_spectrum_info.hasDetectors.assert_called_with(row)
        model.ws_spectrum_info.isMasked.assert_called_once_with(row)
        model.ws_spectrum_info.isMonitor.assert_called_once_with(row)
        ws.hasMaskedBins.assert_called_once_with(row)
        ws.maskedBinsIndices.assert_called_once_with(row)

        index.row.assert_called_once_with()
        index.column.assert_called_once_with()

        self.assertEqual(model.masked_color, output)
        # Just do it a second time -> This time it's cached and should be read off the cache.
        # If it is not read off the cache the assert_called_once below will fail,
        # as the functions would be called a 2nd time
        output = model.data(index, Qt.BackgroundRole)

        # masked bins is checked last, so it will call all other functions a second time
        model.ws_spectrum_info.hasDetectors.assert_has_calls([call.do_work(row), call.do_work(row)])
        model.ws_spectrum_info.isMasked.assert_has_calls([call.do_work(row), call.do_work(row)])
        model.ws_spectrum_info.isMonitor.assert_has_calls([call.do_work(row), call.do_work(row)])

        # these, however, should remain at 1 call, as the masked bin cache should have been hit
        ws.hasMaskedBins.assert_called_once_with(row)
        ws.maskedBinsIndices.assert_called_once_with(row)

        self.assertEqual(model.masked_color, output)

        self.assertEqual(2, index.row.call_count)
        self.assertEqual(2, index.column.call_count)