def __init__(self): self.set_context_menu_actions = Mock() self.table_x = MockQTableView() self.table_y = MockQTableView() self.table_e = MockQTableView() self.set_model = Mock() self.ask_confirmation = None self.emit_close = Mock() self.mock_tab = MockQTab() self.get_active_tab = Mock(return_value=self.mock_tab)
def test_action_copy_cell(self, ws, view, presenter, mock_copy, mock_show_mouse_toast): mock_table = MockQTableView() # two columns are selected at different positions mock_index = MockQModelIndex(None, None) mock_model = mock_table.model() 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_model.createIndex.call_count) mock_show_mouse_toast.assert_called_once_with(MatrixWorkspaceDisplay.COPY_SUCCESSFUL_MESSAGE)
def test_copy_cells(self, mock_copy, mock_show_mouse_toast): mock_table = MockQTableView() # two columns are selected at different positions mock_model = mock_table.model() mock_index = MockQModelIndex(None, None) mock_table.mock_selection_model.currentIndex = Mock( return_value=mock_index) self.data_copier.copy_cells(mock_table) mock_table.selectionModel.assert_called_once_with() self.assertEqual(1, mock_copy.call_count) self.assertEqual(9, mock_model.createIndex.call_count) mock_show_mouse_toast.assert_called_once_with( UserNotifier.COPY_SUCCESSFUL_MESSAGE)
def test_copy_cells_no_selection(self, mock_copy, mock_show_mouse_toast): mock_table = MockQTableView() mock_table.mock_selection_model.hasSelection = Mock(return_value=False) self.data_copier.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(UserNotifier.NO_SELECTION_MESSAGE) self.assertNotCalled(mock_copy)
def test_action_copy_cell_no_selection(self, ws, view, presenter, mock_copy, mock_show_mouse_toast): 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 test_action_copy_bin_values_no_selection(self, mock_copy, mock_show_mouse_toast): mock_table = MockQTableView() mock_table.mock_selection_model.hasSelection = Mock(return_value=False) mock_table.mock_selection_model.selectedColumns = Mock() self.data_copier.copy_bin_values(mock_table, None, None) 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.selectedColumns) self.assertNotCalled(mock_copy) mock_show_mouse_toast.assert_called_once_with(UserNotifier.NO_SELECTION_MESSAGE)
def test_action_copy_bin_values_no_selection(self, ws, view, presenter, mock_copy, mock_show_mouse_toast): mock_table = MockQTableView() mock_table.mock_selection_model.hasSelection = Mock(return_value=False) mock_table.mock_selection_model.selectedColumns = Mock() presenter.action_copy_bin_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.selectedColumns) self.assertNotCalled(mock_copy) mock_show_mouse_toast.assert_called_once_with(MatrixWorkspaceDisplay.NO_SELECTION_MESSAGE)
def test_action_copy_spectrum_values(self, mock_copy, mock_show_mouse_toast): 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]) expected_string = "43\t99\n43\t99" self.data_copier.copy_spectrum_values(mock_table, mock_read) 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(UserNotifier.COPY_SUCCESSFUL_MESSAGE)
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 test_action_copy_bin_values(self, mock_copy, mock_show_mouse_toast): 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 num_hist = 3 mock_read = Mock(return_value=[83, 11, 33, 70]) expected_string = "83\t70\n83\t70\n83\t70" self.data_copier.copy_bin_values(mock_table, mock_read, num_hist) 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(UserNotifier.COPY_SUCCESSFUL_MESSAGE)
def test_action_copy_spectrum_values(self, ws, view, presenter, mock_copy, mock_show_mouse_toast): 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) presenter._get_ws_read_from_type.assert_called_once_with(MatrixWorkspaceTableViewModelType.x)
def test_action_copy_bin_values(self, ws, view, presenter, mock_copy, mock_show_mouse_toast): 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) presenter._get_ws_read_from_type.assert_called_once_with(MatrixWorkspaceTableViewModelType.x)