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.copy_to_clipboard = Mock() self.show_mouse_toast = Mock() self.ask_confirmation = None
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 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_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)